web3 6.20.3__py3-none-any.whl → 7.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ens/__init__.py +13 -2
- ens/_normalization.py +2 -17
- ens/async_ens.py +33 -21
- ens/base_ens.py +3 -1
- ens/ens.py +16 -11
- ens/exceptions.py +16 -29
- ens/specs/nf.json +1 -1
- ens/specs/normalization_spec.json +1 -1
- ens/utils.py +52 -63
- web3/__init__.py +20 -24
- web3/_utils/abi.py +115 -271
- web3/_utils/async_transactions.py +7 -4
- web3/_utils/batching.py +217 -0
- web3/_utils/blocks.py +6 -2
- web3/_utils/caching.py +128 -5
- web3/_utils/compat/__init__.py +2 -3
- web3/_utils/contract_sources/compile_contracts.py +1 -1
- web3/_utils/contract_sources/contract_data/arrays_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/bytes_contracts.py +5 -5
- web3/_utils/contract_sources/contract_data/constructor_contracts.py +7 -7
- web3/_utils/contract_sources/contract_data/contract_caller_tester.py +3 -3
- web3/_utils/contract_sources/contract_data/emitter_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/event_contracts.py +5 -5
- web3/_utils/contract_sources/contract_data/extended_resolver.py +3 -3
- web3/_utils/contract_sources/contract_data/fallback_function_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/function_name_tester_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/math_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/offchain_lookup.py +3 -3
- web3/_utils/contract_sources/contract_data/offchain_resolver.py +3 -3
- web3/_utils/contract_sources/contract_data/panic_errors_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/payable_tester.py +3 -3
- web3/_utils/contract_sources/contract_data/receive_function_contracts.py +5 -5
- web3/_utils/contract_sources/contract_data/reflector_contracts.py +3 -3
- web3/_utils/contract_sources/contract_data/revert_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/simple_resolver.py +3 -3
- web3/_utils/contract_sources/contract_data/storage_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/string_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/tuple_contracts.py +5 -5
- web3/_utils/contracts.py +130 -236
- web3/_utils/datatypes.py +5 -1
- web3/_utils/decorators.py +13 -23
- web3/_utils/empty.py +1 -1
- web3/_utils/encoding.py +16 -12
- web3/_utils/ens.py +2 -1
- web3/_utils/error_formatters_utils.py +5 -3
- web3/_utils/events.py +66 -69
- web3/_utils/fee_utils.py +1 -3
- web3/_utils/filters.py +24 -22
- web3/_utils/formatters.py +2 -2
- web3/_utils/http.py +5 -3
- web3/_utils/http_session_manager.py +303 -0
- web3/_utils/math.py +14 -15
- web3/_utils/method_formatters.py +34 -36
- web3/_utils/module.py +2 -1
- web3/_utils/module_testing/__init__.py +0 -3
- web3/_utils/module_testing/eth_module.py +695 -643
- web3/_utils/module_testing/module_testing_utils.py +61 -34
- web3/_utils/module_testing/persistent_connection_provider.py +56 -25
- web3/_utils/module_testing/utils.py +258 -0
- web3/_utils/module_testing/web3_module.py +438 -17
- web3/_utils/normalizers.py +13 -11
- web3/_utils/rpc_abi.py +5 -32
- web3/_utils/threads.py +8 -7
- web3/_utils/transactions.py +14 -12
- web3/_utils/type_conversion.py +5 -1
- web3/_utils/validation.py +17 -17
- web3/auto/gethdev.py +7 -2
- web3/beacon/__init__.py +6 -1
- web3/beacon/async_beacon.py +9 -5
- web3/beacon/{main.py → beacon.py} +7 -5
- web3/contract/__init__.py +7 -0
- web3/contract/async_contract.py +47 -46
- web3/contract/base_contract.py +183 -158
- web3/contract/contract.py +49 -43
- web3/contract/utils.py +203 -59
- web3/datastructures.py +79 -31
- web3/eth/__init__.py +7 -0
- web3/eth/async_eth.py +39 -51
- web3/eth/base_eth.py +17 -10
- web3/eth/eth.py +30 -68
- web3/exceptions.py +108 -82
- web3/gas_strategies/time_based.py +8 -6
- web3/geth.py +1 -254
- web3/main.py +75 -122
- web3/manager.py +316 -146
- web3/method.py +38 -31
- web3/middleware/__init__.py +67 -89
- web3/middleware/attrdict.py +36 -49
- web3/middleware/base.py +174 -0
- web3/middleware/buffered_gas_estimate.py +20 -21
- web3/middleware/filter.py +157 -117
- web3/middleware/formatting.py +124 -108
- web3/middleware/gas_price_strategy.py +20 -32
- web3/middleware/names.py +29 -26
- web3/middleware/proof_of_authority.py +68 -0
- web3/middleware/pythonic.py +2 -2
- web3/middleware/signing.py +74 -89
- web3/middleware/stalecheck.py +52 -79
- web3/middleware/validation.py +5 -13
- web3/module.py +54 -10
- web3/providers/__init__.py +10 -6
- web3/providers/async_base.py +117 -39
- web3/providers/auto.py +3 -3
- web3/providers/base.py +89 -33
- web3/providers/eth_tester/__init__.py +5 -0
- web3/providers/eth_tester/defaults.py +1 -64
- web3/providers/eth_tester/main.py +99 -31
- web3/providers/eth_tester/middleware.py +45 -73
- web3/providers/ipc.py +42 -46
- web3/providers/{websocket/websocket.py → legacy_websocket.py} +32 -7
- web3/providers/persistent/__init__.py +22 -0
- web3/providers/persistent/async_ipc.py +153 -0
- web3/providers/{persistent.py → persistent/persistent.py} +106 -25
- web3/providers/persistent/persistent_connection.py +84 -0
- web3/providers/{websocket → persistent}/request_processor.py +94 -32
- web3/providers/persistent/utils.py +43 -0
- web3/providers/{websocket/websocket_v2.py → persistent/websocket.py} +29 -28
- web3/providers/rpc/__init__.py +11 -0
- web3/providers/rpc/async_rpc.py +171 -0
- web3/providers/rpc/rpc.py +179 -0
- web3/providers/rpc/utils.py +92 -0
- web3/testing.py +4 -4
- web3/tools/benchmark/main.py +22 -22
- web3/tools/benchmark/node.py +2 -8
- web3/tools/benchmark/reporting.py +2 -2
- web3/tools/benchmark/utils.py +1 -1
- web3/tracing.py +9 -5
- web3/types.py +30 -107
- web3/utils/__init__.py +58 -5
- web3/utils/abi.py +575 -10
- web3/utils/async_exception_handling.py +19 -7
- web3/utils/caching.py +32 -13
- web3/utils/exception_handling.py +7 -5
- {web3-6.20.3.dist-info → web3-7.0.0.dist-info}/LICENSE +1 -1
- web3-7.0.0.dist-info/METADATA +112 -0
- web3-7.0.0.dist-info/RECORD +167 -0
- {web3-6.20.3.dist-info → web3-7.0.0.dist-info}/top_level.txt +0 -1
- ethpm/__init__.py +0 -20
- ethpm/_utils/__init__.py +0 -0
- ethpm/_utils/backend.py +0 -93
- ethpm/_utils/cache.py +0 -44
- ethpm/_utils/chains.py +0 -119
- ethpm/_utils/contract.py +0 -35
- ethpm/_utils/deployments.py +0 -145
- ethpm/_utils/ipfs.py +0 -116
- ethpm/_utils/protobuf/__init__.py +0 -0
- ethpm/_utils/protobuf/ipfs_file_pb2.py +0 -33
- ethpm/_utils/registry.py +0 -29
- ethpm/assets/__init__.py +0 -0
- ethpm/assets/ens/v3.json +0 -1
- ethpm/assets/escrow/with_bytecode_v3.json +0 -1
- ethpm/assets/ipfs_file.proto +0 -32
- ethpm/assets/owned/output_v3.json +0 -1
- ethpm/assets/owned/with_contract_type_v3.json +0 -1
- ethpm/assets/registry/contracts/Authority.sol +0 -156
- ethpm/assets/registry/contracts/IndexedOrderedSetLib.sol +0 -106
- ethpm/assets/registry/contracts/PackageDB.sol +0 -225
- ethpm/assets/registry/contracts/PackageRegistry.sol +0 -361
- ethpm/assets/registry/contracts/PackageRegistryInterface.sol +0 -97
- ethpm/assets/registry/contracts/ReleaseDB.sol +0 -309
- ethpm/assets/registry/contracts/ReleaseValidator.sol +0 -152
- ethpm/assets/registry/solc_input.json +0 -1
- ethpm/assets/registry/solc_output.json +0 -1
- ethpm/assets/registry/v3.json +0 -1
- ethpm/assets/safe-math-lib/v3-strict-no-deployments.json +0 -1
- ethpm/assets/simple-registry/contracts/Ownable.sol +0 -63
- ethpm/assets/simple-registry/contracts/PackageRegistry.sol +0 -373
- ethpm/assets/simple-registry/contracts/PackageRegistryInterface.sol +0 -96
- ethpm/assets/simple-registry/solc_input.json +0 -33
- ethpm/assets/simple-registry/solc_output.json +0 -1
- ethpm/assets/simple-registry/v3.json +0 -1
- ethpm/assets/standard-token/output_v3.json +0 -1
- ethpm/assets/standard-token/with_bytecode_v3.json +0 -1
- ethpm/assets/vyper_registry/0.1.0.json +0 -1
- ethpm/assets/vyper_registry/registry.vy +0 -216
- ethpm/assets/vyper_registry/registry_with_delete.vy +0 -244
- ethpm/backends/__init__.py +0 -0
- ethpm/backends/base.py +0 -43
- ethpm/backends/http.py +0 -108
- ethpm/backends/ipfs.py +0 -219
- ethpm/backends/registry.py +0 -154
- ethpm/constants.py +0 -17
- ethpm/contract.py +0 -187
- ethpm/dependencies.py +0 -58
- ethpm/deployments.py +0 -80
- ethpm/ethpm-spec/examples/escrow/1.0.0-pretty.json +0 -146
- ethpm/ethpm-spec/examples/escrow/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/escrow/contracts/Escrow.sol +0 -32
- ethpm/ethpm-spec/examples/escrow/contracts/SafeSendLib.sol +0 -20
- ethpm/ethpm-spec/examples/escrow/v3-pretty.json +0 -171
- ethpm/ethpm-spec/examples/escrow/v3.json +0 -1
- ethpm/ethpm-spec/examples/owned/1.0.0-pretty.json +0 -21
- ethpm/ethpm-spec/examples/owned/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/owned/contracts/Owned.sol +0 -12
- ethpm/ethpm-spec/examples/owned/v3-pretty.json +0 -27
- ethpm/ethpm-spec/examples/owned/v3.json +0 -1
- ethpm/ethpm-spec/examples/piper-coin/1.0.0-pretty.json +0 -31
- ethpm/ethpm-spec/examples/piper-coin/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/piper-coin/v3-pretty.json +0 -21
- ethpm/ethpm-spec/examples/piper-coin/v3.json +0 -1
- ethpm/ethpm-spec/examples/safe-math-lib/1.0.0-pretty.json +0 -85
- ethpm/ethpm-spec/examples/safe-math-lib/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/safe-math-lib/contracts/SafeMathLib.sol +0 -24
- ethpm/ethpm-spec/examples/safe-math-lib/v3-pretty.json +0 -117
- ethpm/ethpm-spec/examples/safe-math-lib/v3.json +0 -1
- ethpm/ethpm-spec/examples/standard-token/1.0.0-pretty.json +0 -55
- ethpm/ethpm-spec/examples/standard-token/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/standard-token/contracts/AbstractToken.sol +0 -20
- ethpm/ethpm-spec/examples/standard-token/contracts/StandardToken.sol +0 -84
- ethpm/ethpm-spec/examples/standard-token/v3-pretty.json +0 -460
- ethpm/ethpm-spec/examples/standard-token/v3.json +0 -1
- ethpm/ethpm-spec/examples/transferable/1.0.0-pretty.json +0 -21
- ethpm/ethpm-spec/examples/transferable/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/transferable/contracts/Transferable.sol +0 -14
- ethpm/ethpm-spec/examples/transferable/v3-pretty.json +0 -27
- ethpm/ethpm-spec/examples/transferable/v3.json +0 -1
- ethpm/ethpm-spec/examples/wallet/1.0.0-pretty.json +0 -120
- ethpm/ethpm-spec/examples/wallet/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/wallet/contracts/Wallet.sol +0 -41
- ethpm/ethpm-spec/examples/wallet/v3-pretty.json +0 -181
- ethpm/ethpm-spec/examples/wallet/v3.json +0 -1
- ethpm/ethpm-spec/examples/wallet-with-send/1.0.0-pretty.json +0 -135
- ethpm/ethpm-spec/examples/wallet-with-send/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/wallet-with-send/contracts/WalletWithSend.sol +0 -18
- ethpm/ethpm-spec/examples/wallet-with-send/v3-pretty.json +0 -207
- ethpm/ethpm-spec/examples/wallet-with-send/v3.json +0 -1
- ethpm/ethpm-spec/spec/package.spec.json +0 -379
- ethpm/ethpm-spec/spec/v3.spec.json +0 -483
- ethpm/exceptions.py +0 -68
- ethpm/package.py +0 -438
- ethpm/tools/__init__.py +0 -4
- ethpm/tools/builder.py +0 -930
- ethpm/tools/checker.py +0 -312
- ethpm/tools/get_manifest.py +0 -19
- ethpm/uri.py +0 -141
- ethpm/validation/__init__.py +0 -0
- ethpm/validation/manifest.py +0 -146
- ethpm/validation/misc.py +0 -39
- ethpm/validation/package.py +0 -80
- ethpm/validation/uri.py +0 -163
- web3/_utils/contract_sources/contract_data/address_reflector.py +0 -29
- web3/_utils/miner.py +0 -88
- web3/_utils/module_testing/go_ethereum_personal_module.py +0 -323
- web3/_utils/request.py +0 -265
- web3/middleware/abi.py +0 -11
- web3/middleware/async_cache.py +0 -99
- web3/middleware/cache.py +0 -374
- web3/middleware/exception_handling.py +0 -49
- web3/middleware/exception_retry_request.py +0 -188
- web3/middleware/fixture.py +0 -190
- web3/middleware/geth_poa.py +0 -81
- web3/middleware/normalize_request_parameters.py +0 -11
- web3/middleware/simulate_unmined_transaction.py +0 -43
- web3/pm.py +0 -602
- web3/providers/async_rpc.py +0 -99
- web3/providers/rpc.py +0 -98
- web3/providers/websocket/__init__.py +0 -11
- web3/providers/websocket/websocket_connection.py +0 -42
- web3/tools/__init__.py +0 -4
- web3/tools/pytest_ethereum/__init__.py +0 -0
- web3/tools/pytest_ethereum/_utils.py +0 -145
- web3/tools/pytest_ethereum/deployer.py +0 -48
- web3/tools/pytest_ethereum/exceptions.py +0 -22
- web3/tools/pytest_ethereum/linker.py +0 -128
- web3/tools/pytest_ethereum/plugins.py +0 -33
- web3-6.20.3.dist-info/METADATA +0 -104
- web3-6.20.3.dist-info/RECORD +0 -283
- web3-6.20.3.dist-info/entry_points.txt +0 -2
- /web3/_utils/{function_identifiers.py → abi_element_identifiers.py} +0 -0
- {web3-6.20.3.dist-info → web3-7.0.0.dist-info}/WHEEL +0 -0
web3/_utils/decorators.py
CHANGED
|
@@ -8,6 +8,10 @@ from typing import (
|
|
|
8
8
|
)
|
|
9
9
|
import warnings
|
|
10
10
|
|
|
11
|
+
from web3.exceptions import (
|
|
12
|
+
Web3ValueError,
|
|
13
|
+
)
|
|
14
|
+
|
|
11
15
|
TFunc = TypeVar("TFunc", bound=Callable[..., Any])
|
|
12
16
|
|
|
13
17
|
|
|
@@ -24,7 +28,7 @@ def reject_recursive_repeats(to_wrap: Callable[..., Any]) -> Callable[..., Any]:
|
|
|
24
28
|
thread_id = threading.get_ident()
|
|
25
29
|
thread_local_args = (thread_id,) + arg_instances
|
|
26
30
|
if thread_local_args in to_wrap.__already_called: # type: ignore
|
|
27
|
-
raise
|
|
31
|
+
raise Web3ValueError(f"Recursively called {to_wrap} with {args!r}")
|
|
28
32
|
to_wrap.__already_called[thread_local_args] = True # type: ignore
|
|
29
33
|
try:
|
|
30
34
|
wrapped_val = to_wrap(*args)
|
|
@@ -35,37 +39,23 @@ def reject_recursive_repeats(to_wrap: Callable[..., Any]) -> Callable[..., Any]:
|
|
|
35
39
|
return wrapped
|
|
36
40
|
|
|
37
41
|
|
|
38
|
-
def
|
|
39
|
-
replacement_method: str = None, deprecation_msg: str = None
|
|
40
|
-
) -> Callable[..., Any]:
|
|
42
|
+
def deprecated_for(replace_message: str) -> Callable[..., Any]:
|
|
41
43
|
"""
|
|
42
|
-
Decorate a deprecated function with info
|
|
43
|
-
reason for the deprecation.
|
|
44
|
-
|
|
45
|
-
@deprecate_method("to_bytes()")
|
|
46
|
-
def to_ascii(arg):
|
|
47
|
-
...
|
|
44
|
+
Decorate a deprecated function, with info about what to use instead, like:
|
|
48
45
|
|
|
49
|
-
@
|
|
50
|
-
|
|
51
|
-
))
|
|
52
|
-
def some_method(arg):
|
|
46
|
+
@deprecated_for("to_bytes()")
|
|
47
|
+
def toAscii(arg):
|
|
53
48
|
...
|
|
54
49
|
"""
|
|
55
|
-
if replacement_method is None and deprecation_msg is None:
|
|
56
|
-
raise ValueError(
|
|
57
|
-
"Must provide either `replacement_method` or `deprecation_msg`"
|
|
58
|
-
)
|
|
59
50
|
|
|
60
51
|
def decorator(to_wrap: TFunc) -> TFunc:
|
|
61
52
|
@functools.wraps(to_wrap)
|
|
62
53
|
def wrapper(*args: Any, **kwargs: Any) -> Callable[..., Any]:
|
|
63
|
-
|
|
64
|
-
f"{to_wrap.__name__} is deprecated in favor of {
|
|
65
|
-
|
|
66
|
-
|
|
54
|
+
warnings.warn(
|
|
55
|
+
f"{to_wrap.__name__} is deprecated in favor of {replace_message}",
|
|
56
|
+
category=DeprecationWarning,
|
|
57
|
+
stacklevel=2,
|
|
67
58
|
)
|
|
68
|
-
warnings.warn(msg, category=DeprecationWarning)
|
|
69
59
|
return to_wrap(*args, **kwargs)
|
|
70
60
|
|
|
71
61
|
return cast(TFunc, wrapper)
|
web3/_utils/empty.py
CHANGED
web3/_utils/encoding.py
CHANGED
|
@@ -55,6 +55,10 @@ from web3._utils.validation import (
|
|
|
55
55
|
from web3.datastructures import (
|
|
56
56
|
AttributeDict,
|
|
57
57
|
)
|
|
58
|
+
from web3.exceptions import (
|
|
59
|
+
Web3TypeError,
|
|
60
|
+
Web3ValueError,
|
|
61
|
+
)
|
|
58
62
|
|
|
59
63
|
|
|
60
64
|
def hex_encode_abi_type(
|
|
@@ -90,7 +94,7 @@ def hex_encode_abi_type(
|
|
|
90
94
|
elif is_string_type(abi_type):
|
|
91
95
|
return to_hex(text=value)
|
|
92
96
|
else:
|
|
93
|
-
raise
|
|
97
|
+
raise Web3ValueError(f"Unsupported ABI type: {abi_type}")
|
|
94
98
|
|
|
95
99
|
|
|
96
100
|
def to_hex_twos_compliment(value: Any, bit_size: int) -> HexStr:
|
|
@@ -169,7 +173,7 @@ def hexstr_if_str(
|
|
|
169
173
|
if isinstance(hexstr_or_primitive, str):
|
|
170
174
|
(primitive, hexstr) = (None, hexstr_or_primitive)
|
|
171
175
|
if remove_0x_prefix(HexStr(hexstr)) and not is_hex(hexstr):
|
|
172
|
-
raise
|
|
176
|
+
raise Web3ValueError(
|
|
173
177
|
"when sending a str, it must be a hex string. "
|
|
174
178
|
f"Got: {hexstr_or_primitive!r}"
|
|
175
179
|
)
|
|
@@ -210,12 +214,12 @@ class FriendlyJsonSerde:
|
|
|
210
214
|
except TypeError as full_exception:
|
|
211
215
|
if hasattr(obj, "items"):
|
|
212
216
|
item_errors = "; ".join(self._json_mapping_errors(obj))
|
|
213
|
-
raise
|
|
217
|
+
raise Web3TypeError(
|
|
214
218
|
f"dict had unencodable value at keys: {{{item_errors}}}"
|
|
215
219
|
)
|
|
216
220
|
elif is_list_like(obj):
|
|
217
221
|
element_errors = "; ".join(self._json_list_errors(obj))
|
|
218
|
-
raise
|
|
222
|
+
raise Web3TypeError(
|
|
219
223
|
f"list had unencodable value at index: [{element_errors}]"
|
|
220
224
|
)
|
|
221
225
|
else:
|
|
@@ -237,14 +241,16 @@ class FriendlyJsonSerde:
|
|
|
237
241
|
try:
|
|
238
242
|
return self._friendly_json_encode(obj, cls=cls)
|
|
239
243
|
except TypeError as exc:
|
|
240
|
-
raise
|
|
244
|
+
raise Web3TypeError(f"Could not encode to JSON: {exc}")
|
|
241
245
|
|
|
242
246
|
|
|
243
247
|
def to_4byte_hex(hex_or_str_or_bytes: Union[HexStr, str, bytes, int]) -> HexStr:
|
|
244
248
|
size_of_4bytes = 4 * 8
|
|
245
249
|
byte_str = hexstr_if_str(to_bytes, hex_or_str_or_bytes)
|
|
246
250
|
if len(byte_str) > 4:
|
|
247
|
-
raise
|
|
251
|
+
raise Web3ValueError(
|
|
252
|
+
f"expected value of size 4 bytes. Got: {len(byte_str)} bytes"
|
|
253
|
+
)
|
|
248
254
|
hex_str = encode_hex(byte_str)
|
|
249
255
|
return pad_hex(hex_str, size_of_4bytes)
|
|
250
256
|
|
|
@@ -253,7 +259,7 @@ class DynamicArrayPackedEncoder(BaseArrayEncoder):
|
|
|
253
259
|
is_dynamic = True
|
|
254
260
|
|
|
255
261
|
def encode(self, value: Sequence[Any]) -> bytes:
|
|
256
|
-
encoded_elements = self.encode_elements(value)
|
|
262
|
+
encoded_elements = self.encode_elements(value) # type: ignore[no-untyped-call]
|
|
257
263
|
encoded_value = encoded_elements
|
|
258
264
|
|
|
259
265
|
return encoded_value
|
|
@@ -272,10 +278,10 @@ def encode_single_packed(_type: TypeStr, value: Any) -> bytes:
|
|
|
272
278
|
)
|
|
273
279
|
|
|
274
280
|
abi_type = abi_type_parser.parse(_type)
|
|
275
|
-
if has_arrlist(_type):
|
|
281
|
+
if has_arrlist(_type): # type: ignore[no-untyped-call]
|
|
276
282
|
item_encoder = registry.get_encoder(abi_type.item_type.to_type_str())
|
|
277
283
|
if abi_type.arrlist[-1] != 1:
|
|
278
|
-
return DynamicArrayPackedEncoder(item_encoder=item_encoder).encode(value)
|
|
284
|
+
return DynamicArrayPackedEncoder(item_encoder=item_encoder).encode(value) # type: ignore[no-untyped-call] # noqa: E501
|
|
279
285
|
else:
|
|
280
286
|
raise NotImplementedError(
|
|
281
287
|
"Fixed arrays are not implemented in this packed encoder prototype"
|
|
@@ -291,9 +297,7 @@ class Web3JsonEncoder(json.JSONEncoder):
|
|
|
291
297
|
def default(self, obj: Any) -> Union[Dict[Any, Any], HexStr]:
|
|
292
298
|
if isinstance(obj, AttributeDict):
|
|
293
299
|
return obj.__dict__
|
|
294
|
-
elif isinstance(obj, HexBytes):
|
|
295
|
-
return HexStr(obj.hex())
|
|
296
|
-
elif isinstance(obj, bytes):
|
|
300
|
+
elif isinstance(obj, (HexBytes, bytes)):
|
|
297
301
|
return to_hex(obj)
|
|
298
302
|
return json.JSONEncoder.default(self, obj)
|
|
299
303
|
|
web3/_utils/ens.py
CHANGED
|
@@ -17,6 +17,7 @@ from eth_utils import (
|
|
|
17
17
|
is_0x_prefixed,
|
|
18
18
|
is_hex,
|
|
19
19
|
is_hex_address,
|
|
20
|
+
to_checksum_address,
|
|
20
21
|
)
|
|
21
22
|
|
|
22
23
|
from ens import (
|
|
@@ -51,7 +52,7 @@ def is_ens_name(value: Any) -> bool:
|
|
|
51
52
|
def validate_name_has_address(ens: ENS, name: str) -> ChecksumAddress:
|
|
52
53
|
addr = ens.address(name)
|
|
53
54
|
if addr:
|
|
54
|
-
return addr
|
|
55
|
+
return to_checksum_address(addr)
|
|
55
56
|
else:
|
|
56
57
|
raise NameNotFound(f"Could not find address for name {name!r}")
|
|
57
58
|
|
|
@@ -13,6 +13,7 @@ from web3.exceptions import (
|
|
|
13
13
|
ContractPanicError,
|
|
14
14
|
OffchainLookup,
|
|
15
15
|
TransactionIndexingInProgress,
|
|
16
|
+
Web3ValueError,
|
|
16
17
|
)
|
|
17
18
|
from web3.types import (
|
|
18
19
|
RPCResponse,
|
|
@@ -76,7 +77,9 @@ def _parse_error_with_reverted_prefix(data: str) -> str:
|
|
|
76
77
|
try:
|
|
77
78
|
error = bytes.fromhex(error).decode("utf8")
|
|
78
79
|
except UnicodeDecodeError:
|
|
79
|
-
warnings.warn(
|
|
80
|
+
warnings.warn(
|
|
81
|
+
"Could not decode revert reason as UTF-8", RuntimeWarning, stacklevel=2
|
|
82
|
+
)
|
|
80
83
|
raise ContractLogicError("execution reverted", data=data)
|
|
81
84
|
|
|
82
85
|
return error
|
|
@@ -140,7 +143,7 @@ def raise_contract_logic_error_on_revert(response: RPCResponse) -> RPCResponse:
|
|
|
140
143
|
"""
|
|
141
144
|
error = response.get("error")
|
|
142
145
|
if error is None or isinstance(error, str):
|
|
143
|
-
raise
|
|
146
|
+
raise Web3ValueError(error)
|
|
144
147
|
|
|
145
148
|
message = error.get("message")
|
|
146
149
|
message_present = message is not None and message != ""
|
|
@@ -172,7 +175,6 @@ def raise_transaction_indexing_error_if_indexing(response: RPCResponse) -> RPCRe
|
|
|
172
175
|
Raise an error if ``eth_getTransactionReceipt`` returns an error indicating that
|
|
173
176
|
transactions are still being indexed.
|
|
174
177
|
"""
|
|
175
|
-
|
|
176
178
|
error = response.get("error")
|
|
177
179
|
if not isinstance(error, str) and error is not None:
|
|
178
180
|
message = error.get("message")
|
web3/_utils/events.py
CHANGED
|
@@ -27,6 +27,9 @@ from eth_abi.codec import (
|
|
|
27
27
|
ABICodec,
|
|
28
28
|
)
|
|
29
29
|
from eth_typing import (
|
|
30
|
+
ABIComponent,
|
|
31
|
+
ABIComponentIndexed,
|
|
32
|
+
ABIEvent,
|
|
30
33
|
ChecksumAddress,
|
|
31
34
|
HexStr,
|
|
32
35
|
Primitives,
|
|
@@ -34,7 +37,6 @@ from eth_typing import (
|
|
|
34
37
|
)
|
|
35
38
|
from eth_utils import (
|
|
36
39
|
encode_hex,
|
|
37
|
-
event_abi_to_log_topic,
|
|
38
40
|
is_list_like,
|
|
39
41
|
keccak,
|
|
40
42
|
to_bytes,
|
|
@@ -42,6 +44,11 @@ from eth_utils import (
|
|
|
42
44
|
to_hex,
|
|
43
45
|
to_tuple,
|
|
44
46
|
)
|
|
47
|
+
from eth_utils.abi import (
|
|
48
|
+
collapse_if_tuple,
|
|
49
|
+
event_abi_to_log_topic,
|
|
50
|
+
get_abi_input_names,
|
|
51
|
+
)
|
|
45
52
|
from eth_utils.curried import (
|
|
46
53
|
apply_formatter_if,
|
|
47
54
|
)
|
|
@@ -57,7 +64,6 @@ import web3
|
|
|
57
64
|
from web3._utils.abi import (
|
|
58
65
|
exclude_indexed_event_inputs,
|
|
59
66
|
get_indexed_event_inputs,
|
|
60
|
-
get_normalized_abi_arg_type,
|
|
61
67
|
map_abi_data,
|
|
62
68
|
named_tree,
|
|
63
69
|
normalize_event_input_types,
|
|
@@ -75,18 +81,16 @@ from web3.datastructures import (
|
|
|
75
81
|
from web3.exceptions import (
|
|
76
82
|
InvalidEventABI,
|
|
77
83
|
LogTopicError,
|
|
78
|
-
|
|
84
|
+
Web3ValueError,
|
|
79
85
|
)
|
|
80
86
|
from web3.types import (
|
|
81
|
-
ABIEvent,
|
|
82
|
-
ABIEventParams,
|
|
83
87
|
BlockIdentifier,
|
|
84
88
|
EventData,
|
|
85
89
|
FilterParams,
|
|
86
90
|
LogReceipt,
|
|
87
91
|
)
|
|
88
|
-
from web3.utils import (
|
|
89
|
-
|
|
92
|
+
from web3.utils.abi import (
|
|
93
|
+
get_event_log_topics,
|
|
90
94
|
)
|
|
91
95
|
|
|
92
96
|
if TYPE_CHECKING:
|
|
@@ -109,13 +113,13 @@ def _log_entry_data_to_bytes(
|
|
|
109
113
|
def construct_event_topic_set(
|
|
110
114
|
event_abi: ABIEvent,
|
|
111
115
|
abi_codec: ABICodec,
|
|
112
|
-
arguments: Optional[Union[
|
|
116
|
+
arguments: Optional[Union[List[Any], Tuple[Any], Dict[str, Any]]] = None,
|
|
113
117
|
) -> List[HexStr]:
|
|
114
118
|
if arguments is None:
|
|
115
119
|
arguments = {}
|
|
116
|
-
|
|
120
|
+
elif isinstance(arguments, (list, tuple)):
|
|
117
121
|
if len(arguments) != len(event_abi["inputs"]):
|
|
118
|
-
raise
|
|
122
|
+
raise Web3ValueError(
|
|
119
123
|
"When passing an argument list, the number of arguments must "
|
|
120
124
|
"match the event constructor."
|
|
121
125
|
)
|
|
@@ -123,16 +127,12 @@ def construct_event_topic_set(
|
|
|
123
127
|
arg["name"]: [arg_value]
|
|
124
128
|
for arg, arg_value in zip(event_abi["inputs"], arguments)
|
|
125
129
|
}
|
|
126
|
-
|
|
127
130
|
normalized_args = {
|
|
128
131
|
key: value if is_list_like(value) else [value]
|
|
129
|
-
|
|
130
|
-
for key, value in arguments.items() # type: ignore
|
|
132
|
+
for key, value in arguments.items()
|
|
131
133
|
}
|
|
132
134
|
|
|
133
|
-
|
|
134
|
-
# https://github.com/python/mypy/issues/4976
|
|
135
|
-
event_topic = encode_hex(event_abi_to_log_topic(event_abi)) # type: ignore
|
|
135
|
+
event_topic = encode_hex(event_abi_to_log_topic(event_abi))
|
|
136
136
|
indexed_args = get_indexed_event_inputs(event_abi)
|
|
137
137
|
zipped_abi_and_args = [
|
|
138
138
|
(arg, normalized_args.get(arg["name"], [None])) for arg in indexed_args
|
|
@@ -162,7 +162,7 @@ def construct_event_data_set(
|
|
|
162
162
|
arguments = {}
|
|
163
163
|
if isinstance(arguments, (list, tuple)):
|
|
164
164
|
if len(arguments) != len(event_abi["inputs"]):
|
|
165
|
-
raise
|
|
165
|
+
raise Web3ValueError(
|
|
166
166
|
"When passing an argument list, the number of arguments must "
|
|
167
167
|
"match the event constructor."
|
|
168
168
|
)
|
|
@@ -207,7 +207,7 @@ def is_dynamic_sized_type(type_str: TypeStr) -> bool:
|
|
|
207
207
|
|
|
208
208
|
@to_tuple
|
|
209
209
|
def get_event_abi_types_for_decoding(
|
|
210
|
-
event_inputs: Sequence[
|
|
210
|
+
event_inputs: Sequence[Union[ABIComponent, ABIComponentIndexed]],
|
|
211
211
|
) -> Iterable[TypeStr]:
|
|
212
212
|
"""
|
|
213
213
|
Event logs use the `keccak(value)` for indexed inputs of type `bytes` or
|
|
@@ -215,10 +215,10 @@ def get_event_abi_types_for_decoding(
|
|
|
215
215
|
decode the log entries using the correct types.
|
|
216
216
|
"""
|
|
217
217
|
for input_abi in event_inputs:
|
|
218
|
-
if input_abi
|
|
218
|
+
if input_abi.get("indexed") and is_dynamic_sized_type(input_abi["type"]):
|
|
219
219
|
yield "bytes32"
|
|
220
220
|
else:
|
|
221
|
-
yield
|
|
221
|
+
yield collapse_if_tuple(input_abi)
|
|
222
222
|
|
|
223
223
|
|
|
224
224
|
@curry
|
|
@@ -231,22 +231,14 @@ def get_event_data(
|
|
|
231
231
|
Given an event ABI and a log entry for that event, return the decoded
|
|
232
232
|
event data
|
|
233
233
|
"""
|
|
234
|
-
|
|
235
|
-
log_topics = log_entry["topics"]
|
|
236
|
-
elif not log_entry["topics"]:
|
|
237
|
-
raise MismatchedABI("Expected non-anonymous event to have 1 or more topics")
|
|
238
|
-
elif event_abi_to_log_topic(dict(event_abi)) != _log_entry_data_to_bytes(
|
|
239
|
-
log_entry["topics"][0]
|
|
240
|
-
):
|
|
241
|
-
raise MismatchedABI("The event signature did not match the provided ABI")
|
|
242
|
-
else:
|
|
243
|
-
log_topics = log_entry["topics"][1:]
|
|
244
|
-
|
|
234
|
+
log_topics = get_event_log_topics(event_abi, log_entry["topics"])
|
|
245
235
|
log_topics_bytes = [_log_entry_data_to_bytes(topic) for topic in log_topics]
|
|
246
236
|
log_topics_abi = get_indexed_event_inputs(event_abi)
|
|
247
237
|
log_topic_normalized_inputs = normalize_event_input_types(log_topics_abi)
|
|
248
238
|
log_topic_types = get_event_abi_types_for_decoding(log_topic_normalized_inputs)
|
|
249
|
-
log_topic_names = get_abi_input_names(
|
|
239
|
+
log_topic_names = get_abi_input_names(
|
|
240
|
+
ABIEvent({"name": event_abi["name"], "type": "event", "inputs": log_topics_abi})
|
|
241
|
+
)
|
|
250
242
|
|
|
251
243
|
if len(log_topics_bytes) != len(log_topic_types):
|
|
252
244
|
raise LogTopicError(
|
|
@@ -257,7 +249,9 @@ def get_event_data(
|
|
|
257
249
|
log_data_abi = exclude_indexed_event_inputs(event_abi)
|
|
258
250
|
log_data_normalized_inputs = normalize_event_input_types(log_data_abi)
|
|
259
251
|
log_data_types = get_event_abi_types_for_decoding(log_data_normalized_inputs)
|
|
260
|
-
log_data_names = get_abi_input_names(
|
|
252
|
+
log_data_names = get_abi_input_names(
|
|
253
|
+
ABIEvent({"name": event_abi["name"], "type": "event", "inputs": log_data_abi})
|
|
254
|
+
)
|
|
261
255
|
|
|
262
256
|
# sanity check that there are not name intersections between the topic
|
|
263
257
|
# names and the data argument names.
|
|
@@ -341,8 +335,8 @@ is_not_indexed = complement(is_indexed)
|
|
|
341
335
|
|
|
342
336
|
class BaseEventFilterBuilder:
|
|
343
337
|
formatter = None
|
|
344
|
-
|
|
345
|
-
|
|
338
|
+
_from_block = None
|
|
339
|
+
_to_block = None
|
|
346
340
|
_address = None
|
|
347
341
|
_immutable = False
|
|
348
342
|
|
|
@@ -362,30 +356,30 @@ class BaseEventFilterBuilder:
|
|
|
362
356
|
self._ordered_arg_names = tuple(arg["name"] for arg in event_abi["inputs"])
|
|
363
357
|
|
|
364
358
|
@property
|
|
365
|
-
def
|
|
366
|
-
return self.
|
|
359
|
+
def from_block(self) -> BlockIdentifier:
|
|
360
|
+
return self._from_block
|
|
367
361
|
|
|
368
|
-
@
|
|
369
|
-
def
|
|
370
|
-
if self.
|
|
371
|
-
self.
|
|
362
|
+
@from_block.setter
|
|
363
|
+
def from_block(self, value: BlockIdentifier) -> None:
|
|
364
|
+
if self._from_block is None and not self._immutable:
|
|
365
|
+
self._from_block = value
|
|
372
366
|
else:
|
|
373
|
-
raise
|
|
374
|
-
f"
|
|
367
|
+
raise Web3ValueError(
|
|
368
|
+
f"from_block is already set to {self._from_block!r}. "
|
|
375
369
|
"Resetting filter parameters is not permitted"
|
|
376
370
|
)
|
|
377
371
|
|
|
378
372
|
@property
|
|
379
|
-
def
|
|
380
|
-
return self.
|
|
373
|
+
def to_block(self) -> BlockIdentifier:
|
|
374
|
+
return self._to_block
|
|
381
375
|
|
|
382
|
-
@
|
|
383
|
-
def
|
|
384
|
-
if self.
|
|
385
|
-
self.
|
|
376
|
+
@to_block.setter
|
|
377
|
+
def to_block(self, value: BlockIdentifier) -> None:
|
|
378
|
+
if self._to_block is None and not self._immutable:
|
|
379
|
+
self._to_block = value
|
|
386
380
|
else:
|
|
387
|
-
raise
|
|
388
|
-
f"toBlock is already set to {self.
|
|
381
|
+
raise Web3ValueError(
|
|
382
|
+
f"toBlock is already set to {self._to_block!r}. "
|
|
389
383
|
"Resetting filter parameters is not permitted"
|
|
390
384
|
)
|
|
391
385
|
|
|
@@ -398,7 +392,7 @@ class BaseEventFilterBuilder:
|
|
|
398
392
|
if self._address is None and not self._immutable:
|
|
399
393
|
self._address = value
|
|
400
394
|
else:
|
|
401
|
-
raise
|
|
395
|
+
raise Web3ValueError(
|
|
402
396
|
f"address is already set to {self.address!r}. "
|
|
403
397
|
"Resetting filter parameters is not permitted"
|
|
404
398
|
)
|
|
@@ -433,8 +427,8 @@ class BaseEventFilterBuilder:
|
|
|
433
427
|
def filter_params(self) -> FilterParams:
|
|
434
428
|
params = {
|
|
435
429
|
"topics": self.topics,
|
|
436
|
-
"fromBlock": self.
|
|
437
|
-
"toBlock": self.
|
|
430
|
+
"fromBlock": self.from_block,
|
|
431
|
+
"toBlock": self.to_block,
|
|
438
432
|
"address": self.address,
|
|
439
433
|
}
|
|
440
434
|
return valfilter(lambda x: x is not None, params)
|
|
@@ -443,10 +437,10 @@ class BaseEventFilterBuilder:
|
|
|
443
437
|
class EventFilterBuilder(BaseEventFilterBuilder):
|
|
444
438
|
def deploy(self, w3: "Web3") -> "LogFilter":
|
|
445
439
|
if not isinstance(w3, web3.Web3):
|
|
446
|
-
raise
|
|
440
|
+
raise Web3ValueError(f"Invalid web3 argument: got: {w3!r}")
|
|
447
441
|
|
|
448
|
-
for arg in
|
|
449
|
-
arg._immutable = True
|
|
442
|
+
for arg in self.args.values():
|
|
443
|
+
arg._immutable = True
|
|
450
444
|
self._immutable = True
|
|
451
445
|
|
|
452
446
|
log_filter = cast("LogFilter", w3.eth.filter(self.filter_params))
|
|
@@ -461,10 +455,10 @@ class EventFilterBuilder(BaseEventFilterBuilder):
|
|
|
461
455
|
class AsyncEventFilterBuilder(BaseEventFilterBuilder):
|
|
462
456
|
async def deploy(self, async_w3: "AsyncWeb3") -> "AsyncLogFilter":
|
|
463
457
|
if not isinstance(async_w3, web3.AsyncWeb3):
|
|
464
|
-
raise
|
|
458
|
+
raise Web3ValueError(f"Invalid web3 argument: got: {async_w3!r}")
|
|
465
459
|
|
|
466
|
-
for arg in
|
|
467
|
-
arg._immutable = True
|
|
460
|
+
for arg in self.args.values():
|
|
461
|
+
arg._immutable = True
|
|
468
462
|
self._immutable = True
|
|
469
463
|
|
|
470
464
|
log_filter = await async_w3.eth.filter(self.filter_params)
|
|
@@ -479,8 +473,7 @@ class AsyncEventFilterBuilder(BaseEventFilterBuilder):
|
|
|
479
473
|
|
|
480
474
|
def initialize_event_topics(event_abi: ABIEvent) -> Union[bytes, List[Any]]:
|
|
481
475
|
if event_abi["anonymous"] is False:
|
|
482
|
-
|
|
483
|
-
return event_abi_to_log_topic(event_abi) # type: ignore
|
|
476
|
+
return event_abi_to_log_topic(event_abi)
|
|
484
477
|
else:
|
|
485
478
|
return list()
|
|
486
479
|
|
|
@@ -492,12 +485,12 @@ def _build_argument_filters_from_event_abi(
|
|
|
492
485
|
for item in event_abi["inputs"]:
|
|
493
486
|
key = item["name"]
|
|
494
487
|
value: "BaseArgumentFilter"
|
|
495
|
-
if item
|
|
488
|
+
if item.get("indexed") is True:
|
|
496
489
|
value = TopicArgumentFilter(
|
|
497
|
-
abi_codec=abi_codec, arg_type=
|
|
490
|
+
abi_codec=abi_codec, arg_type=collapse_if_tuple(item)
|
|
498
491
|
)
|
|
499
492
|
else:
|
|
500
|
-
value = DataArgumentFilter(arg_type=
|
|
493
|
+
value = DataArgumentFilter(arg_type=collapse_if_tuple(item))
|
|
501
494
|
yield key, value
|
|
502
495
|
|
|
503
496
|
|
|
@@ -519,19 +512,23 @@ class BaseArgumentFilter(ABC):
|
|
|
519
512
|
|
|
520
513
|
def match_single(self, value: Any) -> None:
|
|
521
514
|
if self._immutable:
|
|
522
|
-
raise
|
|
515
|
+
raise Web3ValueError(
|
|
516
|
+
"Setting values is forbidden after filter is deployed."
|
|
517
|
+
)
|
|
523
518
|
if self._match_values is None:
|
|
524
519
|
self._match_values = _normalize_match_values((value,))
|
|
525
520
|
else:
|
|
526
|
-
raise
|
|
521
|
+
raise Web3ValueError("An argument match value/s has already been set.")
|
|
527
522
|
|
|
528
523
|
def match_any(self, *values: Collection[Any]) -> None:
|
|
529
524
|
if self._immutable:
|
|
530
|
-
raise
|
|
525
|
+
raise Web3ValueError(
|
|
526
|
+
"Setting values is forbidden after filter is deployed."
|
|
527
|
+
)
|
|
531
528
|
if self._match_values is None:
|
|
532
529
|
self._match_values = _normalize_match_values(values)
|
|
533
530
|
else:
|
|
534
|
-
raise
|
|
531
|
+
raise Web3ValueError("An argument match value/s has already been set.")
|
|
535
532
|
|
|
536
533
|
@property
|
|
537
534
|
@abstractmethod
|
web3/_utils/fee_utils.py
CHANGED
|
@@ -53,7 +53,5 @@ async def async_fee_history_priority_fee(async_eth: "AsyncEth") -> Wei:
|
|
|
53
53
|
# This is a tested internal call so no need for type hinting. We can keep
|
|
54
54
|
# better consistency between the sync and async calls by unpacking
|
|
55
55
|
# PRIORITY_FEE_HISTORY_PARAMS as constants here.
|
|
56
|
-
fee_history = await async_eth.fee_history(
|
|
57
|
-
*PRIORITY_FEE_HISTORY_PARAMS # type: ignore
|
|
58
|
-
)
|
|
56
|
+
fee_history = await async_eth.fee_history(*PRIORITY_FEE_HISTORY_PARAMS) # type: ignore # noqa: E501
|
|
59
57
|
return _fee_history_priority_fee_estimate(fee_history)
|