Skip to content

Commit

Permalink
Update web3py to stable version (#35)
Browse files Browse the repository at this point in the history
* Update web3py to stable version

* Bump web3py version
  • Loading branch information
cyc60 authored Jun 28, 2023
1 parent 7fbb341 commit 4491a57
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
21 changes: 10 additions & 11 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
[tool.poetry]
name = "sw-utils"
version = "0.3.7"
version = "0.3.8"
description = "StakeWise Python utils"
authors = ["StakeWise Labs <[email protected]>"]
license = "GPL-3.0-or-later"
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"
Expand Down
9 changes: 5 additions & 4 deletions sw_utils/execution.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
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

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},
)

Expand Down
16 changes: 11 additions & 5 deletions sw_utils/middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 4491a57

Please sign in to comment.