web3 6.20.2__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.2.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.2.dist-info → web3-7.0.0.dist-info}/WHEEL +1 -1
- {web3-6.20.2.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.2.dist-info/METADATA +0 -103
- web3-6.20.2.dist-info/RECORD +0 -283
- web3-6.20.2.dist-info/entry_points.txt +0 -2
- /web3/_utils/{function_identifiers.py → abi_element_identifiers.py} +0 -0
web3/datastructures.py
CHANGED
|
@@ -28,6 +28,11 @@ from eth_utils import (
|
|
|
28
28
|
from web3._utils.formatters import (
|
|
29
29
|
recursive_map,
|
|
30
30
|
)
|
|
31
|
+
from web3.exceptions import (
|
|
32
|
+
Web3AssertionError,
|
|
33
|
+
Web3TypeError,
|
|
34
|
+
Web3ValueError,
|
|
35
|
+
)
|
|
31
36
|
|
|
32
37
|
# Hashable must be immutable:
|
|
33
38
|
# "the implementation of hashable collections requires that a
|
|
@@ -85,7 +90,10 @@ class ReadableAttributeDict(Mapping[TKey, TValue]):
|
|
|
85
90
|
|
|
86
91
|
@classmethod
|
|
87
92
|
def recursive(cls, value: TValue) -> "ReadableAttributeDict[TKey, TValue]":
|
|
88
|
-
return
|
|
93
|
+
return cast(
|
|
94
|
+
"ReadableAttributeDict[TKey, TValue]",
|
|
95
|
+
recursive_map(cls._apply_if_mapping, value),
|
|
96
|
+
)
|
|
89
97
|
|
|
90
98
|
|
|
91
99
|
class MutableAttributeDict(
|
|
@@ -100,19 +108,21 @@ class MutableAttributeDict(
|
|
|
100
108
|
|
|
101
109
|
class AttributeDict(ReadableAttributeDict[TKey, TValue], Hashable):
|
|
102
110
|
"""
|
|
103
|
-
|
|
111
|
+
Provides superficial immutability, someone could hack around it
|
|
104
112
|
"""
|
|
105
113
|
|
|
106
114
|
def __setattr__(self, attr: str, val: TValue) -> None:
|
|
107
115
|
if attr == "__dict__":
|
|
108
116
|
super().__setattr__(attr, val)
|
|
109
117
|
else:
|
|
110
|
-
raise
|
|
118
|
+
raise Web3TypeError(
|
|
111
119
|
"This data is immutable -- create a copy instead of modifying"
|
|
112
120
|
)
|
|
113
121
|
|
|
114
122
|
def __delattr__(self, key: str) -> None:
|
|
115
|
-
raise
|
|
123
|
+
raise Web3TypeError(
|
|
124
|
+
"This data is immutable -- create a copy instead of modifying"
|
|
125
|
+
)
|
|
116
126
|
|
|
117
127
|
def __hash__(self) -> int:
|
|
118
128
|
return hash(tuple(sorted(tupleize_lists_nested(self).items())))
|
|
@@ -143,7 +153,7 @@ def tupleize_lists_nested(d: Mapping[TKey, TValue]) -> AttributeDict[TKey, TValu
|
|
|
143
153
|
elif isinstance(v, Mapping):
|
|
144
154
|
ret[k] = tupleize_lists_nested(v)
|
|
145
155
|
elif not isinstance(v, Hashable):
|
|
146
|
-
raise
|
|
156
|
+
raise Web3TypeError(f"Found unhashable type '{type(v).__name__}': {v}")
|
|
147
157
|
else:
|
|
148
158
|
ret[k] = v
|
|
149
159
|
return AttributeDict(ret)
|
|
@@ -172,11 +182,13 @@ class NamedElementOnion(Mapping[TKey, TValue]):
|
|
|
172
182
|
if name is None:
|
|
173
183
|
name = cast(TKey, element)
|
|
174
184
|
|
|
185
|
+
name = self._repr_if_not_hashable(name)
|
|
186
|
+
|
|
175
187
|
if name in self._queue:
|
|
176
188
|
if name is element:
|
|
177
|
-
raise
|
|
189
|
+
raise Web3ValueError("You can't add the same un-named instance twice")
|
|
178
190
|
else:
|
|
179
|
-
raise
|
|
191
|
+
raise Web3ValueError(
|
|
180
192
|
"You can't add the same name again, use replace instead"
|
|
181
193
|
)
|
|
182
194
|
|
|
@@ -193,7 +205,7 @@ class NamedElementOnion(Mapping[TKey, TValue]):
|
|
|
193
205
|
to calling :meth:`add` .
|
|
194
206
|
"""
|
|
195
207
|
if not is_integer(layer):
|
|
196
|
-
raise
|
|
208
|
+
raise Web3TypeError("The layer for insertion must be an int.")
|
|
197
209
|
elif layer != 0 and layer != len(self._queue):
|
|
198
210
|
raise NotImplementedError(
|
|
199
211
|
f"You can only insert to the beginning or end of a {type(self)}, "
|
|
@@ -206,11 +218,14 @@ class NamedElementOnion(Mapping[TKey, TValue]):
|
|
|
206
218
|
if layer == 0:
|
|
207
219
|
if name is None:
|
|
208
220
|
name = cast(TKey, element)
|
|
221
|
+
|
|
222
|
+
name = self._repr_if_not_hashable(name)
|
|
223
|
+
|
|
209
224
|
self._queue.move_to_end(name, last=False)
|
|
210
225
|
elif layer == len(self._queue):
|
|
211
226
|
return
|
|
212
227
|
else:
|
|
213
|
-
raise
|
|
228
|
+
raise Web3AssertionError(
|
|
214
229
|
"Impossible to reach: earlier validation raises an error"
|
|
215
230
|
)
|
|
216
231
|
|
|
@@ -218,49 +233,56 @@ class NamedElementOnion(Mapping[TKey, TValue]):
|
|
|
218
233
|
self._queue.clear()
|
|
219
234
|
|
|
220
235
|
def replace(self, old: TKey, new: TKey) -> TValue:
|
|
221
|
-
|
|
222
|
-
|
|
236
|
+
old_name = self._repr_if_not_hashable(old)
|
|
237
|
+
|
|
238
|
+
if old_name not in self._queue:
|
|
239
|
+
raise Web3ValueError(
|
|
223
240
|
"You can't replace unless one already exists, use add instead"
|
|
224
241
|
)
|
|
225
|
-
|
|
242
|
+
|
|
243
|
+
to_be_replaced = self._queue[old_name]
|
|
226
244
|
if to_be_replaced is old:
|
|
227
245
|
# re-insert with new name in old slot
|
|
228
246
|
self._replace_with_new_name(old, new)
|
|
229
247
|
else:
|
|
230
|
-
self._queue[
|
|
248
|
+
self._queue[old_name] = new
|
|
231
249
|
return to_be_replaced
|
|
232
250
|
|
|
251
|
+
def _repr_if_not_hashable(self, value: TKey) -> TKey:
|
|
252
|
+
try:
|
|
253
|
+
value.__hash__()
|
|
254
|
+
except TypeError:
|
|
255
|
+
value = cast(TKey, repr(value))
|
|
256
|
+
return value
|
|
257
|
+
|
|
233
258
|
def remove(self, old: TKey) -> None:
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
259
|
+
old_name = self._repr_if_not_hashable(old)
|
|
260
|
+
if old_name not in self._queue:
|
|
261
|
+
raise Web3ValueError("You can only remove something that has been added")
|
|
262
|
+
del self._queue[old_name]
|
|
237
263
|
|
|
238
264
|
@property
|
|
239
|
-
def
|
|
265
|
+
def middleware(self) -> Sequence[Any]:
|
|
240
266
|
"""
|
|
241
|
-
Returns
|
|
267
|
+
Returns middleware in the appropriate order to be imported into a new Web3
|
|
242
268
|
instance (reversed _queue order) as a list of (middleware, name) tuples.
|
|
243
269
|
"""
|
|
244
270
|
return [(val, key) for key, val in reversed(self._queue.items())]
|
|
245
271
|
|
|
246
272
|
def _replace_with_new_name(self, old: TKey, new: TKey) -> None:
|
|
247
|
-
|
|
273
|
+
old_name = self._repr_if_not_hashable(old)
|
|
274
|
+
new_name = self._repr_if_not_hashable(new)
|
|
275
|
+
|
|
276
|
+
self._queue[new_name] = new
|
|
248
277
|
found_old = False
|
|
249
278
|
for key in list(self._queue.keys()):
|
|
250
279
|
if not found_old:
|
|
251
|
-
if key ==
|
|
280
|
+
if key == old_name:
|
|
252
281
|
found_old = True
|
|
253
282
|
continue
|
|
254
|
-
elif key !=
|
|
283
|
+
elif key != new_name:
|
|
255
284
|
self._queue.move_to_end(key)
|
|
256
|
-
del self._queue[
|
|
257
|
-
|
|
258
|
-
def __iter__(self) -> Iterator[TKey]:
|
|
259
|
-
elements = self._queue.values()
|
|
260
|
-
if not isinstance(elements, Sequence):
|
|
261
|
-
# type ignored b/c elements is set as _OrderedDictValuesView[Any] on 210
|
|
262
|
-
elements = list(elements) # type: ignore
|
|
263
|
-
return iter(reversed(elements))
|
|
285
|
+
del self._queue[old_name]
|
|
264
286
|
|
|
265
287
|
def __add__(self, other: Any) -> "NamedElementOnion[TKey, TValue]":
|
|
266
288
|
if not isinstance(other, NamedElementOnion):
|
|
@@ -271,10 +293,12 @@ class NamedElementOnion(Mapping[TKey, TValue]):
|
|
|
271
293
|
return NamedElementOnion(cast(List[Any], combined.items()))
|
|
272
294
|
|
|
273
295
|
def __contains__(self, element: Any) -> bool:
|
|
274
|
-
|
|
296
|
+
element_name = self._repr_if_not_hashable(element)
|
|
297
|
+
return element_name in self._queue
|
|
275
298
|
|
|
276
299
|
def __getitem__(self, element: TKey) -> TValue:
|
|
277
|
-
|
|
300
|
+
element_name = self._repr_if_not_hashable(element)
|
|
301
|
+
return self._queue[element_name]
|
|
278
302
|
|
|
279
303
|
def __len__(self) -> int:
|
|
280
304
|
return len(self._queue)
|
|
@@ -284,3 +308,27 @@ class NamedElementOnion(Mapping[TKey, TValue]):
|
|
|
284
308
|
if not isinstance(elements, Sequence):
|
|
285
309
|
elements = list(elements)
|
|
286
310
|
return iter(elements)
|
|
311
|
+
|
|
312
|
+
# --- iter and tupleize methods --- #
|
|
313
|
+
|
|
314
|
+
def _reversed_middleware(self) -> Iterator[TValue]:
|
|
315
|
+
elements = self._queue.values()
|
|
316
|
+
if not isinstance(elements, Sequence):
|
|
317
|
+
# type ignored b/c elements is set as _OrderedDictValuesView[Any] on 210
|
|
318
|
+
elements = list(elements) # type: ignore
|
|
319
|
+
return reversed(elements)
|
|
320
|
+
|
|
321
|
+
def as_tuple_of_middleware(self) -> Tuple[TValue, ...]:
|
|
322
|
+
"""
|
|
323
|
+
Helps with type hinting since we return `Iterator[TKey]` type, though it's
|
|
324
|
+
actually a `Iterator[TValue]` type, for the `__iter__()` method. This is in
|
|
325
|
+
order to satisfy the `Mapping` interface.
|
|
326
|
+
"""
|
|
327
|
+
return tuple(self._reversed_middleware())
|
|
328
|
+
|
|
329
|
+
def __iter__(self) -> Iterator[TKey]:
|
|
330
|
+
# ``__iter__()`` for a ``Mapping`` returns ``Iterator[TKey]`` but this
|
|
331
|
+
# implementation returns ``Iterator[TValue]`` on reversed values (not keys).
|
|
332
|
+
# This leads to typing issues, so it's better to use
|
|
333
|
+
# ``as_tuple_of_middleware()`` to achieve the same result.
|
|
334
|
+
return iter(self._reversed_middleware()) # type: ignore
|
web3/eth/__init__.py
CHANGED
web3/eth/async_eth.py
CHANGED
|
@@ -35,6 +35,9 @@ from web3._utils.async_transactions import (
|
|
|
35
35
|
from web3._utils.blocks import (
|
|
36
36
|
select_method_for_block_identifier,
|
|
37
37
|
)
|
|
38
|
+
from web3._utils.compat import (
|
|
39
|
+
Unpack,
|
|
40
|
+
)
|
|
38
41
|
from web3._utils.fee_utils import (
|
|
39
42
|
async_fee_history_priority_fee,
|
|
40
43
|
)
|
|
@@ -57,12 +60,14 @@ from web3.eth.base_eth import (
|
|
|
57
60
|
BaseEth,
|
|
58
61
|
)
|
|
59
62
|
from web3.exceptions import (
|
|
60
|
-
|
|
63
|
+
MethodNotSupported,
|
|
61
64
|
OffchainLookup,
|
|
62
65
|
TimeExhausted,
|
|
63
66
|
TooManyRequests,
|
|
64
67
|
TransactionIndexingInProgress,
|
|
65
68
|
TransactionNotFound,
|
|
69
|
+
Web3RPCError,
|
|
70
|
+
Web3ValueError,
|
|
66
71
|
)
|
|
67
72
|
from web3.method import (
|
|
68
73
|
Method,
|
|
@@ -76,7 +81,7 @@ from web3.types import (
|
|
|
76
81
|
BlockData,
|
|
77
82
|
BlockIdentifier,
|
|
78
83
|
BlockParams,
|
|
79
|
-
|
|
84
|
+
BlockReceipts,
|
|
80
85
|
CreateAccessListResponse,
|
|
81
86
|
FeeHistory,
|
|
82
87
|
FilterParams,
|
|
@@ -84,6 +89,7 @@ from web3.types import (
|
|
|
84
89
|
LogsSubscriptionArg,
|
|
85
90
|
Nonce,
|
|
86
91
|
SignedTx,
|
|
92
|
+
StateOverride,
|
|
87
93
|
SubscriptionType,
|
|
88
94
|
SyncStatus,
|
|
89
95
|
TxData,
|
|
@@ -121,17 +127,6 @@ class AsyncEth(BaseEth):
|
|
|
121
127
|
async def accounts(self) -> Tuple[ChecksumAddress]:
|
|
122
128
|
return await self._accounts()
|
|
123
129
|
|
|
124
|
-
# eth_hashrate
|
|
125
|
-
|
|
126
|
-
_hashrate: Method[Callable[[], Awaitable[int]]] = Method(
|
|
127
|
-
RPC.eth_hashrate,
|
|
128
|
-
is_property=True,
|
|
129
|
-
)
|
|
130
|
-
|
|
131
|
-
@property
|
|
132
|
-
async def hashrate(self) -> int:
|
|
133
|
-
return await self._hashrate()
|
|
134
|
-
|
|
135
130
|
# eth_blockNumber
|
|
136
131
|
|
|
137
132
|
get_block_number: Method[Callable[[], Awaitable[BlockNumber]]] = Method(
|
|
@@ -154,17 +149,6 @@ class AsyncEth(BaseEth):
|
|
|
154
149
|
async def chain_id(self) -> int:
|
|
155
150
|
return await self._chain_id()
|
|
156
151
|
|
|
157
|
-
# eth_coinbase
|
|
158
|
-
|
|
159
|
-
_coinbase: Method[Callable[[], Awaitable[ChecksumAddress]]] = Method(
|
|
160
|
-
RPC.eth_coinbase,
|
|
161
|
-
is_property=True,
|
|
162
|
-
)
|
|
163
|
-
|
|
164
|
-
@property
|
|
165
|
-
async def coinbase(self) -> ChecksumAddress:
|
|
166
|
-
return await self._coinbase()
|
|
167
|
-
|
|
168
152
|
# eth_gasPrice
|
|
169
153
|
|
|
170
154
|
_gas_price: Method[Callable[[], Awaitable[Wei]]] = Method(
|
|
@@ -192,24 +176,14 @@ class AsyncEth(BaseEth):
|
|
|
192
176
|
"""
|
|
193
177
|
try:
|
|
194
178
|
return await self._max_priority_fee()
|
|
195
|
-
except
|
|
179
|
+
except Web3RPCError:
|
|
196
180
|
warnings.warn(
|
|
197
181
|
"There was an issue with the method eth_maxPriorityFeePerGas. "
|
|
198
|
-
"Calculating using eth_feeHistory."
|
|
182
|
+
"Calculating using eth_feeHistory.",
|
|
183
|
+
stacklevel=2,
|
|
199
184
|
)
|
|
200
185
|
return await async_fee_history_priority_fee(self)
|
|
201
186
|
|
|
202
|
-
# eth_mining
|
|
203
|
-
|
|
204
|
-
_mining: Method[Callable[[], Awaitable[bool]]] = Method(
|
|
205
|
-
RPC.eth_mining,
|
|
206
|
-
is_property=True,
|
|
207
|
-
)
|
|
208
|
-
|
|
209
|
-
@property
|
|
210
|
-
async def mining(self) -> bool:
|
|
211
|
-
return await self._mining()
|
|
212
|
-
|
|
213
187
|
# eth_syncing
|
|
214
188
|
|
|
215
189
|
_syncing: Method[Callable[[], Awaitable[Union[SyncStatus, bool]]]] = Method(
|
|
@@ -246,7 +220,7 @@ class AsyncEth(BaseEth):
|
|
|
246
220
|
[
|
|
247
221
|
TxParams,
|
|
248
222
|
Optional[BlockIdentifier],
|
|
249
|
-
Optional[
|
|
223
|
+
Optional[StateOverride],
|
|
250
224
|
],
|
|
251
225
|
Awaitable[HexBytes],
|
|
252
226
|
]
|
|
@@ -256,7 +230,7 @@ class AsyncEth(BaseEth):
|
|
|
256
230
|
self,
|
|
257
231
|
transaction: TxParams,
|
|
258
232
|
block_identifier: Optional[BlockIdentifier] = None,
|
|
259
|
-
state_override: Optional[
|
|
233
|
+
state_override: Optional[StateOverride] = None,
|
|
260
234
|
ccip_read_enabled: Optional[bool] = None,
|
|
261
235
|
) -> HexBytes:
|
|
262
236
|
ccip_read_enabled_on_provider = self.w3.provider.global_ccip_read_enabled
|
|
@@ -277,12 +251,12 @@ class AsyncEth(BaseEth):
|
|
|
277
251
|
self,
|
|
278
252
|
transaction: TxParams,
|
|
279
253
|
block_identifier: Optional[BlockIdentifier] = None,
|
|
280
|
-
state_override: Optional[
|
|
254
|
+
state_override: Optional[StateOverride] = None,
|
|
281
255
|
) -> HexBytes:
|
|
282
256
|
max_redirects = self.w3.provider.ccip_read_max_redirects
|
|
283
257
|
|
|
284
258
|
if not max_redirects or max_redirects < 4:
|
|
285
|
-
raise
|
|
259
|
+
raise Web3ValueError(
|
|
286
260
|
"ccip_read_max_redirects property on provider must be at least 4."
|
|
287
261
|
)
|
|
288
262
|
|
|
@@ -318,7 +292,7 @@ class AsyncEth(BaseEth):
|
|
|
318
292
|
|
|
319
293
|
_estimate_gas: Method[
|
|
320
294
|
Callable[
|
|
321
|
-
[TxParams, Optional[BlockIdentifier], Optional[
|
|
295
|
+
[TxParams, Optional[BlockIdentifier], Optional[StateOverride]],
|
|
322
296
|
Awaitable[int],
|
|
323
297
|
]
|
|
324
298
|
] = Method(RPC.eth_estimateGas, mungers=[BaseEth.estimate_gas_munger])
|
|
@@ -327,7 +301,7 @@ class AsyncEth(BaseEth):
|
|
|
327
301
|
self,
|
|
328
302
|
transaction: TxParams,
|
|
329
303
|
block_identifier: Optional[BlockIdentifier] = None,
|
|
330
|
-
state_override: Optional[
|
|
304
|
+
state_override: Optional[StateOverride] = None,
|
|
331
305
|
) -> int:
|
|
332
306
|
return await self._estimate_gas(transaction, block_identifier, state_override)
|
|
333
307
|
|
|
@@ -441,6 +415,20 @@ class AsyncEth(BaseEth):
|
|
|
441
415
|
) -> BlockData:
|
|
442
416
|
return await self._get_block(block_identifier, full_transactions)
|
|
443
417
|
|
|
418
|
+
# eth_getBlockReceipts
|
|
419
|
+
|
|
420
|
+
_get_block_receipts: Method[
|
|
421
|
+
Callable[[BlockIdentifier], Awaitable[BlockReceipts]]
|
|
422
|
+
] = Method(
|
|
423
|
+
RPC.eth_getBlockReceipts,
|
|
424
|
+
mungers=[default_root_munger],
|
|
425
|
+
)
|
|
426
|
+
|
|
427
|
+
async def get_block_receipts(
|
|
428
|
+
self, block_identifier: BlockIdentifier
|
|
429
|
+
) -> BlockReceipts:
|
|
430
|
+
return await self._get_block_receipts(block_identifier)
|
|
431
|
+
|
|
444
432
|
# eth_getBalance
|
|
445
433
|
|
|
446
434
|
_get_balance: Method[
|
|
@@ -517,7 +505,10 @@ class AsyncEth(BaseEth):
|
|
|
517
505
|
return await self._transaction_receipt(transaction_hash)
|
|
518
506
|
|
|
519
507
|
async def wait_for_transaction_receipt(
|
|
520
|
-
self,
|
|
508
|
+
self,
|
|
509
|
+
transaction_hash: _Hash32,
|
|
510
|
+
timeout: Optional[float] = 120,
|
|
511
|
+
poll_latency: float = 0.1,
|
|
521
512
|
) -> TxReceipt:
|
|
522
513
|
async def _wait_for_tx_receipt_with_timeout(
|
|
523
514
|
_tx_hash: _Hash32, _poll_latency: float
|
|
@@ -573,10 +564,8 @@ class AsyncEth(BaseEth):
|
|
|
573
564
|
self.w3, current_transaction, new_transaction
|
|
574
565
|
)
|
|
575
566
|
|
|
576
|
-
# todo: Update Any to stricter kwarg checking with TxParams
|
|
577
|
-
# https://github.com/python/mypy/issues/4441
|
|
578
567
|
async def modify_transaction(
|
|
579
|
-
self, transaction_hash: _Hash32, **transaction_params:
|
|
568
|
+
self, transaction_hash: _Hash32, **transaction_params: Unpack[TxParams]
|
|
580
569
|
) -> HexBytes:
|
|
581
570
|
assert_valid_transaction_params(cast(TxParams, transaction_params))
|
|
582
571
|
|
|
@@ -716,7 +705,7 @@ class AsyncEth(BaseEth):
|
|
|
716
705
|
] = None,
|
|
717
706
|
) -> HexStr:
|
|
718
707
|
if not isinstance(self.w3.provider, PersistentConnectionProvider):
|
|
719
|
-
raise
|
|
708
|
+
raise MethodNotSupported(
|
|
720
709
|
"eth_subscribe is only supported with providers that support "
|
|
721
710
|
"persistent connections."
|
|
722
711
|
)
|
|
@@ -733,7 +722,7 @@ class AsyncEth(BaseEth):
|
|
|
733
722
|
|
|
734
723
|
async def unsubscribe(self, subscription_id: HexStr) -> bool:
|
|
735
724
|
if not isinstance(self.w3.provider, PersistentConnectionProvider):
|
|
736
|
-
raise
|
|
725
|
+
raise MethodNotSupported(
|
|
737
726
|
"eth_unsubscribe is only supported with providers that support "
|
|
738
727
|
"persistent connections."
|
|
739
728
|
)
|
|
@@ -743,8 +732,7 @@ class AsyncEth(BaseEth):
|
|
|
743
732
|
# -- contract methods -- #
|
|
744
733
|
|
|
745
734
|
@overload
|
|
746
|
-
|
|
747
|
-
def contract(self, address: None = None, **kwargs: Any) -> Type[AsyncContract]: # type: ignore[misc] # noqa: E501
|
|
735
|
+
def contract(self, address: None = None, **kwargs: Any) -> Type[AsyncContract]:
|
|
748
736
|
...
|
|
749
737
|
|
|
750
738
|
@overload
|
web3/eth/base_eth.py
CHANGED
|
@@ -30,15 +30,19 @@ from web3._utils.empty import (
|
|
|
30
30
|
from web3._utils.encoding import (
|
|
31
31
|
to_hex,
|
|
32
32
|
)
|
|
33
|
+
from web3.exceptions import (
|
|
34
|
+
Web3TypeError,
|
|
35
|
+
Web3ValueError,
|
|
36
|
+
)
|
|
33
37
|
from web3.module import (
|
|
34
38
|
Module,
|
|
35
39
|
)
|
|
36
40
|
from web3.types import (
|
|
37
41
|
ENS,
|
|
38
42
|
BlockIdentifier,
|
|
39
|
-
CallOverride,
|
|
40
43
|
FilterParams,
|
|
41
44
|
GasPriceStrategy,
|
|
45
|
+
StateOverride,
|
|
42
46
|
TxParams,
|
|
43
47
|
Wei,
|
|
44
48
|
)
|
|
@@ -97,9 +101,10 @@ class BaseEth(Module):
|
|
|
97
101
|
self,
|
|
98
102
|
transaction: TxParams,
|
|
99
103
|
block_identifier: Optional[BlockIdentifier] = None,
|
|
100
|
-
state_override: Optional[
|
|
104
|
+
state_override: Optional[StateOverride] = None,
|
|
101
105
|
) -> Union[
|
|
102
|
-
Tuple[TxParams, BlockIdentifier],
|
|
106
|
+
Tuple[TxParams, BlockIdentifier],
|
|
107
|
+
Tuple[TxParams, BlockIdentifier, StateOverride],
|
|
103
108
|
]:
|
|
104
109
|
# TODO: move to middleware
|
|
105
110
|
if "from" not in transaction and is_checksum_address(self.default_account):
|
|
@@ -118,9 +123,10 @@ class BaseEth(Module):
|
|
|
118
123
|
self,
|
|
119
124
|
transaction: TxParams,
|
|
120
125
|
block_identifier: Optional[BlockIdentifier] = None,
|
|
121
|
-
state_override: Optional[
|
|
126
|
+
state_override: Optional[StateOverride] = None,
|
|
122
127
|
) -> Union[
|
|
123
|
-
Tuple[TxParams, BlockIdentifier],
|
|
128
|
+
Tuple[TxParams, BlockIdentifier],
|
|
129
|
+
Tuple[TxParams, BlockIdentifier, StateOverride],
|
|
124
130
|
]:
|
|
125
131
|
return self._eth_call_and_estimate_gas_munger(
|
|
126
132
|
transaction, block_identifier, state_override
|
|
@@ -154,9 +160,10 @@ class BaseEth(Module):
|
|
|
154
160
|
self,
|
|
155
161
|
transaction: TxParams,
|
|
156
162
|
block_identifier: Optional[BlockIdentifier] = None,
|
|
157
|
-
state_override: Optional[
|
|
163
|
+
state_override: Optional[StateOverride] = None,
|
|
158
164
|
) -> Union[
|
|
159
|
-
Tuple[TxParams, BlockIdentifier],
|
|
165
|
+
Tuple[TxParams, BlockIdentifier],
|
|
166
|
+
Tuple[TxParams, BlockIdentifier, StateOverride],
|
|
160
167
|
]:
|
|
161
168
|
return self._eth_call_and_estimate_gas_munger(
|
|
162
169
|
transaction, block_identifier, state_override
|
|
@@ -191,7 +198,7 @@ class BaseEth(Module):
|
|
|
191
198
|
filter_id: Optional[HexStr] = None,
|
|
192
199
|
) -> Union[List[FilterParams], List[HexStr], List[str]]:
|
|
193
200
|
if filter_id and filter_params:
|
|
194
|
-
raise
|
|
201
|
+
raise Web3TypeError(
|
|
195
202
|
"Ambiguous invocation: provide either a `filter_params` or a "
|
|
196
203
|
"`filter_id` argument. Both were supplied."
|
|
197
204
|
)
|
|
@@ -201,14 +208,14 @@ class BaseEth(Module):
|
|
|
201
208
|
if filter_params in {"latest", "pending"}:
|
|
202
209
|
return [filter_params]
|
|
203
210
|
else:
|
|
204
|
-
raise
|
|
211
|
+
raise Web3ValueError(
|
|
205
212
|
"The filter API only accepts the values of `pending` or "
|
|
206
213
|
"`latest` for string based filters"
|
|
207
214
|
)
|
|
208
215
|
elif filter_id and not filter_params:
|
|
209
216
|
return [filter_id]
|
|
210
217
|
else:
|
|
211
|
-
raise
|
|
218
|
+
raise Web3TypeError(
|
|
212
219
|
"Must provide either filter_params as a string or "
|
|
213
220
|
"a valid filter object, or a filter_id as a string "
|
|
214
221
|
"or hex."
|