From 4491a577b53ef8b850fe75ae22ee0ff2050ff1a4 Mon Sep 17 00:00:00 2001 From: Alexander Sysoev Date: Wed, 28 Jun 2023 14:50:53 +0300 Subject: [PATCH] Update web3py to stable version (#35) * Update web3py to stable version * Bump web3py version --- poetry.lock | 21 ++++++++++----------- pyproject.toml | 4 ++-- sw_utils/execution.py | 9 +++++---- sw_utils/middlewares.py | 16 +++++++++++----- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/poetry.lock b/poetry.lock index 21dd572..768413e 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2318,19 +2318,19 @@ test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess [[package]] name = "web3" -version = "6.0.0b9" -description = "Web3.py" +version = "6.5.0" +description = "web3.py" category = "main" optional = false python-versions = ">=3.7.2" files = [ - {file = "web3-6.0.0b9-py3-none-any.whl", hash = "sha256:2b70afe31d38813804aa5ee3503c72e9e41cb2cf7e720627ccbc0a85791f97ca"}, - {file = "web3-6.0.0b9.tar.gz", hash = "sha256:f90e55cddf6cde97552ff241d55903a5ef2a5fec192f2cad540e8effe555c494"}, + {file = "web3-6.5.0-py3-none-any.whl", hash = "sha256:a6e9f6e4e13d75a5a3726d10b1be91cde5951446e8a6f0efdaee1695b5011472"}, + {file = "web3-6.5.0.tar.gz", hash = "sha256:ebbce3caa0b50015d15a07f17d2a280abbb94a52c6994babb90f3a5482c97712"}, ] [package.dependencies] aiohttp = ">=3.7.4.post0" -eth-abi = ">=4.0.0-b.2" +eth-abi = ">=4.0.0" eth-account = ">=0.8.0" eth-hash = {version = ">=0.5.1", extras = ["pycryptodome"]} eth-typing = ">=3.0.0" @@ -2338,18 +2338,17 @@ eth-utils = ">=2.1.0" hexbytes = ">=0.1.0" jsonschema = ">=4.0.0" lru-dict = ">=1.1.6" -parsimonious = "0.9.0" protobuf = ">=4.21.6" pywin32 = {version = ">=223", markers = "platform_system == \"Windows\""} requests = ">=2.16.0" websockets = ">=10.0.0" [package.extras] -dev = ["black (>=22.1.0)", "bumpversion", "click (>=5.1)", "configparser (==3.5.0)", "contextlib2 (>=0.5.4)", "eth-tester[py-evm] (==v0.8.0-b.3)", "flake8 (==3.8.3)", "flaky (>=3.7.0)", "hypothesis (>=3.31.2)", "importlib-metadata (<5.0)", "ipfshttpclient (==0.8.0a2)", "isort (>=4.2.15,<4.3.5)", "mock", "mypy (==0.910)", "pluggy (==0.13.1)", "py-geth (>=3.10.0)", "py-geth (>=3.9.1)", "py-solc (>=0.4.0)", "pytest (>=6.2.5)", "pytest-asyncio (>=0.18.1)", "pytest-mock (>=1.10)", "pytest-pythonpath (>=0.3)", "pytest-watch (>=4.2)", "pytest-xdist (>=1.29)", "setuptools (>=38.6.0)", "sphinx (>=4.2.0)", "sphinx-rtd-theme (>=0.5.2)", "toposort (>=1.4)", "towncrier (==18.5.0)", "tox (>=3.18.0)", "tqdm (>4.32)", "twine (>=1.13)", "types-protobuf (==3.19.13)", "types-requests (>=2.26.1)", "types-setuptools (>=57.4.4)", "urllib3", "wheel", "when-changed (>=0.3.0)"] -docs = ["click (>=5.1)", "configparser (==3.5.0)", "contextlib2 (>=0.5.4)", "mock", "py-geth (>=3.9.1)", "py-solc (>=0.4.0)", "pytest (>=6.2.5)", "sphinx (>=4.2.0)", "sphinx-rtd-theme (>=0.5.2)", "toposort (>=1.4)", "towncrier (==18.5.0)", "urllib3", "wheel"] +dev = ["black (>=22.1.0)", "build (>=0.9.0)", "bumpversion", "eth-tester[py-evm] (==v0.9.0-b.1)", "flake8 (==3.8.3)", "flaky (>=3.7.0)", "hypothesis (>=3.31.2)", "importlib-metadata (<5.0)", "ipfshttpclient (==0.8.0a2)", "isort (>=5.11.0)", "mypy (==0.910)", "py-geth (>=3.11.0)", "pytest (>=7.0.0)", "pytest-asyncio (>=0.18.1)", "pytest-mock (>=1.10)", "pytest-watch (>=4.2)", "pytest-xdist (>=1.29)", "setuptools (>=38.6.0)", "sphinx (>=5.3.0)", "sphinx-rtd-theme (>=1.0.0)", "towncrier (>=21,<22)", "tox (>=3.18.0)", "tqdm (>4.32)", "twine (>=1.13)", "types-protobuf (==3.19.13)", "types-requests (>=2.26.1)", "types-setuptools (>=57.4.4)", "when-changed (>=0.3.0)"] +docs = ["sphinx (>=5.3.0)", "sphinx-rtd-theme (>=1.0.0)", "towncrier (>=21,<22)"] ipfs = ["ipfshttpclient (==0.8.0a2)"] -linter = ["black (>=22.1.0)", "flake8 (==3.8.3)", "isort (>=4.2.15,<4.3.5)", "mypy (==0.910)", "types-protobuf (==3.19.13)", "types-requests (>=2.26.1)", "types-setuptools (>=57.4.4)"] -tester = ["eth-tester[py-evm] (==v0.8.0-b.3)", "py-geth (>=3.10.0)"] +linter = ["black (>=22.1.0)", "flake8 (==3.8.3)", "isort (>=5.11.0)", "mypy (==0.910)", "types-protobuf (==3.19.13)", "types-requests (>=2.26.1)", "types-setuptools (>=57.4.4)"] +tester = ["eth-tester[py-evm] (==v0.9.0-b.1)", "py-geth (>=3.11.0)"] [[package]] name = "websockets" @@ -2607,4 +2606,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "71bc3c2e6b0ef6ce49d67c56d907df56cc86dd710dc2be30fc56dc5fc85266c1" +content-hash = "6598d03436f2d2c4a783b269f68a05a55e3795671f2c81991041f88d6fd7c1d5" diff --git a/pyproject.toml b/pyproject.toml index c92c5c1..cd02b0a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "sw-utils" -version = "0.3.7" +version = "0.3.8" description = "StakeWise Python utils" authors = ["StakeWise Labs "] license = "GPL-3.0-or-later" @@ -8,12 +8,12 @@ readme = "README.md" [tool.poetry.dependencies] python = "^3.10" -web3 = "==6.0.0b9" backoff = "^2.2.1" milagro-bls-binding = "==1.9.0" py-ecc = "^6.0.0" ipfshttpclient = "^0.8.0a2" types-requests = "^2.28.11.15" +web3 = "==6.5.0" [tool.poetry.group.dev.dependencies] pylint = "^2.14.5" diff --git a/sw_utils/execution.py b/sw_utils/execution.py index 570e543..5df1aca 100644 --- a/sw_utils/execution.py +++ b/sw_utils/execution.py @@ -1,6 +1,6 @@ import logging -from web3 import Web3 +from web3 import AsyncHTTPProvider, AsyncWeb3 from web3.eth import AsyncEth from web3.middleware import async_geth_poa_middleware from web3.net import AsyncNet @@ -8,9 +8,10 @@ logger = logging.getLogger(__name__) -def get_execution_client(endpoint: str, is_poa=False, timeout=60) -> Web3: - client = Web3( - Web3.AsyncHTTPProvider(endpoint, request_kwargs={'timeout': timeout}), +def get_execution_client(endpoint: str, is_poa=False, timeout=60) -> AsyncWeb3: + provider = AsyncHTTPProvider(endpoint, request_kwargs={'timeout': timeout}) + client = AsyncWeb3( + provider, modules={'eth': (AsyncEth,), 'net': AsyncNet}, ) diff --git a/sw_utils/middlewares.py b/sw_utils/middlewares.py index 43d3d3c..1328782 100644 --- a/sw_utils/middlewares.py +++ b/sw_utils/middlewares.py @@ -6,10 +6,16 @@ from eth_keys.datatypes import PrivateKey from eth_typing import ChecksumAddress, HexStr from eth_utils.toolz import curry -from web3 import Web3 +from web3 import AsyncWeb3, Web3 from web3._utils.async_transactions import fill_transaction_defaults from web3.middleware.signing import format_transaction, gen_normalized_accounts -from web3.types import AsyncMiddleware, Middleware, RPCEndpoint, RPCResponse, TxParams +from web3.types import ( + AsyncMiddleware, + AsyncMiddlewareCoroutine, + RPCEndpoint, + RPCResponse, + TxParams, +) _PrivateKey = Union[LocalAccount, PrivateKey, HexStr, bytes] @@ -30,7 +36,7 @@ async def fill_nonce(w3: 'Web3', transaction: TxParams) -> TxParams: # TODO: can be removed once https://github.com/ethereum/web3.py/issues/2773 is fixed def construct_async_sign_and_send_raw_middleware( private_key_or_account: Union[_PrivateKey, Collection[_PrivateKey]] -) -> Middleware: +) -> AsyncMiddleware: """Capture transactions sign and send as raw transactions @@ -45,8 +51,8 @@ def construct_async_sign_and_send_raw_middleware( accounts = gen_normalized_accounts(private_key_or_account) async def sign_and_send_raw_middleware( - make_request: Callable[[RPCEndpoint, Any], Any], _async_w3: 'Web3' - ) -> AsyncMiddleware: + make_request: Callable[[RPCEndpoint, Any], Any], _async_w3: 'AsyncWeb3' + ) -> AsyncMiddlewareCoroutine: async def middleware(method: RPCEndpoint, params: Any) -> RPCResponse: if method != 'eth_sendTransaction': return await make_request(method, params)