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/_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 ValueError(f"Recursively called {to_wrap} with {args!r}")
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 deprecate_method(
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 on its replacement method OR a clarifying
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
- @deprecate_method(deprecation_msg=(
50
- "This method is no longer supported and will be removed in the next release."
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
- msg = (
64
- f"{to_wrap.__name__} is deprecated in favor of {replacement_method}"
65
- if replacement_method is not None
66
- else deprecation_msg
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
@@ -1,4 +1,4 @@
1
- from web3._utils.compat import (
1
+ from typing import (
2
2
  Literal,
3
3
  )
4
4
 
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 ValueError(f"Unsupported ABI type: {abi_type}")
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 ValueError(
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 TypeError(
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 TypeError(
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 TypeError(f"Could not encode to JSON: {exc}")
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 ValueError(f"expected value of size 4 bytes. Got: {len(byte_str)} bytes")
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("Could not decode revert reason as UTF-8", RuntimeWarning)
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 ValueError(error)
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
- MismatchedABI,
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
- get_abi_input_names,
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[Sequence[Any], Dict[str, Any]]] = None,
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
- if isinstance(arguments, (list, tuple)):
120
+ elif isinstance(arguments, (list, tuple)):
117
121
  if len(arguments) != len(event_abi["inputs"]):
118
- raise ValueError(
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
- # type ignored b/c arguments is always a dict at this point
130
- for key, value in arguments.items() # type: ignore
132
+ for key, value in arguments.items()
131
133
  }
132
134
 
133
- # typed dict cannot be used w/ a normal Dict
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 ValueError(
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[ABIEventParams],
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["indexed"] and is_dynamic_sized_type(input_abi["type"]):
218
+ if input_abi.get("indexed") and is_dynamic_sized_type(input_abi["type"]):
219
219
  yield "bytes32"
220
220
  else:
221
- yield get_normalized_abi_arg_type(input_abi)
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
- if event_abi["anonymous"]:
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(ABIEvent({"inputs": log_topics_abi}))
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(ABIEvent({"inputs": log_data_abi}))
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
- _fromBlock = None
345
- _toBlock = None
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 fromBlock(self) -> BlockIdentifier:
366
- return self._fromBlock
359
+ def from_block(self) -> BlockIdentifier:
360
+ return self._from_block
367
361
 
368
- @fromBlock.setter
369
- def fromBlock(self, value: BlockIdentifier) -> None:
370
- if self._fromBlock is None and not self._immutable:
371
- self._fromBlock = value
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 ValueError(
374
- f"fromBlock is already set to {self._fromBlock!r}. "
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 toBlock(self) -> BlockIdentifier:
380
- return self._toBlock
373
+ def to_block(self) -> BlockIdentifier:
374
+ return self._to_block
381
375
 
382
- @toBlock.setter
383
- def toBlock(self, value: BlockIdentifier) -> None:
384
- if self._toBlock is None and not self._immutable:
385
- self._toBlock = value
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 ValueError(
388
- f"toBlock is already set to {self._toBlock!r}. "
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 ValueError(
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.fromBlock,
437
- "toBlock": self.toBlock,
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 ValueError(f"Invalid web3 argument: got: {w3!r}")
440
+ raise Web3ValueError(f"Invalid web3 argument: got: {w3!r}")
447
441
 
448
- for arg in AttributeDict.values(self.args): # type: ignore[arg-type]
449
- arg._immutable = True # type: ignore[attr-defined]
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 ValueError(f"Invalid web3 argument: got: {async_w3!r}")
458
+ raise Web3ValueError(f"Invalid web3 argument: got: {async_w3!r}")
465
459
 
466
- for arg in AttributeDict.values(self.args): # type: ignore[arg-type]
467
- arg._immutable = True # type: ignore[attr-defined]
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
- # https://github.com/python/mypy/issues/4976
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["indexed"] is True:
488
+ if item.get("indexed") is True:
496
489
  value = TopicArgumentFilter(
497
- abi_codec=abi_codec, arg_type=get_normalized_abi_arg_type(item)
490
+ abi_codec=abi_codec, arg_type=collapse_if_tuple(item)
498
491
  )
499
492
  else:
500
- value = DataArgumentFilter(arg_type=get_normalized_abi_arg_type(item))
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 ValueError("Setting values is forbidden after filter is deployed.")
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 ValueError("An argument match value/s has already been set.")
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 ValueError("Setting values is forbidden after filter is deployed.")
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 ValueError("An argument match value/s has already been set.")
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)