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.
Files changed (270) hide show
  1. ens/__init__.py +13 -2
  2. ens/_normalization.py +2 -17
  3. ens/async_ens.py +33 -21
  4. ens/base_ens.py +3 -1
  5. ens/ens.py +16 -11
  6. ens/exceptions.py +16 -29
  7. ens/specs/nf.json +1 -1
  8. ens/specs/normalization_spec.json +1 -1
  9. ens/utils.py +52 -63
  10. web3/__init__.py +20 -24
  11. web3/_utils/abi.py +115 -271
  12. web3/_utils/async_transactions.py +7 -4
  13. web3/_utils/batching.py +217 -0
  14. web3/_utils/blocks.py +6 -2
  15. web3/_utils/caching.py +128 -5
  16. web3/_utils/compat/__init__.py +2 -3
  17. web3/_utils/contract_sources/compile_contracts.py +1 -1
  18. web3/_utils/contract_sources/contract_data/arrays_contract.py +3 -3
  19. web3/_utils/contract_sources/contract_data/bytes_contracts.py +5 -5
  20. web3/_utils/contract_sources/contract_data/constructor_contracts.py +7 -7
  21. web3/_utils/contract_sources/contract_data/contract_caller_tester.py +3 -3
  22. web3/_utils/contract_sources/contract_data/emitter_contract.py +3 -3
  23. web3/_utils/contract_sources/contract_data/event_contracts.py +5 -5
  24. web3/_utils/contract_sources/contract_data/extended_resolver.py +3 -3
  25. web3/_utils/contract_sources/contract_data/fallback_function_contract.py +3 -3
  26. web3/_utils/contract_sources/contract_data/function_name_tester_contract.py +3 -3
  27. web3/_utils/contract_sources/contract_data/math_contract.py +3 -3
  28. web3/_utils/contract_sources/contract_data/offchain_lookup.py +3 -3
  29. web3/_utils/contract_sources/contract_data/offchain_resolver.py +3 -3
  30. web3/_utils/contract_sources/contract_data/panic_errors_contract.py +3 -3
  31. web3/_utils/contract_sources/contract_data/payable_tester.py +3 -3
  32. web3/_utils/contract_sources/contract_data/receive_function_contracts.py +5 -5
  33. web3/_utils/contract_sources/contract_data/reflector_contracts.py +3 -3
  34. web3/_utils/contract_sources/contract_data/revert_contract.py +3 -3
  35. web3/_utils/contract_sources/contract_data/simple_resolver.py +3 -3
  36. web3/_utils/contract_sources/contract_data/storage_contract.py +3 -3
  37. web3/_utils/contract_sources/contract_data/string_contract.py +3 -3
  38. web3/_utils/contract_sources/contract_data/tuple_contracts.py +5 -5
  39. web3/_utils/contracts.py +130 -236
  40. web3/_utils/datatypes.py +5 -1
  41. web3/_utils/decorators.py +13 -23
  42. web3/_utils/empty.py +1 -1
  43. web3/_utils/encoding.py +16 -12
  44. web3/_utils/ens.py +2 -1
  45. web3/_utils/error_formatters_utils.py +5 -3
  46. web3/_utils/events.py +66 -69
  47. web3/_utils/fee_utils.py +1 -3
  48. web3/_utils/filters.py +24 -22
  49. web3/_utils/formatters.py +2 -2
  50. web3/_utils/http.py +5 -3
  51. web3/_utils/http_session_manager.py +303 -0
  52. web3/_utils/math.py +14 -15
  53. web3/_utils/method_formatters.py +34 -36
  54. web3/_utils/module.py +2 -1
  55. web3/_utils/module_testing/__init__.py +0 -3
  56. web3/_utils/module_testing/eth_module.py +695 -643
  57. web3/_utils/module_testing/module_testing_utils.py +61 -34
  58. web3/_utils/module_testing/persistent_connection_provider.py +56 -25
  59. web3/_utils/module_testing/utils.py +258 -0
  60. web3/_utils/module_testing/web3_module.py +438 -17
  61. web3/_utils/normalizers.py +13 -11
  62. web3/_utils/rpc_abi.py +5 -32
  63. web3/_utils/threads.py +8 -7
  64. web3/_utils/transactions.py +14 -12
  65. web3/_utils/type_conversion.py +5 -1
  66. web3/_utils/validation.py +17 -17
  67. web3/auto/gethdev.py +7 -2
  68. web3/beacon/__init__.py +6 -1
  69. web3/beacon/async_beacon.py +9 -5
  70. web3/beacon/{main.py → beacon.py} +7 -5
  71. web3/contract/__init__.py +7 -0
  72. web3/contract/async_contract.py +47 -46
  73. web3/contract/base_contract.py +183 -158
  74. web3/contract/contract.py +49 -43
  75. web3/contract/utils.py +203 -59
  76. web3/datastructures.py +79 -31
  77. web3/eth/__init__.py +7 -0
  78. web3/eth/async_eth.py +39 -51
  79. web3/eth/base_eth.py +17 -10
  80. web3/eth/eth.py +30 -68
  81. web3/exceptions.py +108 -82
  82. web3/gas_strategies/time_based.py +8 -6
  83. web3/geth.py +1 -254
  84. web3/main.py +75 -122
  85. web3/manager.py +316 -146
  86. web3/method.py +38 -31
  87. web3/middleware/__init__.py +67 -89
  88. web3/middleware/attrdict.py +36 -49
  89. web3/middleware/base.py +174 -0
  90. web3/middleware/buffered_gas_estimate.py +20 -21
  91. web3/middleware/filter.py +157 -117
  92. web3/middleware/formatting.py +124 -108
  93. web3/middleware/gas_price_strategy.py +20 -32
  94. web3/middleware/names.py +29 -26
  95. web3/middleware/proof_of_authority.py +68 -0
  96. web3/middleware/pythonic.py +2 -2
  97. web3/middleware/signing.py +74 -89
  98. web3/middleware/stalecheck.py +52 -79
  99. web3/middleware/validation.py +5 -13
  100. web3/module.py +54 -10
  101. web3/providers/__init__.py +10 -6
  102. web3/providers/async_base.py +117 -39
  103. web3/providers/auto.py +3 -3
  104. web3/providers/base.py +89 -33
  105. web3/providers/eth_tester/__init__.py +5 -0
  106. web3/providers/eth_tester/defaults.py +1 -64
  107. web3/providers/eth_tester/main.py +99 -31
  108. web3/providers/eth_tester/middleware.py +45 -73
  109. web3/providers/ipc.py +42 -46
  110. web3/providers/{websocket/websocket.py → legacy_websocket.py} +32 -7
  111. web3/providers/persistent/__init__.py +22 -0
  112. web3/providers/persistent/async_ipc.py +153 -0
  113. web3/providers/{persistent.py → persistent/persistent.py} +106 -25
  114. web3/providers/persistent/persistent_connection.py +84 -0
  115. web3/providers/{websocket → persistent}/request_processor.py +94 -32
  116. web3/providers/persistent/utils.py +43 -0
  117. web3/providers/{websocket/websocket_v2.py → persistent/websocket.py} +29 -28
  118. web3/providers/rpc/__init__.py +11 -0
  119. web3/providers/rpc/async_rpc.py +171 -0
  120. web3/providers/rpc/rpc.py +179 -0
  121. web3/providers/rpc/utils.py +92 -0
  122. web3/testing.py +4 -4
  123. web3/tools/benchmark/main.py +22 -22
  124. web3/tools/benchmark/node.py +2 -8
  125. web3/tools/benchmark/reporting.py +2 -2
  126. web3/tools/benchmark/utils.py +1 -1
  127. web3/tracing.py +9 -5
  128. web3/types.py +30 -107
  129. web3/utils/__init__.py +58 -5
  130. web3/utils/abi.py +575 -10
  131. web3/utils/async_exception_handling.py +19 -7
  132. web3/utils/caching.py +32 -13
  133. web3/utils/exception_handling.py +7 -5
  134. {web3-6.20.3.dist-info → web3-7.0.0.dist-info}/LICENSE +1 -1
  135. web3-7.0.0.dist-info/METADATA +112 -0
  136. web3-7.0.0.dist-info/RECORD +167 -0
  137. {web3-6.20.3.dist-info → web3-7.0.0.dist-info}/top_level.txt +0 -1
  138. ethpm/__init__.py +0 -20
  139. ethpm/_utils/__init__.py +0 -0
  140. ethpm/_utils/backend.py +0 -93
  141. ethpm/_utils/cache.py +0 -44
  142. ethpm/_utils/chains.py +0 -119
  143. ethpm/_utils/contract.py +0 -35
  144. ethpm/_utils/deployments.py +0 -145
  145. ethpm/_utils/ipfs.py +0 -116
  146. ethpm/_utils/protobuf/__init__.py +0 -0
  147. ethpm/_utils/protobuf/ipfs_file_pb2.py +0 -33
  148. ethpm/_utils/registry.py +0 -29
  149. ethpm/assets/__init__.py +0 -0
  150. ethpm/assets/ens/v3.json +0 -1
  151. ethpm/assets/escrow/with_bytecode_v3.json +0 -1
  152. ethpm/assets/ipfs_file.proto +0 -32
  153. ethpm/assets/owned/output_v3.json +0 -1
  154. ethpm/assets/owned/with_contract_type_v3.json +0 -1
  155. ethpm/assets/registry/contracts/Authority.sol +0 -156
  156. ethpm/assets/registry/contracts/IndexedOrderedSetLib.sol +0 -106
  157. ethpm/assets/registry/contracts/PackageDB.sol +0 -225
  158. ethpm/assets/registry/contracts/PackageRegistry.sol +0 -361
  159. ethpm/assets/registry/contracts/PackageRegistryInterface.sol +0 -97
  160. ethpm/assets/registry/contracts/ReleaseDB.sol +0 -309
  161. ethpm/assets/registry/contracts/ReleaseValidator.sol +0 -152
  162. ethpm/assets/registry/solc_input.json +0 -1
  163. ethpm/assets/registry/solc_output.json +0 -1
  164. ethpm/assets/registry/v3.json +0 -1
  165. ethpm/assets/safe-math-lib/v3-strict-no-deployments.json +0 -1
  166. ethpm/assets/simple-registry/contracts/Ownable.sol +0 -63
  167. ethpm/assets/simple-registry/contracts/PackageRegistry.sol +0 -373
  168. ethpm/assets/simple-registry/contracts/PackageRegistryInterface.sol +0 -96
  169. ethpm/assets/simple-registry/solc_input.json +0 -33
  170. ethpm/assets/simple-registry/solc_output.json +0 -1
  171. ethpm/assets/simple-registry/v3.json +0 -1
  172. ethpm/assets/standard-token/output_v3.json +0 -1
  173. ethpm/assets/standard-token/with_bytecode_v3.json +0 -1
  174. ethpm/assets/vyper_registry/0.1.0.json +0 -1
  175. ethpm/assets/vyper_registry/registry.vy +0 -216
  176. ethpm/assets/vyper_registry/registry_with_delete.vy +0 -244
  177. ethpm/backends/__init__.py +0 -0
  178. ethpm/backends/base.py +0 -43
  179. ethpm/backends/http.py +0 -108
  180. ethpm/backends/ipfs.py +0 -219
  181. ethpm/backends/registry.py +0 -154
  182. ethpm/constants.py +0 -17
  183. ethpm/contract.py +0 -187
  184. ethpm/dependencies.py +0 -58
  185. ethpm/deployments.py +0 -80
  186. ethpm/ethpm-spec/examples/escrow/1.0.0-pretty.json +0 -146
  187. ethpm/ethpm-spec/examples/escrow/1.0.0.json +0 -1
  188. ethpm/ethpm-spec/examples/escrow/contracts/Escrow.sol +0 -32
  189. ethpm/ethpm-spec/examples/escrow/contracts/SafeSendLib.sol +0 -20
  190. ethpm/ethpm-spec/examples/escrow/v3-pretty.json +0 -171
  191. ethpm/ethpm-spec/examples/escrow/v3.json +0 -1
  192. ethpm/ethpm-spec/examples/owned/1.0.0-pretty.json +0 -21
  193. ethpm/ethpm-spec/examples/owned/1.0.0.json +0 -1
  194. ethpm/ethpm-spec/examples/owned/contracts/Owned.sol +0 -12
  195. ethpm/ethpm-spec/examples/owned/v3-pretty.json +0 -27
  196. ethpm/ethpm-spec/examples/owned/v3.json +0 -1
  197. ethpm/ethpm-spec/examples/piper-coin/1.0.0-pretty.json +0 -31
  198. ethpm/ethpm-spec/examples/piper-coin/1.0.0.json +0 -1
  199. ethpm/ethpm-spec/examples/piper-coin/v3-pretty.json +0 -21
  200. ethpm/ethpm-spec/examples/piper-coin/v3.json +0 -1
  201. ethpm/ethpm-spec/examples/safe-math-lib/1.0.0-pretty.json +0 -85
  202. ethpm/ethpm-spec/examples/safe-math-lib/1.0.0.json +0 -1
  203. ethpm/ethpm-spec/examples/safe-math-lib/contracts/SafeMathLib.sol +0 -24
  204. ethpm/ethpm-spec/examples/safe-math-lib/v3-pretty.json +0 -117
  205. ethpm/ethpm-spec/examples/safe-math-lib/v3.json +0 -1
  206. ethpm/ethpm-spec/examples/standard-token/1.0.0-pretty.json +0 -55
  207. ethpm/ethpm-spec/examples/standard-token/1.0.0.json +0 -1
  208. ethpm/ethpm-spec/examples/standard-token/contracts/AbstractToken.sol +0 -20
  209. ethpm/ethpm-spec/examples/standard-token/contracts/StandardToken.sol +0 -84
  210. ethpm/ethpm-spec/examples/standard-token/v3-pretty.json +0 -460
  211. ethpm/ethpm-spec/examples/standard-token/v3.json +0 -1
  212. ethpm/ethpm-spec/examples/transferable/1.0.0-pretty.json +0 -21
  213. ethpm/ethpm-spec/examples/transferable/1.0.0.json +0 -1
  214. ethpm/ethpm-spec/examples/transferable/contracts/Transferable.sol +0 -14
  215. ethpm/ethpm-spec/examples/transferable/v3-pretty.json +0 -27
  216. ethpm/ethpm-spec/examples/transferable/v3.json +0 -1
  217. ethpm/ethpm-spec/examples/wallet/1.0.0-pretty.json +0 -120
  218. ethpm/ethpm-spec/examples/wallet/1.0.0.json +0 -1
  219. ethpm/ethpm-spec/examples/wallet/contracts/Wallet.sol +0 -41
  220. ethpm/ethpm-spec/examples/wallet/v3-pretty.json +0 -181
  221. ethpm/ethpm-spec/examples/wallet/v3.json +0 -1
  222. ethpm/ethpm-spec/examples/wallet-with-send/1.0.0-pretty.json +0 -135
  223. ethpm/ethpm-spec/examples/wallet-with-send/1.0.0.json +0 -1
  224. ethpm/ethpm-spec/examples/wallet-with-send/contracts/WalletWithSend.sol +0 -18
  225. ethpm/ethpm-spec/examples/wallet-with-send/v3-pretty.json +0 -207
  226. ethpm/ethpm-spec/examples/wallet-with-send/v3.json +0 -1
  227. ethpm/ethpm-spec/spec/package.spec.json +0 -379
  228. ethpm/ethpm-spec/spec/v3.spec.json +0 -483
  229. ethpm/exceptions.py +0 -68
  230. ethpm/package.py +0 -438
  231. ethpm/tools/__init__.py +0 -4
  232. ethpm/tools/builder.py +0 -930
  233. ethpm/tools/checker.py +0 -312
  234. ethpm/tools/get_manifest.py +0 -19
  235. ethpm/uri.py +0 -141
  236. ethpm/validation/__init__.py +0 -0
  237. ethpm/validation/manifest.py +0 -146
  238. ethpm/validation/misc.py +0 -39
  239. ethpm/validation/package.py +0 -80
  240. ethpm/validation/uri.py +0 -163
  241. web3/_utils/contract_sources/contract_data/address_reflector.py +0 -29
  242. web3/_utils/miner.py +0 -88
  243. web3/_utils/module_testing/go_ethereum_personal_module.py +0 -323
  244. web3/_utils/request.py +0 -265
  245. web3/middleware/abi.py +0 -11
  246. web3/middleware/async_cache.py +0 -99
  247. web3/middleware/cache.py +0 -374
  248. web3/middleware/exception_handling.py +0 -49
  249. web3/middleware/exception_retry_request.py +0 -188
  250. web3/middleware/fixture.py +0 -190
  251. web3/middleware/geth_poa.py +0 -81
  252. web3/middleware/normalize_request_parameters.py +0 -11
  253. web3/middleware/simulate_unmined_transaction.py +0 -43
  254. web3/pm.py +0 -602
  255. web3/providers/async_rpc.py +0 -99
  256. web3/providers/rpc.py +0 -98
  257. web3/providers/websocket/__init__.py +0 -11
  258. web3/providers/websocket/websocket_connection.py +0 -42
  259. web3/tools/__init__.py +0 -4
  260. web3/tools/pytest_ethereum/__init__.py +0 -0
  261. web3/tools/pytest_ethereum/_utils.py +0 -145
  262. web3/tools/pytest_ethereum/deployer.py +0 -48
  263. web3/tools/pytest_ethereum/exceptions.py +0 -22
  264. web3/tools/pytest_ethereum/linker.py +0 -128
  265. web3/tools/pytest_ethereum/plugins.py +0 -33
  266. web3-6.20.3.dist-info/METADATA +0 -104
  267. web3-6.20.3.dist-info/RECORD +0 -283
  268. web3-6.20.3.dist-info/entry_points.txt +0 -2
  269. /web3/_utils/{function_identifiers.py → abi_element_identifiers.py} +0 -0
  270. {web3-6.20.3.dist-info → web3-7.0.0.dist-info}/WHEEL +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 recursive_map(cls._apply_if_mapping, value)
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
- This provides superficial immutability, someone could hack around it
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 TypeError(
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 TypeError("This data is immutable -- create a copy instead of modifying")
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 TypeError(f"Found unhashable type '{type(v).__name__}': {v}")
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 ValueError("You can't add the same un-named instance twice")
189
+ raise Web3ValueError("You can't add the same un-named instance twice")
178
190
  else:
179
- raise ValueError(
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 TypeError("The layer for insertion must be an int.")
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 AssertionError(
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
- if old not in self._queue:
222
- raise ValueError(
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
- to_be_replaced = self._queue[old]
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[old] = new
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
- if old not in self._queue:
235
- raise ValueError("You can only remove something that has been added")
236
- del self._queue[old]
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 middlewares(self) -> Sequence[Any]:
265
+ def middleware(self) -> Sequence[Any]:
240
266
  """
241
- Returns middlewares in the appropriate order to be imported into a new Web3
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
- self._queue[new] = new
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 == old:
280
+ if key == old_name:
252
281
  found_old = True
253
282
  continue
254
- elif key != new:
283
+ elif key != new_name:
255
284
  self._queue.move_to_end(key)
256
- del self._queue[old]
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
- return element in self._queue
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
- return self._queue[element]
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
@@ -8,3 +8,10 @@ from .eth import (
8
8
  Contract,
9
9
  Eth,
10
10
  )
11
+
12
+ __all__ = [
13
+ "AsyncEth",
14
+ "BaseEth",
15
+ "Contract",
16
+ "Eth",
17
+ ]
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
- MethodUnavailable,
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
- CallOverride,
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 (ValueError, MethodUnavailable):
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[CallOverride],
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[CallOverride] = None,
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[CallOverride] = None,
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 ValueError(
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[CallOverride]],
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[CallOverride] = None,
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, transaction_hash: _Hash32, timeout: float = 120, poll_latency: float = 0.1
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: Any
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 MethodUnavailable(
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 MethodUnavailable(
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
- # type ignored because error: Overloaded function signatures 1 and 2 overlap with incompatible return types # noqa: E501
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[CallOverride] = None,
104
+ state_override: Optional[StateOverride] = None,
101
105
  ) -> Union[
102
- Tuple[TxParams, BlockIdentifier], Tuple[TxParams, BlockIdentifier, CallOverride]
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[CallOverride] = None,
126
+ state_override: Optional[StateOverride] = None,
122
127
  ) -> Union[
123
- Tuple[TxParams, BlockIdentifier], Tuple[TxParams, BlockIdentifier, CallOverride]
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[CallOverride] = None,
163
+ state_override: Optional[StateOverride] = None,
158
164
  ) -> Union[
159
- Tuple[TxParams, BlockIdentifier], Tuple[TxParams, BlockIdentifier, CallOverride]
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 TypeError(
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 ValueError(
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 TypeError(
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."