Skip to content

Commit

Permalink
feat: upgrade web3
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Dec 10, 2024
1 parent a3f17aa commit 97e30f8
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 43 deletions.
12 changes: 6 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@
"watchdog>=3.0,<4",
# ** Dependencies maintained by Ethereum Foundation **
"eth-abi>=5.1.0,<6",
"eth-account>=0.11.3,<0.14",
"eth-typing>=3.5.2,<6",
"eth-utils>=2.1.0,<6",
"hexbytes>=0.3.1,<2",
"py-geth>=3.14.0,<6",
"eth-account>=0.13.4,<0.14",
"eth-typing>=5.0.1,<6",
"eth-utils>=5.1.0,<6",
"hexbytes>=1.2.1,<2",
"py-geth>=5.1.0,<6",
"trie>=3.0.1,<4", # Peer: stricter pin needed for uv support.
"web3[tester]>=6.20.1,<8",
"web3[tester]>=7.6.0,<8",
# ** Dependencies maintained by ApeWorX **
"eip712>=0.2.10,<0.3",
"ethpm-types>=0.6.19,<0.7",
Expand Down
28 changes: 0 additions & 28 deletions src/ape/utils/_web3_compat.py

This file was deleted.

3 changes: 1 addition & 2 deletions src/ape_accounts/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from ape.exceptions import AccountsError
from ape.logging import logger
from ape.types.signatures import MessageSignature, SignableMessage, TransactionSignature
from ape.utils._web3_compat import sign_hash
from ape.utils.basemodel import ManagerAccessMixin
from ape.utils.misc import log_instead_of_fail
from ape.utils.validators import _validate_account_alias, _validate_account_passphrase
Expand Down Expand Up @@ -256,7 +255,7 @@ def sign_raw_msghash(self, msghash: HexBytes) -> Optional[MessageSignature]:
# Also, we have already warned the user about the safety.
with warnings.catch_warnings():
warnings.simplefilter("ignore")
signed_msg = sign_hash(msghash, self.__key)
signed_msg = EthAccount.unsafe_sign_hash(msghash, self.__key)

return MessageSignature(
v=signed_msg.v,
Expand Down
6 changes: 3 additions & 3 deletions src/ape_ethereum/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from evmchains import PUBLIC_CHAIN_META, get_random_rpc
from pydantic.dataclasses import dataclass
from requests import HTTPError
from web3 import HTTPProvider, IPCProvider, Web3
from web3 import HTTPProvider, IPCProvider, Web3, WebSocketProvider
from web3 import __version__ as web3_version
from web3.exceptions import ContractLogicError as Web3ContractLogicError
from web3.exceptions import (
Expand All @@ -35,6 +35,7 @@
Web3RPCError = ValueError # type: ignore

from web3.gas_strategies.rpc import rpc_gas_price_strategy
from web3.middleware import ExtraDataToPOAMiddleware
from web3.middleware.validation import MAX_EXTRADATA_LENGTH
from web3.providers import AutoProvider
from web3.providers.auto import load_provider_from_environment
Expand Down Expand Up @@ -63,7 +64,6 @@
from ape.types.events import ContractLog, LogFilter
from ape.types.gas import AutoGasLimit
from ape.types.trace import SourceTraceback
from ape.utils._web3_compat import ExtraDataToPOAMiddleware, WebsocketProvider
from ape.utils.basemodel import ManagerAccessMixin
from ape.utils.misc import DEFAULT_MAX_RETRIES_TX, gas_estimation_error_message, to_int
from ape.utils.rpc import request_with_retry
Expand Down Expand Up @@ -1633,7 +1633,7 @@ def _create_web3(

providers.append(lambda: HTTPProvider(endpoint_uri=http, request_kwargs=request_kwargs))
if ws := ws_uri:
providers.append(lambda: WebsocketProvider(endpoint_uri=ws))
providers.append(lambda: WebSocketProvider(endpoint_uri=ws))

provider = AutoProvider(potential_providers=providers)
return Web3(provider)
Expand Down
2 changes: 1 addition & 1 deletion src/ape_node/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
from pydantic import field_validator
from pydantic_settings import SettingsConfigDict
from requests.exceptions import ConnectionError
from web3.middleware import ExtraDataToPOAMiddleware

from ape.api.config import PluginConfig
from ape.api.providers import SubprocessProvider, TestProviderAPI
from ape.exceptions import VirtualMachineError
from ape.logging import LogLevel, logger
from ape.utils._web3_compat import ExtraDataToPOAMiddleware
from ape.utils.misc import ZERO_ADDRESS, log_instead_of_fail, raises_not_implemented
from ape.utils.process import JoinableQueue, spawn
from ape.utils.testing import (
Expand Down
3 changes: 1 addition & 2 deletions src/ape_test/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from ape.api.accounts import TestAccountAPI, TestAccountContainerAPI
from ape.exceptions import ProviderNotConnectedError, SignatureError
from ape.types.signatures import MessageSignature, TransactionSignature
from ape.utils._web3_compat import sign_hash
from ape.utils.testing import (
DEFAULT_NUMBER_OF_TEST_ACCOUNTS,
DEFAULT_TEST_HD_PATH,
Expand Down Expand Up @@ -167,7 +166,7 @@ def sign_transaction(
def sign_raw_msghash(self, msghash: HexBytes) -> MessageSignature:
with warnings.catch_warnings():
warnings.simplefilter("ignore")
signed_msg = sign_hash(msghash, self.private_key)
signed_msg = EthAccount.unsafe_sign_hash(msghash, self.private_key)

return MessageSignature(
v=signed_msg.v,
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/geth/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from web3 import AutoProvider, Web3
from web3.exceptions import ContractLogicError as Web3ContractLogicError
from web3.exceptions import ExtraDataLengthError
from web3.middleware import ExtraDataToPOAMiddleware
from web3.providers import HTTPProvider

from ape.exceptions import (
Expand All @@ -25,7 +26,6 @@
VirtualMachineError,
)
from ape.utils import to_int
from ape.utils._web3_compat import ExtraDataToPOAMiddleware
from ape_ethereum.ecosystem import Block
from ape_ethereum.provider import DEFAULT_SETTINGS, EthereumNodeProvider
from ape_ethereum.trace import TraceApproach
Expand Down

0 comments on commit 97e30f8

Please sign in to comment.