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.
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.2.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.2.dist-info → web3-7.0.0.dist-info}/WHEEL +1 -1
  138. {web3-6.20.2.dist-info → web3-7.0.0.dist-info}/top_level.txt +0 -1
  139. ethpm/__init__.py +0 -20
  140. ethpm/_utils/__init__.py +0 -0
  141. ethpm/_utils/backend.py +0 -93
  142. ethpm/_utils/cache.py +0 -44
  143. ethpm/_utils/chains.py +0 -119
  144. ethpm/_utils/contract.py +0 -35
  145. ethpm/_utils/deployments.py +0 -145
  146. ethpm/_utils/ipfs.py +0 -116
  147. ethpm/_utils/protobuf/__init__.py +0 -0
  148. ethpm/_utils/protobuf/ipfs_file_pb2.py +0 -33
  149. ethpm/_utils/registry.py +0 -29
  150. ethpm/assets/__init__.py +0 -0
  151. ethpm/assets/ens/v3.json +0 -1
  152. ethpm/assets/escrow/with_bytecode_v3.json +0 -1
  153. ethpm/assets/ipfs_file.proto +0 -32
  154. ethpm/assets/owned/output_v3.json +0 -1
  155. ethpm/assets/owned/with_contract_type_v3.json +0 -1
  156. ethpm/assets/registry/contracts/Authority.sol +0 -156
  157. ethpm/assets/registry/contracts/IndexedOrderedSetLib.sol +0 -106
  158. ethpm/assets/registry/contracts/PackageDB.sol +0 -225
  159. ethpm/assets/registry/contracts/PackageRegistry.sol +0 -361
  160. ethpm/assets/registry/contracts/PackageRegistryInterface.sol +0 -97
  161. ethpm/assets/registry/contracts/ReleaseDB.sol +0 -309
  162. ethpm/assets/registry/contracts/ReleaseValidator.sol +0 -152
  163. ethpm/assets/registry/solc_input.json +0 -1
  164. ethpm/assets/registry/solc_output.json +0 -1
  165. ethpm/assets/registry/v3.json +0 -1
  166. ethpm/assets/safe-math-lib/v3-strict-no-deployments.json +0 -1
  167. ethpm/assets/simple-registry/contracts/Ownable.sol +0 -63
  168. ethpm/assets/simple-registry/contracts/PackageRegistry.sol +0 -373
  169. ethpm/assets/simple-registry/contracts/PackageRegistryInterface.sol +0 -96
  170. ethpm/assets/simple-registry/solc_input.json +0 -33
  171. ethpm/assets/simple-registry/solc_output.json +0 -1
  172. ethpm/assets/simple-registry/v3.json +0 -1
  173. ethpm/assets/standard-token/output_v3.json +0 -1
  174. ethpm/assets/standard-token/with_bytecode_v3.json +0 -1
  175. ethpm/assets/vyper_registry/0.1.0.json +0 -1
  176. ethpm/assets/vyper_registry/registry.vy +0 -216
  177. ethpm/assets/vyper_registry/registry_with_delete.vy +0 -244
  178. ethpm/backends/__init__.py +0 -0
  179. ethpm/backends/base.py +0 -43
  180. ethpm/backends/http.py +0 -108
  181. ethpm/backends/ipfs.py +0 -219
  182. ethpm/backends/registry.py +0 -154
  183. ethpm/constants.py +0 -17
  184. ethpm/contract.py +0 -187
  185. ethpm/dependencies.py +0 -58
  186. ethpm/deployments.py +0 -80
  187. ethpm/ethpm-spec/examples/escrow/1.0.0-pretty.json +0 -146
  188. ethpm/ethpm-spec/examples/escrow/1.0.0.json +0 -1
  189. ethpm/ethpm-spec/examples/escrow/contracts/Escrow.sol +0 -32
  190. ethpm/ethpm-spec/examples/escrow/contracts/SafeSendLib.sol +0 -20
  191. ethpm/ethpm-spec/examples/escrow/v3-pretty.json +0 -171
  192. ethpm/ethpm-spec/examples/escrow/v3.json +0 -1
  193. ethpm/ethpm-spec/examples/owned/1.0.0-pretty.json +0 -21
  194. ethpm/ethpm-spec/examples/owned/1.0.0.json +0 -1
  195. ethpm/ethpm-spec/examples/owned/contracts/Owned.sol +0 -12
  196. ethpm/ethpm-spec/examples/owned/v3-pretty.json +0 -27
  197. ethpm/ethpm-spec/examples/owned/v3.json +0 -1
  198. ethpm/ethpm-spec/examples/piper-coin/1.0.0-pretty.json +0 -31
  199. ethpm/ethpm-spec/examples/piper-coin/1.0.0.json +0 -1
  200. ethpm/ethpm-spec/examples/piper-coin/v3-pretty.json +0 -21
  201. ethpm/ethpm-spec/examples/piper-coin/v3.json +0 -1
  202. ethpm/ethpm-spec/examples/safe-math-lib/1.0.0-pretty.json +0 -85
  203. ethpm/ethpm-spec/examples/safe-math-lib/1.0.0.json +0 -1
  204. ethpm/ethpm-spec/examples/safe-math-lib/contracts/SafeMathLib.sol +0 -24
  205. ethpm/ethpm-spec/examples/safe-math-lib/v3-pretty.json +0 -117
  206. ethpm/ethpm-spec/examples/safe-math-lib/v3.json +0 -1
  207. ethpm/ethpm-spec/examples/standard-token/1.0.0-pretty.json +0 -55
  208. ethpm/ethpm-spec/examples/standard-token/1.0.0.json +0 -1
  209. ethpm/ethpm-spec/examples/standard-token/contracts/AbstractToken.sol +0 -20
  210. ethpm/ethpm-spec/examples/standard-token/contracts/StandardToken.sol +0 -84
  211. ethpm/ethpm-spec/examples/standard-token/v3-pretty.json +0 -460
  212. ethpm/ethpm-spec/examples/standard-token/v3.json +0 -1
  213. ethpm/ethpm-spec/examples/transferable/1.0.0-pretty.json +0 -21
  214. ethpm/ethpm-spec/examples/transferable/1.0.0.json +0 -1
  215. ethpm/ethpm-spec/examples/transferable/contracts/Transferable.sol +0 -14
  216. ethpm/ethpm-spec/examples/transferable/v3-pretty.json +0 -27
  217. ethpm/ethpm-spec/examples/transferable/v3.json +0 -1
  218. ethpm/ethpm-spec/examples/wallet/1.0.0-pretty.json +0 -120
  219. ethpm/ethpm-spec/examples/wallet/1.0.0.json +0 -1
  220. ethpm/ethpm-spec/examples/wallet/contracts/Wallet.sol +0 -41
  221. ethpm/ethpm-spec/examples/wallet/v3-pretty.json +0 -181
  222. ethpm/ethpm-spec/examples/wallet/v3.json +0 -1
  223. ethpm/ethpm-spec/examples/wallet-with-send/1.0.0-pretty.json +0 -135
  224. ethpm/ethpm-spec/examples/wallet-with-send/1.0.0.json +0 -1
  225. ethpm/ethpm-spec/examples/wallet-with-send/contracts/WalletWithSend.sol +0 -18
  226. ethpm/ethpm-spec/examples/wallet-with-send/v3-pretty.json +0 -207
  227. ethpm/ethpm-spec/examples/wallet-with-send/v3.json +0 -1
  228. ethpm/ethpm-spec/spec/package.spec.json +0 -379
  229. ethpm/ethpm-spec/spec/v3.spec.json +0 -483
  230. ethpm/exceptions.py +0 -68
  231. ethpm/package.py +0 -438
  232. ethpm/tools/__init__.py +0 -4
  233. ethpm/tools/builder.py +0 -930
  234. ethpm/tools/checker.py +0 -312
  235. ethpm/tools/get_manifest.py +0 -19
  236. ethpm/uri.py +0 -141
  237. ethpm/validation/__init__.py +0 -0
  238. ethpm/validation/manifest.py +0 -146
  239. ethpm/validation/misc.py +0 -39
  240. ethpm/validation/package.py +0 -80
  241. ethpm/validation/uri.py +0 -163
  242. web3/_utils/contract_sources/contract_data/address_reflector.py +0 -29
  243. web3/_utils/miner.py +0 -88
  244. web3/_utils/module_testing/go_ethereum_personal_module.py +0 -323
  245. web3/_utils/request.py +0 -265
  246. web3/middleware/abi.py +0 -11
  247. web3/middleware/async_cache.py +0 -99
  248. web3/middleware/cache.py +0 -374
  249. web3/middleware/exception_handling.py +0 -49
  250. web3/middleware/exception_retry_request.py +0 -188
  251. web3/middleware/fixture.py +0 -190
  252. web3/middleware/geth_poa.py +0 -81
  253. web3/middleware/normalize_request_parameters.py +0 -11
  254. web3/middleware/simulate_unmined_transaction.py +0 -43
  255. web3/pm.py +0 -602
  256. web3/providers/async_rpc.py +0 -99
  257. web3/providers/rpc.py +0 -98
  258. web3/providers/websocket/__init__.py +0 -11
  259. web3/providers/websocket/websocket_connection.py +0 -42
  260. web3/tools/__init__.py +0 -4
  261. web3/tools/pytest_ethereum/__init__.py +0 -0
  262. web3/tools/pytest_ethereum/_utils.py +0 -145
  263. web3/tools/pytest_ethereum/deployer.py +0 -48
  264. web3/tools/pytest_ethereum/exceptions.py +0 -22
  265. web3/tools/pytest_ethereum/linker.py +0 -128
  266. web3/tools/pytest_ethereum/plugins.py +0 -33
  267. web3-6.20.2.dist-info/METADATA +0 -103
  268. web3-6.20.2.dist-info/RECORD +0 -283
  269. web3-6.20.2.dist-info/entry_points.txt +0 -2
  270. /web3/_utils/{function_identifiers.py → abi_element_identifiers.py} +0 -0
web3/_utils/abi.py CHANGED
@@ -25,7 +25,6 @@ from typing import (
25
25
  )
26
26
 
27
27
  from eth_abi import (
28
- codec,
29
28
  decoding,
30
29
  encoding,
31
30
  )
@@ -47,11 +46,23 @@ from eth_abi.registry import (
47
46
  registry as default_registry,
48
47
  )
49
48
  from eth_typing import (
49
+ ABI,
50
+ ABIComponent,
51
+ ABIComponentIndexed,
52
+ ABIConstructor,
53
+ ABIElement,
54
+ ABIEvent,
55
+ ABIFallback,
56
+ ABIFunction,
57
+ ABIReceive,
50
58
  HexStr,
51
59
  TypeStr,
52
60
  )
53
61
  from eth_utils import (
62
+ collapse_if_tuple,
54
63
  decode_hex,
64
+ filter_abi_by_type,
65
+ get_abi_input_names,
55
66
  is_bytes,
56
67
  is_list_like,
57
68
  is_string,
@@ -59,9 +70,6 @@ from eth_utils import (
59
70
  to_text,
60
71
  to_tuple,
61
72
  )
62
- from eth_utils.abi import (
63
- collapse_if_tuple,
64
- )
65
73
  from eth_utils.toolz import (
66
74
  curry,
67
75
  partial,
@@ -78,20 +86,14 @@ from web3._utils.formatters import (
78
86
  recursive_map,
79
87
  )
80
88
  from web3.exceptions import (
81
- FallbackNotFound,
82
89
  MismatchedABI,
90
+ Web3AttributeError,
91
+ Web3TypeError,
92
+ Web3ValueError,
83
93
  )
84
94
  from web3.types import (
85
- ABI,
86
- ABIEvent,
87
- ABIEventParams,
88
- ABIFunction,
89
- ABIFunctionParams,
90
95
  TReturn,
91
96
  )
92
- from web3.utils import ( # public utils module
93
- get_abi_input_names,
94
- )
95
97
 
96
98
  if TYPE_CHECKING:
97
99
  from web3 import ( # noqa: F401
@@ -99,92 +101,50 @@ if TYPE_CHECKING:
99
101
  )
100
102
 
101
103
 
102
- def filter_by_type(_type: str, contract_abi: ABI) -> List[Union[ABIFunction, ABIEvent]]:
103
- return [abi for abi in contract_abi if abi["type"] == _type]
104
+ def fallback_func_abi_exists(contract_abi: ABI) -> Sequence[ABIFallback]:
105
+ return filter_abi_by_type("fallback", contract_abi)
104
106
 
105
107
 
106
- def filter_by_name(name: str, contract_abi: ABI) -> List[Union[ABIFunction, ABIEvent]]:
107
- return [
108
- abi
109
- for abi in contract_abi
110
- if (
111
- abi["type"] not in ("fallback", "constructor", "receive")
112
- and abi["name"] == name
113
- )
114
- ]
115
-
116
-
117
- def get_abi_input_types(abi: ABIFunction) -> List[str]:
118
- if "inputs" not in abi and (abi["type"] == "fallback" or abi["type"] == "receive"):
119
- return []
120
- else:
121
- return [collapse_if_tuple(cast(Dict[str, Any], arg)) for arg in abi["inputs"]]
108
+ def receive_func_abi_exists(contract_abi: ABI) -> Sequence[ABIReceive]:
109
+ return filter_abi_by_type("receive", contract_abi)
122
110
 
123
111
 
124
- def get_abi_output_types(abi: ABIFunction) -> List[str]:
125
- if abi["type"] == "fallback":
126
- return []
127
- else:
128
- return [collapse_if_tuple(cast(Dict[str, Any], arg)) for arg in abi["outputs"]]
129
-
130
-
131
- def get_receive_func_abi(contract_abi: ABI) -> ABIFunction:
132
- receive_abis = filter_by_type("receive", contract_abi)
133
- if receive_abis:
134
- return cast(ABIFunction, receive_abis[0])
135
- else:
136
- raise FallbackNotFound("No receive function was found in the contract ABI.")
137
-
138
-
139
- def get_fallback_func_abi(contract_abi: ABI) -> ABIFunction:
140
- fallback_abis = filter_by_type("fallback", contract_abi)
141
- if fallback_abis:
142
- return cast(ABIFunction, fallback_abis[0])
143
- else:
144
- raise FallbackNotFound("No fallback function was found in the contract ABI.")
145
-
146
-
147
- def fallback_func_abi_exists(contract_abi: ABI) -> List[Union[ABIFunction, ABIEvent]]:
148
- return filter_by_type("fallback", contract_abi)
149
-
150
-
151
- def receive_func_abi_exists(contract_abi: ABI) -> List[Union[ABIFunction, ABIEvent]]:
152
- return filter_by_type("receive", contract_abi)
153
-
154
-
155
- def get_indexed_event_inputs(event_abi: ABIEvent) -> List[ABIEventParams]:
156
- return [arg for arg in event_abi["inputs"] if arg["indexed"] is True]
112
+ def get_indexed_event_inputs(event_abi: ABIEvent) -> Sequence[ABIComponentIndexed]:
113
+ return [
114
+ cast(ABIComponentIndexed, arg)
115
+ for arg in event_abi["inputs"]
116
+ if cast(ABIComponentIndexed, arg)["indexed"] is True
117
+ ]
157
118
 
158
119
 
159
- def exclude_indexed_event_inputs(event_abi: ABIEvent) -> List[ABIEventParams]:
160
- return [arg for arg in event_abi["inputs"] if arg["indexed"] is False]
120
+ def exclude_indexed_event_inputs(event_abi: ABIEvent) -> Sequence[ABIComponent]:
121
+ return [
122
+ arg
123
+ for arg in event_abi["inputs"]
124
+ if cast(ABIComponentIndexed, arg)["indexed"] is False
125
+ ]
161
126
 
162
127
 
163
- def get_normalized_abi_arg_type(abi_arg: ABIEventParams) -> str:
128
+ def filter_by_argument_name(
129
+ argument_names: Collection[str], contract_abi: ABI
130
+ ) -> List[ABIElement]:
164
131
  """
165
- Return the normalized type for the abi argument provided.
166
- In order to account for tuple argument types, this abstraction
167
- makes use of `collapse_if_tuple()` to collapse the appropriate component
168
- types within a tuple type, if present.
132
+ Return a list of each ``ABIElement`` which contain arguments matching provided
133
+ names.
169
134
  """
170
- return collapse_if_tuple(dict(abi_arg))
135
+ abis_with_matching_args = []
136
+ for abi_element in contract_abi:
137
+ try:
138
+ abi_arg_names = get_abi_input_names(abi_element)
171
139
 
140
+ if set(argument_names).intersection(abi_arg_names) == set(argument_names):
141
+ abis_with_matching_args.append(abi_element)
142
+ except TypeError:
143
+ # fallback or receive functions do not have arguments
144
+ # proceed to next ABIElement
145
+ continue
172
146
 
173
- def filter_by_argument_count(
174
- num_arguments: int, contract_abi: ABI
175
- ) -> List[Union[ABIFunction, ABIEvent]]:
176
- return [abi for abi in contract_abi if len(abi["inputs"]) == num_arguments]
177
-
178
-
179
- def filter_by_argument_name(
180
- argument_names: Collection[str], contract_abi: ABI
181
- ) -> List[Union[ABIFunction, ABIEvent]]:
182
- return [
183
- abi
184
- for abi in contract_abi
185
- if set(argument_names).intersection(get_abi_input_names(abi))
186
- == set(argument_names)
187
- ]
147
+ return abis_with_matching_args
188
148
 
189
149
 
190
150
  class AddressEncoder(encoding.AddressEncoder):
@@ -193,7 +153,7 @@ class AddressEncoder(encoding.AddressEncoder):
193
153
  if is_ens_name(value):
194
154
  return
195
155
 
196
- super().validate_value(value)
156
+ super().validate_value(value) # type: ignore[no-untyped-call]
197
157
 
198
158
 
199
159
  class AcceptsHexStrEncoder(encoding.BaseEncoder):
@@ -208,7 +168,7 @@ class AcceptsHexStrEncoder(encoding.BaseEncoder):
208
168
  subencoder: encoding.BaseEncoder,
209
169
  **kwargs: Dict[str, Any],
210
170
  ) -> None:
211
- super().__init__(**kwargs)
171
+ super().__init__(**kwargs) # type: ignore[no-untyped-call]
212
172
  self.subencoder = subencoder
213
173
  self.is_dynamic = subencoder.is_dynamic
214
174
 
@@ -220,14 +180,14 @@ class AcceptsHexStrEncoder(encoding.BaseEncoder):
220
180
  # cast b/c expects BaseCoder but `from_type_string`
221
181
  # restricted to BaseEncoder subclasses
222
182
  subencoder = cast(
223
- encoding.BaseEncoder, subencoder_cls.from_type_str(abi_type, registry)
183
+ encoding.BaseEncoder, subencoder_cls.from_type_str(abi_type, registry) # type: ignore[no-untyped-call] # noqa: E501
224
184
  )
225
185
  return cls(subencoder)
226
186
 
227
187
  @classmethod
228
188
  def get_subencoder_class(cls) -> Type[encoding.BaseEncoder]:
229
189
  if cls.subencoder_cls is None:
230
- raise AttributeError(f"No subencoder class is set. {cls.__name__}")
190
+ raise Web3AttributeError(f"No subencoder class is set. {cls.__name__}")
231
191
  return cls.subencoder_cls
232
192
 
233
193
  def validate_value(self, value: Any) -> None:
@@ -285,35 +245,39 @@ class ExactLengthBytesEncoder(BytesEncoder):
285
245
  is_strict = True
286
246
 
287
247
  def validate(self) -> None:
288
- super().validate()
248
+ super().validate() # type: ignore[no-untyped-call]
289
249
  if self.value_bit_size is None:
290
- raise ValueError("`value_bit_size` may not be none")
250
+ raise Web3ValueError("`value_bit_size` may not be none")
291
251
  if self.data_byte_size is None:
292
- raise ValueError("`data_byte_size` may not be none")
252
+ raise Web3ValueError("`data_byte_size` may not be none")
293
253
  if self.is_big_endian is None:
294
- raise ValueError("`is_big_endian` may not be none")
254
+ raise Web3ValueError("`is_big_endian` may not be none")
295
255
 
296
256
  if self.value_bit_size % 8 != 0:
297
- raise ValueError(
257
+ raise Web3ValueError(
298
258
  f"Invalid value bit size: {self.value_bit_size}. "
299
259
  "Must be a multiple of 8"
300
260
  )
301
261
 
302
262
  if self.value_bit_size > self.data_byte_size * 8:
303
- raise ValueError("Value byte size exceeds data size")
263
+ raise Web3ValueError("Value byte size exceeds data size")
304
264
 
305
- @parse_type_str("bytes")
265
+ @parse_type_str("bytes") # type: ignore[no-untyped-call]
306
266
  def from_type_str(
307
267
  cls, abi_type: BasicType, registry: ABIRegistry
308
268
  ) -> "ExactLengthBytesEncoder":
309
269
  subencoder_cls = cls.get_subencoder_class()
310
- subencoder = subencoder_cls.from_type_str(abi_type.to_type_str(), registry)
311
- # type ignored b/c @parse_type_str decorator turns it into a classmethod,
312
- # so mypy thinks cls(...) is a call to __call__, but actually calls __init__
313
- return cls( # type: ignore
314
- subencoder,
315
- value_bit_size=abi_type.sub * 8,
316
- data_byte_size=abi_type.sub,
270
+ subencoder = subencoder_cls.from_type_str(abi_type.to_type_str(), registry) # type: ignore[no-untyped-call] # noqa: E501
271
+ return cast(
272
+ ExactLengthBytesEncoder,
273
+ # type ignored b/c mypy thinks the __call__ is from BaseEncoder, but it's
274
+ # from ExactLengthBytesEncoder, which does have value_bit_size and
275
+ # data_byte_size attributes
276
+ cls( # type: ignore[call-arg]
277
+ subencoder,
278
+ value_bit_size=abi_type.sub * 8,
279
+ data_byte_size=abi_type.sub,
280
+ ),
317
281
  )
318
282
 
319
283
 
@@ -339,110 +303,7 @@ class TextStringEncoder(encoding.TextStringEncoder):
339
303
  msg="not decodable as unicode string",
340
304
  )
341
305
 
342
- super().validate_value(value)
343
-
344
-
345
- def filter_by_encodability(
346
- abi_codec: codec.ABIEncoder,
347
- args: Sequence[Any],
348
- kwargs: Dict[str, Any],
349
- contract_abi: ABI,
350
- ) -> List[ABIFunction]:
351
- return [
352
- cast(ABIFunction, function_abi)
353
- for function_abi in contract_abi
354
- if check_if_arguments_can_be_encoded(
355
- cast(ABIFunction, function_abi), abi_codec, args, kwargs
356
- )
357
- ]
358
-
359
-
360
- def check_if_arguments_can_be_encoded(
361
- function_abi: ABIFunction,
362
- abi_codec: codec.ABIEncoder,
363
- args: Sequence[Any],
364
- kwargs: Dict[str, Any],
365
- ) -> bool:
366
- try:
367
- arguments = merge_args_and_kwargs(function_abi, args, kwargs)
368
- except TypeError:
369
- return False
370
-
371
- if len(function_abi.get("inputs", [])) != len(arguments):
372
- return False
373
-
374
- try:
375
- types, aligned_args = get_aligned_abi_inputs(function_abi, arguments)
376
- except TypeError:
377
- return False
378
-
379
- return all(
380
- abi_codec.is_encodable(_type, arg) for _type, arg in zip(types, aligned_args)
381
- )
382
-
383
-
384
- def merge_args_and_kwargs(
385
- function_abi: ABIFunction, args: Sequence[Any], kwargs: Dict[str, Any]
386
- ) -> Tuple[Any, ...]:
387
- """
388
- Takes a list of positional args (``args``) and a dict of keyword args
389
- (``kwargs``) defining values to be passed to a call to the contract function
390
- described by ``function_abi``. Checks to ensure that the correct number of
391
- args were given, no duplicate args were given, and no unknown args were
392
- given. Returns a list of argument values aligned to the order of inputs
393
- defined in ``function_abi``.
394
- """
395
- # Ensure the function is being applied to the correct number of args
396
- if len(args) + len(kwargs) != len(function_abi.get("inputs", [])):
397
- raise TypeError(
398
- f"Incorrect argument count. Expected '{len(function_abi['inputs'])}'"
399
- f". Got '{len(args) + len(kwargs)}'"
400
- )
401
-
402
- # If no keyword args were given, we don't need to align them
403
- if not kwargs:
404
- return cast(Tuple[Any, ...], args)
405
-
406
- kwarg_names = set(kwargs.keys())
407
- sorted_arg_names = tuple(arg_abi["name"] for arg_abi in function_abi["inputs"])
408
- args_as_kwargs = dict(zip(sorted_arg_names, args))
409
-
410
- # Check for duplicate args
411
- duplicate_args = kwarg_names.intersection(args_as_kwargs.keys())
412
- if duplicate_args:
413
- raise TypeError(
414
- f"{function_abi.get('name')}() got multiple values for argument(s) "
415
- f"'{', '.join(duplicate_args)}'"
416
- )
417
-
418
- # Check for unknown args
419
- unknown_args = kwarg_names.difference(sorted_arg_names)
420
- if unknown_args:
421
- if function_abi.get("name"):
422
- raise TypeError(
423
- f"{function_abi.get('name')}() got unexpected keyword argument(s)"
424
- f" '{', '.join(unknown_args)}'"
425
- )
426
- raise TypeError(
427
- f"Type: '{function_abi.get('type')}' got unexpected keyword argument(s)"
428
- f" '{', '.join(unknown_args)}'"
429
- )
430
-
431
- # Sort args according to their position in the ABI and unzip them from their
432
- # names
433
- sorted_args = tuple(
434
- zip(
435
- *sorted(
436
- itertools.chain(kwargs.items(), args_as_kwargs.items()),
437
- key=lambda kv: sorted_arg_names.index(kv[0]),
438
- )
439
- )
440
- )
441
-
442
- if sorted_args:
443
- return sorted_args[1]
444
- else:
445
- return tuple()
306
+ super().validate_value(value) # type: ignore[no-untyped-call]
446
307
 
447
308
 
448
309
  TUPLE_TYPE_STR_RE = re.compile(r"^(tuple)((\[([1-9]\d*\b)?])*)??$")
@@ -464,7 +325,9 @@ def get_tuple_type_str_parts(s: str) -> Optional[Tuple[str, Optional[str]]]:
464
325
  return None
465
326
 
466
327
 
467
- def _align_abi_input(arg_abi: ABIFunctionParams, arg: Any) -> Tuple[Any, ...]:
328
+ def _align_abi_input(
329
+ arg_abi: Union[ABIComponent, ABIComponentIndexed], arg: Any
330
+ ) -> Tuple[Any, ...]:
468
331
  """
469
332
  Aligns the values of any mapping at any level of nesting in ``arg``
470
333
  according to the layout of the corresponding abi spec.
@@ -488,7 +351,7 @@ def _align_abi_input(arg_abi: ABIFunctionParams, arg: Any) -> Tuple[Any, ...]:
488
351
  new_abi = copy.copy(arg_abi)
489
352
  new_abi["type"] = tuple_prefix + "[]" * (num_dims - 1)
490
353
 
491
- sub_abis = itertools.repeat(new_abi) # type: ignore
354
+ sub_abis = [cast(ABIComponent, abi) for abi in itertools.repeat(new_abi)]
492
355
 
493
356
  if isinstance(arg, abc.Mapping):
494
357
  # Arg is mapping. Align values according to abi order.
@@ -497,7 +360,7 @@ def _align_abi_input(arg_abi: ABIFunctionParams, arg: Any) -> Tuple[Any, ...]:
497
360
  aligned_arg = arg
498
361
 
499
362
  if not is_list_like(aligned_arg):
500
- raise TypeError(
363
+ raise Web3TypeError(
501
364
  f'Expected non-string sequence for "{arg_abi.get("type")}" '
502
365
  f"component type: got {aligned_arg}"
503
366
  )
@@ -511,38 +374,21 @@ def _align_abi_input(arg_abi: ABIFunctionParams, arg: Any) -> Tuple[Any, ...]:
511
374
  )
512
375
 
513
376
 
514
- def get_aligned_abi_inputs(
515
- abi: ABIFunction, args: Union[Tuple[Any, ...], Mapping[Any, Any]]
516
- ) -> Tuple[Tuple[Any, ...], Tuple[Any, ...]]:
517
- """
518
- Takes a function ABI (``abi``) and a sequence or mapping of args (``args``).
519
- Returns a list of type strings for the function's inputs and a list of
520
- arguments which have been aligned to the layout of those types. The args
521
- contained in ``args`` may contain nested mappings or sequences corresponding
522
- to tuple-encoded values in ``abi``.
377
+ def find_constructor_abi_element_by_type(contract_abi: ABI) -> ABIConstructor:
523
378
  """
524
- input_abis = abi.get("inputs", [])
525
-
526
- if isinstance(args, abc.Mapping):
527
- # `args` is mapping. Align values according to abi order.
528
- args = tuple(args[abi["name"]] for abi in input_abis)
529
-
530
- return (
531
- # typed dict cannot be used w/ a normal Dict
532
- # https://github.com/python/mypy/issues/4976
533
- tuple(collapse_if_tuple(abi) for abi in input_abis), # type: ignore
534
- type(args)(_align_abi_input(abi, arg) for abi, arg in zip(input_abis, args)),
535
- )
379
+ Find the constructor ABI element in the contract ABI.
536
380
 
537
-
538
- def get_constructor_abi(contract_abi: ABI) -> ABIFunction:
381
+ This function is often used in place of `web3.utils.abi.get_abi_element` to find
382
+ a constructor without considering it's argument types. This is used prior to
383
+ encoding the abi, since the argument types are not known at that time.
384
+ """
539
385
  candidates = [abi for abi in contract_abi if abi["type"] == "constructor"]
540
386
  if len(candidates) == 1:
541
387
  return candidates[0]
542
388
  elif len(candidates) == 0:
543
389
  return None
544
390
  elif len(candidates) > 1:
545
- raise ValueError("Found multiple constructors.")
391
+ raise Web3ValueError("Found multiple constructors.")
546
392
  return None
547
393
 
548
394
 
@@ -564,7 +410,7 @@ STATIC_TYPES = list(
564
410
  )
565
411
 
566
412
  BASE_TYPE_REGEX = "|".join(
567
- (_type + "(?![a-z0-9])" for _type in itertools.chain(STATIC_TYPES, DYNAMIC_TYPES))
413
+ _type + "(?![a-z0-9])" for _type in itertools.chain(STATIC_TYPES, DYNAMIC_TYPES)
568
414
  )
569
415
 
570
416
  SUB_TYPE_REGEX = r"\[" "[0-9]*" r"\]"
@@ -630,14 +476,14 @@ END_BRACKETS_OF_ARRAY_TYPE_REGEX = r"\[[^]]*\]$"
630
476
 
631
477
  def sub_type_of_array_type(abi_type: TypeStr) -> str:
632
478
  if not is_array_type(abi_type):
633
- raise ValueError(f"Cannot parse subtype of nonarray abi-type: {abi_type}")
479
+ raise Web3ValueError(f"Cannot parse subtype of nonarray abi-type: {abi_type}")
634
480
 
635
- return re.sub(END_BRACKETS_OF_ARRAY_TYPE_REGEX, "", abi_type, 1)
481
+ return re.sub(END_BRACKETS_OF_ARRAY_TYPE_REGEX, "", abi_type, count=1)
636
482
 
637
483
 
638
484
  def length_of_array_type(abi_type: TypeStr) -> int:
639
485
  if not is_array_type(abi_type):
640
- raise ValueError(f"Cannot parse length of nonarray abi-type: {abi_type}")
486
+ raise Web3ValueError(f"Cannot parse length of nonarray abi-type: {abi_type}")
641
487
 
642
488
  inner_brackets = (
643
489
  re.search(END_BRACKETS_OF_ARRAY_TYPE_REGEX, abi_type).group(0).strip("[]")
@@ -669,8 +515,8 @@ def is_probably_enum(abi_type: TypeStr) -> bool:
669
515
 
670
516
  @to_tuple
671
517
  def normalize_event_input_types(
672
- abi_args: Collection[Union[ABIFunction, ABIEvent]]
673
- ) -> Iterable[Union[ABIFunction, ABIEvent, Dict[TypeStr, Any]]]:
518
+ abi_args: Collection[ABIEvent],
519
+ ) -> Iterable[Union[ABIEvent, Dict[TypeStr, Any]]]:
674
520
  for arg in abi_args:
675
521
  if is_recognized_type(arg["type"]):
676
522
  yield arg
@@ -680,17 +526,6 @@ def normalize_event_input_types(
680
526
  yield arg
681
527
 
682
528
 
683
- def abi_to_signature(abi: Union[ABIFunction, ABIEvent]) -> str:
684
- function_signature = "{fn_name}({fn_input_types})".format(
685
- fn_name=abi["name"],
686
- fn_input_types=",".join(
687
- collapse_if_tuple(dict(arg))
688
- for arg in normalize_event_input_types(abi.get("inputs", []))
689
- ),
690
- )
691
- return function_signature
692
-
693
-
694
529
  ########################################################
695
530
  #
696
531
  # Conditionally modifying data, tagged with ABI Types
@@ -705,8 +540,8 @@ def map_abi_data(
705
540
  data: Sequence[Any],
706
541
  ) -> Any:
707
542
  """
708
- This function will apply normalizers to your data, in the
709
- context of the relevant types. Each normalizer is in the format:
543
+ Applies normalizers to your data, in the context of the relevant types.
544
+ Each normalizer is in the format:
710
545
 
711
546
  def normalizer(datatype, data):
712
547
  # Conditionally modify data
@@ -772,7 +607,7 @@ def data_tree_map(
772
607
 
773
608
  class ABITypedData(namedtuple("ABITypedData", "abi_type, data")):
774
609
  """
775
- This class marks data as having a certain ABI-type.
610
+ Marks data as having a certain ABI-type.
776
611
 
777
612
  >>> a1 = ABITypedData(['address', addr1])
778
613
  >>> a2 = ABITypedData(['address', addr2])
@@ -841,7 +676,7 @@ def strip_abi_type(elements: Any) -> Any:
841
676
  def build_non_strict_registry() -> ABIRegistry:
842
677
  # We make a copy here just to make sure that eth-abi's default registry is not
843
678
  # affected by our custom encoder subclasses
844
- registry = default_registry.copy()
679
+ registry = default_registry.copy() # type: ignore[no-untyped-call]
845
680
 
846
681
  registry.unregister("address")
847
682
  registry.unregister("bytes<M>")
@@ -849,25 +684,25 @@ def build_non_strict_registry() -> ABIRegistry:
849
684
  registry.unregister("string")
850
685
 
851
686
  registry.register(
852
- BaseEquals("address"),
687
+ BaseEquals("address"), # type: ignore[no-untyped-call]
853
688
  AddressEncoder,
854
689
  decoding.AddressDecoder,
855
690
  label="address",
856
691
  )
857
692
  registry.register(
858
- BaseEquals("bytes", with_sub=True),
693
+ BaseEquals("bytes", with_sub=True), # type: ignore[no-untyped-call]
859
694
  BytesEncoder,
860
695
  decoding.BytesDecoder,
861
696
  label="bytes<M>",
862
697
  )
863
698
  registry.register(
864
- BaseEquals("bytes", with_sub=False),
699
+ BaseEquals("bytes", with_sub=False), # type: ignore[no-untyped-call]
865
700
  ByteStringEncoder,
866
701
  decoding.ByteStringDecoder,
867
702
  label="bytes",
868
703
  )
869
704
  registry.register(
870
- BaseEquals("string"),
705
+ BaseEquals("string"), # type: ignore[no-untyped-call]
871
706
  TextStringEncoder,
872
707
  decoding.StringDecoder,
873
708
  label="string",
@@ -876,7 +711,7 @@ def build_non_strict_registry() -> ABIRegistry:
876
711
 
877
712
 
878
713
  def build_strict_registry() -> ABIRegistry:
879
- registry = default_registry.copy()
714
+ registry = default_registry.copy() # type: ignore[no-untyped-call]
880
715
 
881
716
  registry.unregister("address")
882
717
  registry.unregister("bytes<M>")
@@ -884,25 +719,25 @@ def build_strict_registry() -> ABIRegistry:
884
719
  registry.unregister("string")
885
720
 
886
721
  registry.register(
887
- BaseEquals("address"),
722
+ BaseEquals("address"), # type: ignore[no-untyped-call]
888
723
  AddressEncoder,
889
724
  decoding.AddressDecoder,
890
725
  label="address",
891
726
  )
892
727
  registry.register(
893
- BaseEquals("bytes", with_sub=True),
728
+ BaseEquals("bytes", with_sub=True), # type: ignore[no-untyped-call]
894
729
  ExactLengthBytesEncoder,
895
730
  decoding.BytesDecoder,
896
731
  label="bytes<M>",
897
732
  )
898
733
  registry.register(
899
- BaseEquals("bytes", with_sub=False),
734
+ BaseEquals("bytes", with_sub=False), # type: ignore[no-untyped-call]
900
735
  StrictByteStringEncoder,
901
736
  decoding.ByteStringDecoder,
902
737
  label="bytes",
903
738
  )
904
739
  registry.register(
905
- BaseEquals("string"),
740
+ BaseEquals("string"), # type: ignore[no-untyped-call]
906
741
  encoding.TextStringEncoder,
907
742
  decoding.StringDecoder,
908
743
  label="string",
@@ -911,7 +746,11 @@ def build_strict_registry() -> ABIRegistry:
911
746
 
912
747
 
913
748
  def named_tree(
914
- abi: Iterable[Union[ABIFunctionParams, ABIFunction, ABIEvent, Dict[TypeStr, Any]]],
749
+ abi: Iterable[
750
+ Union[
751
+ ABIComponent, ABIComponentIndexed, ABIFunction, ABIEvent, Dict[TypeStr, Any]
752
+ ]
753
+ ],
915
754
  data: Iterable[Tuple[Any, ...]],
916
755
  ) -> Dict[str, Any]:
917
756
  """
@@ -924,10 +763,12 @@ def named_tree(
924
763
 
925
764
 
926
765
  def _named_subtree(
927
- abi: Union[ABIFunctionParams, ABIFunction, ABIEvent, Dict[TypeStr, Any]],
766
+ abi: Union[
767
+ ABIComponent, ABIComponentIndexed, ABIFunction, ABIEvent, Dict[TypeStr, Any]
768
+ ],
928
769
  data: Tuple[Any, ...],
929
770
  ) -> Union[Dict[str, Any], Tuple[Any, ...], List[Any]]:
930
- abi_type = parse(collapse_if_tuple(dict(abi)))
771
+ abi_type = parse(collapse_if_tuple(cast(Dict[str, Any], abi)))
931
772
 
932
773
  if abi_type.is_array:
933
774
  item_type = abi_type.item_type.to_type_str()
@@ -936,7 +777,11 @@ def _named_subtree(
936
777
  return items
937
778
 
938
779
  elif isinstance(abi_type, TupleType):
939
- abi = cast(ABIFunctionParams, abi)
780
+ if abi.get("indexed"):
781
+ abi = cast(ABIComponentIndexed, abi)
782
+ else:
783
+ abi = cast(ABIComponent, abi)
784
+
940
785
  names = [item["name"] for item in abi["components"]]
941
786
  items = [_named_subtree(*item) for item in zip(abi["components"], data)]
942
787
 
@@ -1029,7 +874,6 @@ async def async_map_if_collection(
1029
874
  Apply an awaitable method to each element of a collection or value of a dictionary.
1030
875
  If the value is not a collection, return it unmodified.
1031
876
  """
1032
-
1033
877
  datatype = type(value)
1034
878
  if isinstance(value, Mapping):
1035
879
  return datatype({key: await func(val) for key, val in value.values()})