From 7d0847253d34d58479731e81aefa88e997267bdc Mon Sep 17 00:00:00 2001 From: NotPeopling2day <32708219+NotPeopling2day@users.noreply.github.com> Date: Mon, 18 Dec 2023 21:54:00 -0500 Subject: [PATCH] feat!: Handle 0.7 breaking changes and updates [APE-1608] (#9) --- .pre-commit-config.yaml | 19 ++++++++++++------- ape_chainstack/__init__.py | 8 +++++--- ape_chainstack/providers.py | 13 ++++--------- ape_chainstack/utils.py | 17 +++++++++++++++++ setup.py | 19 ++++++++++++------- 5 files changed, 50 insertions(+), 26 deletions(-) create mode 100644 ape_chainstack/utils.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ca7f73b..e15dfcf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.2.0 + rev: v4.5.0 hooks: - id: check-yaml @@ -10,22 +10,27 @@ repos: - id: isort - repo: https://github.com/psf/black - rev: 22.3.0 + rev: 23.12.0 hooks: - id: black name: black -- repo: https://gitlab.com/pycqa/flake8 - rev: 4.0.1 +- repo: https://github.com/pycqa/flake8 + rev: 6.1.0 hooks: - id: flake8 - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.971 + rev: v1.7.1 hooks: - id: mypy - additional_dependencies: [types-PyYAML, types-requests] + additional_dependencies: [types-setuptools, pydantic] +- repo: https://github.com/executablebooks/mdformat + rev: 0.7.17 + hooks: + - id: mdformat + additional_dependencies: [mdformat-gfm, mdformat-frontmatter] default_language_version: - python: python3.9 + python: python3 diff --git a/ape_chainstack/__init__.py b/ape_chainstack/__init__.py index bddeeb8..2c1b02e 100644 --- a/ape_chainstack/__init__.py +++ b/ape_chainstack/__init__.py @@ -1,9 +1,11 @@ from ape import plugins -from .providers import ETH_NETWORKS, Chainstack +from .providers import Chainstack +from .utils import NETWORKS @plugins.register(plugins.ProviderPlugin) def providers(): - for network_name in ETH_NETWORKS: - yield "ethereum", network_name, Chainstack + for ecosystem_name in NETWORKS: + for network_name in NETWORKS[ecosystem_name]: + yield ecosystem_name, network_name, Chainstack diff --git a/ape_chainstack/providers.py b/ape_chainstack/providers.py index 683ac57..7108eb5 100644 --- a/ape_chainstack/providers.py +++ b/ape_chainstack/providers.py @@ -1,19 +1,14 @@ import os -from ape.api import Web3Provider from ape.exceptions import ContractLogicError, ProviderError, VirtualMachineError +from ape_ethereum.provider import Web3Provider from web3 import HTTPProvider, Web3 from web3.exceptions import ContractLogicError as Web3ContractLogicError from web3.middleware import geth_poa_middleware -ETH_NETWORKS = [ - "mainnet", - "ropsten", - "rinkeby", - "goerli", -] +from .utils import NETWORKS -_ENVIRONMENT_VARIABLE_NAMES = [f"CHAINSTACK_{network.upper()}_URL" for network in ETH_NETWORKS] +_ENVIRONMENT_VARIABLE_NAMES = [f"CHAINSTACK_{network.upper()}_URL" for network in NETWORKS] class ChainstackProviderError(ProviderError): @@ -61,7 +56,7 @@ def disconnect(self): self._web3 = None return super().disconnect() - def get_virtual_machine_error(self, exception: Exception) -> VirtualMachineError: + def get_virtual_machine_error(self, exception: Exception, **kwargs) -> VirtualMachineError: if not hasattr(exception, "args") or not len(exception.args): return VirtualMachineError(base_err=exception) diff --git a/ape_chainstack/utils.py b/ape_chainstack/utils.py new file mode 100644 index 0000000..254a333 --- /dev/null +++ b/ape_chainstack/utils.py @@ -0,0 +1,17 @@ +from typing import Dict, List + +API_KEY_ENV_KEY_MAP = { + "base": "BASE_CHAINSTACK_API_KEY", + "ethereum": "ETH_CHAINSTACK_API_KEY", + "gnosis": "GNOSIS_CHAINSTACK_API_KEY", + "optimism": "OPTIMISM_CHAINSTACK_API_KEY", + "polygon": "POLYGON_CHAINSTACK_API_KEY", +} + +NETWORKS: Dict[str, List[str]] = { + "base": ["mainnet", "goerli", "sepolia"], + "ethereum": ["mainnet", "ropsten", "rinkeby", "goerli", "sepolia"], + "gnosis": ["mainnet", "chiado"], + "optimism": ["mainnet", "goerli", "sepolia"], + "polygon": ["mainnet"], +} diff --git a/setup.py b/setup.py index 1981d13..cfed4b5 100644 --- a/setup.py +++ b/setup.py @@ -10,12 +10,17 @@ "hypothesis>=6.2.0,<7.0", # Strategy-based fuzzer ], "lint": [ - "black>=22.6.0,<23.0", # auto-formatter and linter - "mypy>=0.971,<1.0", # Static type analyzer - "flake8>=4.0.1,<5.0", # Style linter - "flake8-breakpoint>=1.1.0,<2.0.0", # detect breakpoints left in code - "flake8-print>=4.0.0,<5.0.0", # detect print statements left in code - "isort>=5.10.1,<6.0", # Import sorting linter + "black>=23.12.0,<24", # Auto-formatter and linter + "mypy>=1.7.1,<2", # Static type analyzer + "types-setuptools", # Needed for mypy type shed + "flake8>=6.1.0,<7", # Style linter + "flake8-breakpoint>=1.1.0,<2", # Detect breakpoints left in code + "flake8-print>=5.0.0,<6", # Detect print statements left in code + "isort>=5.10.1,<6", # Import sorting linter + "mdformat>=0.7.17", # Auto-formatter for markdown + "mdformat-gfm>=0.3.5", # Needed for formatting GitHub-flavored markdown + "mdformat-frontmatter>=0.4.1", # Needed for frontmatters-style headers in issue templates + "mdformat-pyproject>=0.0.1", # Allows configuring in pyproject.toml ], "release": [ # `release` GitHub Action job uses this "setuptools", # Installation tool @@ -55,7 +60,7 @@ url="https://github.com/ApeWorX/ape-chainstack", include_package_data=True, install_requires=[ - "eth-ape>=0.5.0,<0.6", + "eth-ape>=0.7.0,<0.8", ], python_requires=">=3.8,<4", extras_require=extras_require,