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
@@ -2,6 +2,7 @@ import math
2
2
  from typing import (
3
3
  TYPE_CHECKING,
4
4
  List,
5
+ Literal,
5
6
  Optional,
6
7
  Union,
7
8
  cast,
@@ -19,9 +20,6 @@ from hexbytes import (
19
20
  HexBytes,
20
21
  )
21
22
 
22
- from web3._utils.compat import (
23
- Literal,
24
- )
25
23
  from web3._utils.utility_methods import (
26
24
  all_in_dict,
27
25
  any_in_dict,
@@ -29,6 +27,10 @@ from web3._utils.utility_methods import (
29
27
  from web3.constants import (
30
28
  DYNAMIC_FEE_TXN_PARAMS,
31
29
  )
30
+ from web3.exceptions import (
31
+ Web3AttributeError,
32
+ Web3ValueError,
33
+ )
32
34
  from web3.types import (
33
35
  BlockIdentifier,
34
36
  TxData,
@@ -107,7 +109,7 @@ def fill_nonce(w3: "Web3", transaction: TxParams) -> TxParams:
107
109
  @curry
108
110
  def fill_transaction_defaults(w3: "Web3", transaction: TxParams) -> TxParams:
109
111
  """
110
- if w3 is None, fill as much as possible while offline
112
+ If w3 is None, fill as much as possible while offline
111
113
  """
112
114
  strategy_based_gas_price = w3.eth.generate_gas_price(transaction)
113
115
  is_dynamic_fee_transaction = strategy_based_gas_price is None and (
@@ -130,7 +132,7 @@ def fill_transaction_defaults(w3: "Web3", transaction: TxParams) -> TxParams:
130
132
 
131
133
  if callable(default_getter):
132
134
  if w3 is None:
133
- raise ValueError(
135
+ raise Web3ValueError(
134
136
  f"You must specify a '{key}' value in the transaction"
135
137
  )
136
138
  default_val = default_getter(w3, transaction)
@@ -160,7 +162,7 @@ def get_buffered_gas_estimate(
160
162
  gas_limit = get_block_gas_limit(w3)
161
163
 
162
164
  if gas_estimate > gas_limit:
163
- raise ValueError(
165
+ raise Web3ValueError(
164
166
  "Contract does not appear to be deployable within the "
165
167
  f"current network gas limits. Estimated: {gas_estimate}. "
166
168
  f"Current gas limit: {gas_limit}"
@@ -172,7 +174,7 @@ def get_buffered_gas_estimate(
172
174
  def get_required_transaction(w3: "Web3", transaction_hash: _Hash32) -> TxData:
173
175
  current_transaction = w3.eth.get_transaction(transaction_hash)
174
176
  if not current_transaction:
175
- raise ValueError(
177
+ raise Web3ValueError(
176
178
  f"Supplied transaction with hash {transaction_hash!r} does not exist"
177
179
  )
178
180
  return current_transaction
@@ -204,7 +206,7 @@ def extract_valid_transaction_params(transaction_params: TxData) -> TxParams:
204
206
  msg = 'failure to handle this transaction due to both "input: {}" and'
205
207
  msg += ' "data: {}" are populated. You need to resolve this conflict.'
206
208
  err_vals = (transaction_params["input"], extracted_params["data"])
207
- raise AttributeError(msg.format(*err_vals))
209
+ raise Web3AttributeError(msg.format(*err_vals))
208
210
  else:
209
211
  return extracted_params
210
212
  else:
@@ -223,7 +225,7 @@ def extract_valid_transaction_params(transaction_params: TxData) -> TxParams:
223
225
  def assert_valid_transaction_params(transaction_params: TxParams) -> None:
224
226
  for param in transaction_params:
225
227
  if param not in VALID_TRANSACTION_PARAMS:
226
- raise ValueError(f"{param} is not a valid transaction parameter")
228
+ raise Web3ValueError(f"{param} is not a valid transaction parameter")
227
229
 
228
230
 
229
231
  def prepare_replacement_transaction(
@@ -233,14 +235,14 @@ def prepare_replacement_transaction(
233
235
  gas_multiplier: float = 1.125,
234
236
  ) -> TxParams:
235
237
  if original_transaction["blockHash"] is not None:
236
- raise ValueError(
238
+ raise Web3ValueError(
237
239
  f'Supplied transaction with hash {original_transaction["hash"]!r} '
238
240
  "has already been mined"
239
241
  )
240
242
  if "nonce" in replacement_transaction and (
241
243
  replacement_transaction["nonce"] != original_transaction["nonce"]
242
244
  ):
243
- raise ValueError(
245
+ raise Web3ValueError(
244
246
  "Supplied nonce in new_transaction must match the pending transaction"
245
247
  )
246
248
 
@@ -259,7 +261,7 @@ def prepare_replacement_transaction(
259
261
  and original_transaction["gasPrice"] is not None
260
262
  ):
261
263
  if replacement_transaction["gasPrice"] <= original_transaction["gasPrice"]:
262
- raise ValueError(
264
+ raise Web3ValueError(
263
265
  "Supplied gas price must exceed existing transaction gas price"
264
266
  )
265
267
 
@@ -10,6 +10,10 @@ from eth_utils import (
10
10
  to_hex,
11
11
  )
12
12
 
13
+ from web3.exceptions import (
14
+ Web3ValueError,
15
+ )
16
+
13
17
 
14
18
  def to_hex_if_bytes(val: Union[HexStr, str, bytes, bytearray]) -> HexStr:
15
19
  """
@@ -17,7 +21,7 @@ def to_hex_if_bytes(val: Union[HexStr, str, bytes, bytearray]) -> HexStr:
17
21
  meant to work with bytes and hex strings.
18
22
  """
19
23
  if isinstance(val, str) and not val.startswith("0x"):
20
- raise ValueError(f"Expected a hex string. Got: {val!r}")
24
+ raise Web3ValueError(f"Expected a hex string. Got: {val!r}")
21
25
 
22
26
  return to_hex(val) if isinstance(val, (bytes, bytearray)) else to_hex(hexstr=val)
23
27
 
web3/_utils/validation.py CHANGED
@@ -5,10 +5,14 @@ from typing import (
5
5
  )
6
6
 
7
7
  from eth_typing import (
8
+ ABI,
9
+ ABIFunction,
8
10
  HexStr,
9
11
  TypeStr,
10
12
  )
11
13
  from eth_utils import (
14
+ abi_to_signature,
15
+ filter_abi_by_type,
12
16
  function_abi_to_4byte_selector,
13
17
  is_0x_prefixed,
14
18
  is_binary_address,
@@ -38,8 +42,6 @@ from ens.utils import (
38
42
  is_valid_ens_name,
39
43
  )
40
44
  from web3._utils.abi import (
41
- abi_to_signature,
42
- filter_by_type,
43
45
  is_address_type,
44
46
  is_array_type,
45
47
  is_bool_type,
@@ -53,10 +55,8 @@ from web3._utils.abi import (
53
55
  )
54
56
  from web3.exceptions import (
55
57
  InvalidAddress,
56
- )
57
- from web3.types import (
58
- ABI,
59
- ABIFunction,
58
+ Web3TypeError,
59
+ Web3ValueError,
60
60
  )
61
61
 
62
62
 
@@ -74,16 +74,16 @@ def validate_abi(abi: ABI) -> None:
74
74
  Helper function for validating an ABI
75
75
  """
76
76
  if not is_list_like(abi):
77
- raise ValueError("'abi' is not a list")
77
+ raise Web3ValueError("'abi' is not a list")
78
78
 
79
79
  if not all(is_dict(e) for e in abi):
80
- raise ValueError("'abi' is not a list of dictionaries")
80
+ raise Web3ValueError("'abi' is not a list of dictionaries")
81
81
 
82
- functions = filter_by_type("function", abi)
82
+ functions = filter_abi_by_type("function", abi)
83
83
  selectors = groupby(compose(encode_hex, function_abi_to_4byte_selector), functions)
84
84
  duplicates = valfilter(lambda funcs: len(funcs) > 1, selectors)
85
85
  if duplicates:
86
- raise ValueError(
86
+ raise Web3ValueError(
87
87
  "Abi contains functions with colliding selectors. "
88
88
  f"Functions {_prepare_selector_collision_msg(duplicates)}"
89
89
  )
@@ -94,7 +94,7 @@ def validate_abi_type(abi_type: TypeStr) -> None:
94
94
  Helper function for validating an abi_type
95
95
  """
96
96
  if not is_recognized_type(abi_type):
97
- raise ValueError(f"Unrecognized abi_type: {abi_type}")
97
+ raise Web3ValueError(f"Unrecognized abi_type: {abi_type}")
98
98
 
99
99
 
100
100
  def validate_abi_value(abi_type: TypeStr, value: Any) -> None:
@@ -107,12 +107,12 @@ def validate_abi_value(abi_type: TypeStr, value: Any) -> None:
107
107
  specified_length = length_of_array_type(abi_type)
108
108
  if specified_length is not None:
109
109
  if specified_length < 1:
110
- raise TypeError(
110
+ raise Web3TypeError(
111
111
  f"Invalid abi-type: {abi_type}. Length of fixed sized "
112
112
  "arrays must be greater than 0."
113
113
  )
114
114
  if specified_length != len(value):
115
- raise TypeError(
115
+ raise Web3TypeError(
116
116
  "The following array length does not the length specified"
117
117
  f"by the abi-type, {abi_type}: {value}"
118
118
  )
@@ -138,14 +138,14 @@ def validate_abi_value(abi_type: TypeStr, value: Any) -> None:
138
138
  if is_0x_prefixed(value):
139
139
  return
140
140
  else:
141
- raise TypeError(
141
+ raise Web3TypeError(
142
142
  "ABI values of abi-type 'bytes' must be either"
143
143
  "a python3 'bytes' object or an '0x' prefixed string."
144
144
  )
145
145
  elif is_string_type(abi_type) and is_string(value):
146
146
  return
147
147
 
148
- raise TypeError(f"The following abi value is not a '{abi_type}': {value}")
148
+ raise Web3TypeError(f"The following abi value is not a '{abi_type}': {value}")
149
149
 
150
150
 
151
151
  def is_not_address_string(value: Any) -> bool:
@@ -173,7 +173,7 @@ def validate_address(value: Any) -> None:
173
173
  return
174
174
 
175
175
  if not isinstance(value, str):
176
- raise TypeError(f"Address {value} must be provided as a string")
176
+ raise Web3TypeError(f"Address {value} must be provided as a string")
177
177
  if not is_hex_address(value):
178
178
  raise InvalidAddress(
179
179
  "Address must be 20 bytes, as a hex string with a 0x prefix", value
@@ -204,7 +204,7 @@ def has_one_val(*args: Any, **kwargs: Any) -> bool:
204
204
 
205
205
  def assert_one_val(*args: Any, **kwargs: Any) -> None:
206
206
  if not has_one_val(*args, **kwargs):
207
- raise TypeError(
207
+ raise Web3TypeError(
208
208
  "Exactly one of the passed values can be specified. "
209
209
  f"Instead, values were: {args!r}, {kwargs!r}"
210
210
  )
web3/auto/gethdev.py CHANGED
@@ -1,13 +1,18 @@
1
1
  from web3 import (
2
+ AsyncIPCProvider,
3
+ AsyncWeb3,
2
4
  IPCProvider,
3
5
  Web3,
4
6
  )
5
7
  from web3.middleware import (
6
- geth_poa_middleware,
8
+ ExtraDataToPOAMiddleware,
7
9
  )
8
10
  from web3.providers.ipc import (
9
11
  get_dev_ipc_path,
10
12
  )
11
13
 
12
14
  w3 = Web3(IPCProvider(get_dev_ipc_path()))
13
- w3.middleware_onion.inject(geth_poa_middleware, layer=0)
15
+ w3.middleware_onion.inject(ExtraDataToPOAMiddleware, layer=0)
16
+
17
+ async_w3 = AsyncWeb3(AsyncIPCProvider(get_dev_ipc_path()))
18
+ async_w3.middleware_onion.inject(ExtraDataToPOAMiddleware, layer=0)
web3/beacon/__init__.py CHANGED
@@ -1,2 +1,7 @@
1
1
  from .async_beacon import AsyncBeacon
2
- from .main import Beacon
2
+ from .beacon import Beacon
3
+
4
+ __all__ = [
5
+ "AsyncBeacon",
6
+ "Beacon",
7
+ ]
@@ -8,9 +8,8 @@ from eth_typing import (
8
8
  HexStr,
9
9
  )
10
10
 
11
- from web3._utils.request import (
12
- async_get_response_from_get_request,
13
- async_json_make_get_request,
11
+ from web3._utils.http_session_manager import (
12
+ HTTPSessionManager,
14
13
  )
15
14
  from web3.beacon.api_endpoints import (
16
15
  GET_ATTESTATIONS,
@@ -63,10 +62,13 @@ class AsyncBeacon:
63
62
  ) -> None:
64
63
  self.base_url = base_url
65
64
  self.request_timeout = request_timeout
65
+ self._request_session_manager = HTTPSessionManager()
66
66
 
67
67
  async def _async_make_get_request(self, endpoint_uri: str) -> Dict[str, Any]:
68
68
  uri = URI(self.base_url + endpoint_uri)
69
- return await async_json_make_get_request(uri, timeout=self.request_timeout)
69
+ return await self._request_session_manager.async_json_make_get_request(
70
+ uri, timeout=self.request_timeout
71
+ )
70
72
 
71
73
  # [ BEACON endpoints ]
72
74
 
@@ -208,7 +210,9 @@ class AsyncBeacon:
208
210
 
209
211
  async def get_health(self) -> int:
210
212
  url = URI(self.base_url + GET_HEALTH)
211
- response = await async_get_response_from_get_request(url)
213
+ response = (
214
+ await self._request_session_manager.async_get_response_from_get_request(url)
215
+ )
212
216
  return response.status
213
217
 
214
218
  async def get_version(self) -> Dict[str, Any]:
@@ -8,9 +8,8 @@ from eth_typing import (
8
8
  HexStr,
9
9
  )
10
10
 
11
- from web3._utils.request import (
12
- get_response_from_get_request,
13
- json_make_get_request,
11
+ from web3._utils.http_session_manager import (
12
+ HTTPSessionManager,
14
13
  )
15
14
  from web3.beacon.api_endpoints import (
16
15
  GET_ATTESTATIONS,
@@ -61,10 +60,13 @@ class Beacon:
61
60
  ) -> None:
62
61
  self.base_url = base_url
63
62
  self.request_timeout = request_timeout
63
+ self._request_session_manager = HTTPSessionManager()
64
64
 
65
65
  def _make_get_request(self, endpoint_url: str) -> Dict[str, Any]:
66
66
  uri = URI(self.base_url + endpoint_url)
67
- return json_make_get_request(uri, timeout=self.request_timeout)
67
+ return self._request_session_manager.json_make_get_request(
68
+ uri, timeout=self.request_timeout
69
+ )
68
70
 
69
71
  # [ BEACON endpoints ]
70
72
 
@@ -196,7 +198,7 @@ class Beacon:
196
198
 
197
199
  def get_health(self) -> int:
198
200
  url = URI(self.base_url + GET_HEALTH)
199
- response = get_response_from_get_request(url)
201
+ response = self._request_session_manager.get_response_from_get_request(url)
200
202
  return response.status_code
201
203
 
202
204
  def get_version(self) -> Dict[str, Any]:
web3/contract/__init__.py CHANGED
@@ -7,3 +7,10 @@ from web3.contract.contract import (
7
7
  ContractCaller,
8
8
  ContractConstructor,
9
9
  )
10
+
11
+ __all__ = [
12
+ "AsyncContract",
13
+ "AsyncContractCaller",
14
+ "Contract",
15
+ "ContractConstructor",
16
+ ]
@@ -14,11 +14,16 @@ from typing import (
14
14
  )
15
15
 
16
16
  from eth_typing import (
17
+ ABI,
17
18
  ChecksumAddress,
18
19
  )
19
20
  from eth_utils import (
20
21
  combomethod,
21
22
  )
23
+ from eth_utils.abi import (
24
+ get_abi_input_names,
25
+ get_all_function_abis,
26
+ )
22
27
  from eth_utils.toolz import (
23
28
  partial,
24
29
  )
@@ -28,9 +33,12 @@ from hexbytes import (
28
33
 
29
34
  from web3._utils.abi import (
30
35
  fallback_func_abi_exists,
31
- filter_by_type,
32
36
  receive_func_abi_exists,
33
37
  )
38
+ from web3._utils.abi_element_identifiers import (
39
+ FallbackFn,
40
+ ReceiveFn,
41
+ )
34
42
  from web3._utils.async_transactions import (
35
43
  async_fill_transaction_defaults,
36
44
  )
@@ -39,7 +47,6 @@ from web3._utils.compat import (
39
47
  )
40
48
  from web3._utils.contracts import (
41
49
  async_parse_block_identifier,
42
- parse_block_identifier_no_extra_call,
43
50
  )
44
51
  from web3._utils.datatypes import (
45
52
  PropertyCheckingFactory,
@@ -51,10 +58,6 @@ from web3._utils.events import (
51
58
  from web3._utils.filters import (
52
59
  AsyncLogFilter,
53
60
  )
54
- from web3._utils.function_identifiers import (
55
- FallbackFn,
56
- ReceiveFn,
57
- )
58
61
  from web3._utils.normalizers import (
59
62
  normalize_abi,
60
63
  normalize_address_no_ens,
@@ -83,18 +86,17 @@ from web3.exceptions import (
83
86
  ABIFunctionNotFound,
84
87
  NoABIFound,
85
88
  NoABIFunctionsFound,
89
+ Web3AttributeError,
90
+ Web3TypeError,
86
91
  Web3ValidationError,
92
+ Web3ValueError,
87
93
  )
88
94
  from web3.types import (
89
- ABI,
90
95
  BlockIdentifier,
91
- CallOverride,
92
96
  EventData,
97
+ StateOverride,
93
98
  TxParams,
94
99
  )
95
- from web3.utils import (
96
- get_abi_input_names,
97
- )
98
100
 
99
101
  if TYPE_CHECKING:
100
102
  from ens import AsyncENS # noqa: F401
@@ -109,11 +111,12 @@ class AsyncContractEvent(BaseContractEvent):
109
111
  async def get_logs(
110
112
  self,
111
113
  argument_filters: Optional[Dict[str, Any]] = None,
112
- fromBlock: Optional[BlockIdentifier] = None,
113
- toBlock: Optional[BlockIdentifier] = None,
114
+ from_block: Optional[BlockIdentifier] = None,
115
+ to_block: Optional[BlockIdentifier] = None,
114
116
  block_hash: Optional[HexBytes] = None,
115
117
  ) -> Awaitable[Iterable[EventData]]:
116
- """Get events for this contract instance using eth_getLogs API.
118
+ """
119
+ Get events for this contract instance using eth_getLogs API.
117
120
 
118
121
  This is a stateless method, as opposed to createFilter.
119
122
  It can be safely called against nodes which do not provide
@@ -132,7 +135,7 @@ class AsyncContractEvent(BaseContractEvent):
132
135
  from = max(mycontract.web3.eth.block_number - 10, 1)
133
136
  to = mycontract.web3.eth.block_number
134
137
 
135
- events = mycontract.events.Transfer.getLogs(fromBlock=from, toBlock=to)
138
+ events = mycontract.events.Transfer.getLogs(from_block=from, to_block=to)
136
139
 
137
140
  for e in events:
138
141
  print(e["args"]["from"],
@@ -158,14 +161,14 @@ class AsyncContractEvent(BaseContractEvent):
158
161
  ...
159
162
  )
160
163
 
161
- See also: :func:`web3.middleware.filter.local_filter_middleware`.
164
+ See also: :func:`web3.middleware.filter.LocalFilterMiddleware`.
162
165
 
163
166
  :param argument_filters: Filter by argument values. Indexed arguments are
164
167
  filtered by the node while non-indexed arguments are filtered by the library.
165
- :param fromBlock: block number or "latest", defaults to "latest"
166
- :param toBlock: block number or "latest". Defaults to "latest"
168
+ :param from_block: block number or "latest", defaults to "latest"
169
+ :param to_block: block number or "latest". Defaults to "latest"
167
170
  :param block_hash: block hash. Cannot be set at the
168
- same time as fromBlock or toBlock
171
+ same time as ``from_block`` or ``to_block``
169
172
  :yield: Tuple of :class:`AttributeDict` instances
170
173
  """
171
174
  event_abi = self._get_event_abi()
@@ -180,7 +183,7 @@ class AsyncContractEvent(BaseContractEvent):
180
183
  )
181
184
 
182
185
  _filter_params = self._get_event_filter_params(
183
- event_abi, argument_filters, fromBlock, toBlock, block_hash
186
+ event_abi, argument_filters, from_block, to_block, block_hash
184
187
  )
185
188
  # call JSON-RPC API
186
189
  logs = await self.w3.eth.get_logs(_filter_params)
@@ -201,8 +204,8 @@ class AsyncContractEvent(BaseContractEvent):
201
204
  self,
202
205
  *, # PEP 3102
203
206
  argument_filters: Optional[Dict[str, Any]] = None,
204
- fromBlock: Optional[BlockIdentifier] = None,
205
- toBlock: BlockIdentifier = "latest",
207
+ from_block: Optional[BlockIdentifier] = None,
208
+ to_block: BlockIdentifier = "latest",
206
209
  address: Optional[ChecksumAddress] = None,
207
210
  topics: Optional[Sequence[Any]] = None,
208
211
  ) -> AsyncLogFilter:
@@ -212,8 +215,8 @@ class AsyncContractEvent(BaseContractEvent):
212
215
  filter_builder = AsyncEventFilterBuilder(self._get_event_abi(), self.w3.codec)
213
216
  self._set_up_filter_builder(
214
217
  argument_filters,
215
- fromBlock,
216
- toBlock,
218
+ from_block,
219
+ to_block,
217
220
  address,
218
221
  topics,
219
222
  filter_builder,
@@ -270,7 +273,7 @@ class AsyncContractFunction(BaseContractFunction):
270
273
  self,
271
274
  transaction: Optional[TxParams] = None,
272
275
  block_identifier: BlockIdentifier = None,
273
- state_override: Optional[CallOverride] = None,
276
+ state_override: Optional[StateOverride] = None,
274
277
  ccip_read_enabled: Optional[bool] = None,
275
278
  ) -> Any:
276
279
  """
@@ -308,7 +311,7 @@ class AsyncContractFunction(BaseContractFunction):
308
311
  self.w3,
309
312
  self.address,
310
313
  self._return_data_normalizers,
311
- self.function_identifier,
314
+ self.abi_element_identifier,
312
315
  call_transaction,
313
316
  block_id,
314
317
  self.contract_abi,
@@ -325,7 +328,7 @@ class AsyncContractFunction(BaseContractFunction):
325
328
  return await async_transact_with_contract_function(
326
329
  self.address,
327
330
  self.w3,
328
- self.function_identifier,
331
+ self.abi_element_identifier,
329
332
  setup_transaction,
330
333
  self.contract_abi,
331
334
  self.abi,
@@ -337,13 +340,13 @@ class AsyncContractFunction(BaseContractFunction):
337
340
  self,
338
341
  transaction: Optional[TxParams] = None,
339
342
  block_identifier: Optional[BlockIdentifier] = None,
340
- state_override: Optional[CallOverride] = None,
343
+ state_override: Optional[StateOverride] = None,
341
344
  ) -> int:
342
345
  setup_transaction = self._estimate_gas(transaction)
343
346
  return await async_estimate_gas_for_function(
344
347
  self.address,
345
348
  self.w3,
346
- self.function_identifier,
349
+ self.abi_element_identifier,
347
350
  setup_transaction,
348
351
  self.contract_abi,
349
352
  self.abi,
@@ -360,7 +363,7 @@ class AsyncContractFunction(BaseContractFunction):
360
363
  return await async_build_transaction_for_function(
361
364
  self.address,
362
365
  self.w3,
363
- self.function_identifier,
366
+ self.abi_element_identifier,
364
367
  built_transaction,
365
368
  self.contract_abi,
366
369
  self.abi,
@@ -380,7 +383,7 @@ class AsyncContractFunction(BaseContractFunction):
380
383
  w3=async_w3,
381
384
  contract_abi=abi,
382
385
  address=address,
383
- function_identifier=FallbackFn,
386
+ abi_element_identifier=FallbackFn,
384
387
  )()
385
388
  return cast(AsyncContractFunction, NonExistentFallbackFunction())
386
389
 
@@ -396,7 +399,7 @@ class AsyncContractFunction(BaseContractFunction):
396
399
  w3=async_w3,
397
400
  contract_abi=abi,
398
401
  address=address,
399
- function_identifier=ReceiveFn,
402
+ abi_element_identifier=ReceiveFn,
400
403
  )()
401
404
  return cast(AsyncContractFunction, NonExistentReceiveFunction())
402
405
 
@@ -441,12 +444,13 @@ class AsyncContract(BaseContract):
441
444
  events: AsyncContractEvents = None
442
445
 
443
446
  def __init__(self, address: Optional[ChecksumAddress] = None) -> None:
444
- """Create a new smart contract proxy object.
445
-
446
- :param address: Contract address as 0x hex string"""
447
+ """
448
+ Create a new smart contract proxy object.
447
449
 
450
+ :param address: Contract address as 0x hex string
451
+ """
448
452
  if self.w3 is None:
449
- raise AttributeError(
453
+ raise Web3AttributeError(
450
454
  "The `Contract` class has not been initialized. Please use the "
451
455
  "`web3.contract` interface to create your contract class."
452
456
  )
@@ -455,7 +459,7 @@ class AsyncContract(BaseContract):
455
459
  self.address = normalize_address_no_ens(address)
456
460
 
457
461
  if not self.address:
458
- raise TypeError(
462
+ raise Web3TypeError(
459
463
  "The address argument is required to instantiate a contract."
460
464
  )
461
465
  self.functions = AsyncContractFunctions(
@@ -517,14 +521,14 @@ class AsyncContract(BaseContract):
517
521
  return contract
518
522
 
519
523
  @classmethod
520
- def constructor(cls, *args: Any, **kwargs: Any) -> Self:
524
+ def constructor(cls, *args: Any, **kwargs: Any) -> "AsyncContractConstructor":
521
525
  """
522
526
  :param args: The contract constructor arguments as positional arguments
523
527
  :param kwargs: The contract constructor arguments as keyword arguments
524
528
  :return: a contract constructor object
525
529
  """
526
530
  if cls.bytecode is None:
527
- raise ValueError(
531
+ raise Web3ValueError(
528
532
  "Cannot call constructor on a contract that does not have "
529
533
  "'bytecode' associated with it"
530
534
  )
@@ -573,26 +577,23 @@ class AsyncContractCaller(BaseContractCaller):
573
577
  if transaction is None:
574
578
  transaction = {}
575
579
 
576
- self._functions = filter_by_type("function", self.abi)
580
+ self._functions = get_all_function_abis(self.abi)
581
+
577
582
  for func in self._functions:
578
583
  fn = AsyncContractFunction.factory(
579
584
  func["name"],
580
585
  w3=w3,
581
586
  contract_abi=self.abi,
582
587
  address=self.address,
583
- function_identifier=func["name"],
588
+ abi_element_identifier=func["name"],
584
589
  decode_tuples=decode_tuples,
585
590
  )
586
591
 
587
- # TODO: The no_extra_call method gets around the fact that we can't call
588
- # the full async method from within a class's __init__ method. We need
589
- # to see if there's a way to account for all desired elif cases.
590
- block_id = parse_block_identifier_no_extra_call(w3, block_identifier)
591
592
  caller_method = partial(
592
593
  self.call_function,
593
594
  fn,
594
595
  transaction=transaction,
595
- block_identifier=block_id,
596
+ block_identifier=block_identifier,
596
597
  ccip_read_enabled=ccip_read_enabled,
597
598
  )
598
599