web3 7.0.0b1__py3-none-any.whl → 7.7.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 (261) hide show
  1. ens/__init__.py +13 -2
  2. ens/_normalization.py +4 -4
  3. ens/async_ens.py +31 -21
  4. ens/base_ens.py +3 -1
  5. ens/contract_data.py +2 -2
  6. ens/ens.py +14 -11
  7. ens/exceptions.py +16 -29
  8. ens/specs/nf.json +1 -1
  9. ens/specs/normalization_spec.json +1 -1
  10. ens/utils.py +33 -41
  11. web3/__init__.py +23 -12
  12. web3/_utils/abi.py +162 -274
  13. web3/_utils/async_transactions.py +34 -20
  14. web3/_utils/batching.py +217 -0
  15. web3/_utils/blocks.py +6 -2
  16. web3/_utils/caching/__init__.py +12 -0
  17. web3/_utils/caching/caching_utils.py +433 -0
  18. web3/_utils/caching/request_caching_validation.py +287 -0
  19. web3/_utils/compat/__init__.py +2 -3
  20. web3/_utils/contract_sources/compile_contracts.py +1 -1
  21. web3/_utils/contract_sources/contract_data/ambiguous_function_contract.py +42 -0
  22. web3/_utils/contract_sources/contract_data/arrays_contract.py +3 -3
  23. web3/_utils/contract_sources/contract_data/bytes_contracts.py +5 -5
  24. web3/_utils/contract_sources/contract_data/constructor_contracts.py +7 -7
  25. web3/_utils/contract_sources/contract_data/contract_caller_tester.py +3 -3
  26. web3/_utils/contract_sources/contract_data/emitter_contract.py +3 -3
  27. web3/_utils/contract_sources/contract_data/event_contracts.py +50 -5
  28. web3/_utils/contract_sources/contract_data/extended_resolver.py +3 -3
  29. web3/_utils/contract_sources/contract_data/fallback_function_contract.py +3 -3
  30. web3/_utils/contract_sources/contract_data/function_name_tester_contract.py +3 -3
  31. web3/_utils/contract_sources/contract_data/math_contract.py +3 -3
  32. web3/_utils/contract_sources/contract_data/offchain_lookup.py +3 -3
  33. web3/_utils/contract_sources/contract_data/offchain_resolver.py +3 -3
  34. web3/_utils/contract_sources/contract_data/panic_errors_contract.py +3 -3
  35. web3/_utils/contract_sources/contract_data/payable_tester.py +3 -3
  36. web3/_utils/contract_sources/contract_data/receive_function_contracts.py +5 -5
  37. web3/_utils/contract_sources/contract_data/reflector_contracts.py +3 -3
  38. web3/_utils/contract_sources/contract_data/revert_contract.py +3 -3
  39. web3/_utils/contract_sources/contract_data/simple_resolver.py +3 -3
  40. web3/_utils/contract_sources/contract_data/storage_contract.py +3 -3
  41. web3/_utils/contract_sources/contract_data/string_contract.py +3 -3
  42. web3/_utils/contract_sources/contract_data/tuple_contracts.py +5 -5
  43. web3/_utils/contracts.py +172 -220
  44. web3/_utils/datatypes.py +5 -1
  45. web3/_utils/decorators.py +6 -1
  46. web3/_utils/empty.py +1 -1
  47. web3/_utils/encoding.py +16 -12
  48. web3/_utils/error_formatters_utils.py +5 -3
  49. web3/_utils/events.py +78 -72
  50. web3/_utils/fee_utils.py +1 -3
  51. web3/_utils/filters.py +24 -22
  52. web3/_utils/formatters.py +2 -2
  53. web3/_utils/http.py +8 -2
  54. web3/_utils/http_session_manager.py +314 -0
  55. web3/_utils/math.py +14 -15
  56. web3/_utils/method_formatters.py +161 -34
  57. web3/_utils/module.py +2 -1
  58. web3/_utils/module_testing/__init__.py +3 -2
  59. web3/_utils/module_testing/eth_module.py +736 -583
  60. web3/_utils/module_testing/go_ethereum_debug_module.py +128 -0
  61. web3/_utils/module_testing/module_testing_utils.py +81 -24
  62. web3/_utils/module_testing/persistent_connection_provider.py +702 -220
  63. web3/_utils/module_testing/utils.py +114 -33
  64. web3/_utils/module_testing/web3_module.py +438 -17
  65. web3/_utils/normalizers.py +13 -11
  66. web3/_utils/rpc_abi.py +10 -22
  67. web3/_utils/threads.py +8 -7
  68. web3/_utils/transactions.py +32 -25
  69. web3/_utils/type_conversion.py +5 -1
  70. web3/_utils/validation.py +20 -17
  71. web3/beacon/__init__.py +5 -0
  72. web3/beacon/api_endpoints.py +3 -0
  73. web3/beacon/async_beacon.py +29 -6
  74. web3/beacon/beacon.py +24 -6
  75. web3/contract/__init__.py +7 -0
  76. web3/contract/async_contract.py +285 -82
  77. web3/contract/base_contract.py +556 -258
  78. web3/contract/contract.py +295 -84
  79. web3/contract/utils.py +251 -55
  80. web3/datastructures.py +56 -41
  81. web3/eth/__init__.py +7 -0
  82. web3/eth/async_eth.py +89 -69
  83. web3/eth/base_eth.py +7 -3
  84. web3/eth/eth.py +43 -66
  85. web3/exceptions.py +158 -83
  86. web3/gas_strategies/time_based.py +8 -6
  87. web3/geth.py +53 -184
  88. web3/main.py +77 -43
  89. web3/manager.py +368 -101
  90. web3/method.py +43 -15
  91. web3/middleware/__init__.py +26 -8
  92. web3/middleware/attrdict.py +12 -22
  93. web3/middleware/base.py +55 -2
  94. web3/middleware/filter.py +45 -23
  95. web3/middleware/formatting.py +6 -3
  96. web3/middleware/names.py +4 -1
  97. web3/middleware/signing.py +15 -6
  98. web3/middleware/stalecheck.py +2 -1
  99. web3/module.py +62 -26
  100. web3/providers/__init__.py +21 -0
  101. web3/providers/async_base.py +93 -38
  102. web3/providers/base.py +85 -40
  103. web3/providers/eth_tester/__init__.py +5 -0
  104. web3/providers/eth_tester/defaults.py +2 -55
  105. web3/providers/eth_tester/main.py +57 -35
  106. web3/providers/eth_tester/middleware.py +16 -17
  107. web3/providers/ipc.py +42 -18
  108. web3/providers/legacy_websocket.py +27 -2
  109. web3/providers/persistent/__init__.py +7 -0
  110. web3/providers/persistent/async_ipc.py +61 -121
  111. web3/providers/persistent/persistent.py +324 -17
  112. web3/providers/persistent/persistent_connection.py +54 -5
  113. web3/providers/persistent/request_processor.py +136 -56
  114. web3/providers/persistent/subscription_container.py +56 -0
  115. web3/providers/persistent/subscription_manager.py +233 -0
  116. web3/providers/persistent/websocket.py +29 -92
  117. web3/providers/rpc/__init__.py +5 -0
  118. web3/providers/rpc/async_rpc.py +73 -18
  119. web3/providers/rpc/rpc.py +73 -30
  120. web3/providers/rpc/utils.py +1 -13
  121. web3/scripts/install_pre_releases.py +33 -0
  122. web3/scripts/parse_pygeth_version.py +16 -0
  123. web3/testing.py +4 -4
  124. web3/tracing.py +9 -5
  125. web3/types.py +141 -74
  126. web3/utils/__init__.py +64 -5
  127. web3/utils/abi.py +790 -10
  128. web3/utils/address.py +8 -0
  129. web3/utils/async_exception_handling.py +20 -11
  130. web3/utils/caching.py +34 -4
  131. web3/utils/exception_handling.py +9 -12
  132. web3/utils/subscriptions.py +285 -0
  133. {web3-7.0.0b1.dist-info → web3-7.7.0.dist-info}/LICENSE +1 -1
  134. web3-7.7.0.dist-info/METADATA +130 -0
  135. web3-7.7.0.dist-info/RECORD +171 -0
  136. {web3-7.0.0b1.dist-info → web3-7.7.0.dist-info}/WHEEL +1 -1
  137. {web3-7.0.0b1.dist-info → web3-7.7.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/caching.py +0 -155
  242. web3/_utils/contract_sources/contract_data/address_reflector.py +0 -29
  243. web3/_utils/module_testing/go_ethereum_personal_module.py +0 -300
  244. web3/_utils/request.py +0 -265
  245. web3/pm.py +0 -602
  246. web3/tools/__init__.py +0 -4
  247. web3/tools/benchmark/__init__.py +0 -0
  248. web3/tools/benchmark/main.py +0 -185
  249. web3/tools/benchmark/node.py +0 -126
  250. web3/tools/benchmark/reporting.py +0 -39
  251. web3/tools/benchmark/utils.py +0 -69
  252. web3/tools/pytest_ethereum/__init__.py +0 -0
  253. web3/tools/pytest_ethereum/_utils.py +0 -145
  254. web3/tools/pytest_ethereum/deployer.py +0 -48
  255. web3/tools/pytest_ethereum/exceptions.py +0 -22
  256. web3/tools/pytest_ethereum/linker.py +0 -128
  257. web3/tools/pytest_ethereum/plugins.py +0 -33
  258. web3-7.0.0b1.dist-info/METADATA +0 -114
  259. web3-7.0.0b1.dist-info/RECORD +0 -280
  260. web3-7.0.0b1.dist-info/entry_points.txt +0 -2
  261. /web3/_utils/{function_identifiers.py → abi_element_identifiers.py} +0 -0
@@ -1,80 +0,0 @@
1
- import re
2
- from typing import (
3
- Any,
4
- Dict,
5
- )
6
-
7
- from eth_utils import (
8
- is_text,
9
- )
10
-
11
- from ethpm._utils.ipfs import (
12
- is_ipfs_uri,
13
- )
14
- from ethpm.constants import (
15
- PACKAGE_NAME_REGEX,
16
- )
17
- from ethpm.exceptions import (
18
- EthPMValidationError,
19
- InsufficientAssetsError,
20
- )
21
-
22
-
23
- def validate_minimal_contract_factory_data(contract_data: Dict[str, str]) -> None:
24
- """
25
- Validate that contract data in a package contains at least an "abi" and
26
- "deploymentBytecode" necessary to generate a deployable contract factory.
27
- """
28
- if not all(key in contract_data.keys() for key in ("abi", "deploymentBytecode")):
29
- raise InsufficientAssetsError(
30
- "Minimum required contract data to generate a deployable "
31
- "contract factory (abi & deploymentBytecode) not found."
32
- )
33
-
34
-
35
- def validate_package_version(version: Any) -> None:
36
- """
37
- Validates that a package version is of text type.
38
- """
39
- if not is_text(version):
40
- raise EthPMValidationError(
41
- f"Expected a version of text type, instead received {type(version)}."
42
- )
43
-
44
-
45
- def validate_package_name(pkg_name: str) -> None:
46
- """
47
- Raise an exception if the value is not a valid package name
48
- as defined in the EthPM-Spec.
49
- """
50
- if not bool(re.match(PACKAGE_NAME_REGEX, pkg_name)):
51
- raise EthPMValidationError(f"{pkg_name} is not a valid package name.")
52
-
53
-
54
- def validate_manifest_version(version: str) -> None:
55
- """
56
- Raise an exception if the version is not "ethpm/3".
57
- """
58
- if not version == "ethpm/3":
59
- raise EthPMValidationError(
60
- f"Py-EthPM does not support the provided specification version: {version}"
61
- )
62
-
63
-
64
- def validate_build_dependency(key: str, uri: str) -> None:
65
- """
66
- Raise an exception if the key in dependencies is not a valid package name,
67
- or if the value is not a valid IPFS URI.
68
- """
69
- validate_package_name(key)
70
- # validate is supported content-addressed uri
71
- if not is_ipfs_uri(uri):
72
- raise EthPMValidationError(f"URI: {uri} is not a valid IPFS URI.")
73
-
74
-
75
- CONTRACT_NAME_REGEX = re.compile("^[a-zA-Z][-a-zA-Z0-9_]{0,255}$")
76
-
77
-
78
- def validate_contract_name(name: str) -> None:
79
- if not CONTRACT_NAME_REGEX.match(name):
80
- raise EthPMValidationError(f"Contract name: {name} is not valid.")
ethpm/validation/uri.py DELETED
@@ -1,163 +0,0 @@
1
- import hashlib
2
- from typing import (
3
- TYPE_CHECKING,
4
- List,
5
- )
6
- from urllib import (
7
- parse,
8
- )
9
-
10
- from eth_utils import (
11
- is_checksum_address,
12
- to_bytes,
13
- to_int,
14
- to_text,
15
- )
16
-
17
- from ethpm._utils.chains import (
18
- is_supported_chain_id,
19
- )
20
- from ethpm._utils.ipfs import (
21
- is_ipfs_uri,
22
- )
23
- from ethpm._utils.registry import (
24
- is_ens_domain,
25
- )
26
- from ethpm.constants import (
27
- REGISTRY_URI_SCHEMES,
28
- )
29
- from ethpm.exceptions import (
30
- EthPMValidationError,
31
- )
32
- from ethpm.validation.misc import (
33
- validate_escaped_string,
34
- )
35
- from ethpm.validation.package import (
36
- validate_package_name,
37
- )
38
-
39
- if TYPE_CHECKING:
40
- from web3 import Web3 # noqa: F401
41
-
42
-
43
- def validate_ipfs_uri(uri: str) -> None:
44
- """
45
- Raise an exception if the provided URI is not a valid IPFS URI.
46
- """
47
- if not is_ipfs_uri(uri):
48
- raise EthPMValidationError(f"URI: {uri} is not a valid IPFS URI.")
49
-
50
-
51
- def validate_registry_uri(uri: str) -> None:
52
- """
53
- Raise an exception if the URI does not conform to the registry URI scheme.
54
- """
55
- parsed = parse.urlparse(uri)
56
- scheme, authority, pkg_path = (
57
- parsed.scheme,
58
- parsed.netloc,
59
- parsed.path,
60
- )
61
- pkg_id = pkg_path.strip("/")
62
-
63
- if "@" in pkg_id:
64
- if len(pkg_id.split("@")) != 2:
65
- raise EthPMValidationError("Registry URI: {pkg_id} is not properly escaped")
66
- pkg_name, pkg_version = pkg_id.split("@")
67
- else:
68
- pkg_name, pkg_version = (pkg_id, None)
69
-
70
- validate_registry_uri_scheme(scheme)
71
- validate_registry_uri_authority(authority)
72
- if pkg_name:
73
- validate_package_name(pkg_name)
74
- if not pkg_name and pkg_version:
75
- raise EthPMValidationError(
76
- "Registry URIs cannot provide a version without a package name."
77
- )
78
- if pkg_version:
79
- validate_escaped_string(pkg_version)
80
-
81
-
82
- def validate_registry_uri_authority(auth: str) -> None:
83
- """
84
- Raise an exception if the authority is not a valid ENS domain
85
- or a valid checksummed contract address.
86
- """
87
- if ":" in auth:
88
- if len(auth.split(":")) != 2:
89
- raise EthPMValidationError(
90
- f"{auth} is not a valid registry URI authority. "
91
- "Please try again with a valid registry URI."
92
- )
93
- address, chain_id = auth.split(":")
94
- else:
95
- address, chain_id = auth, "1"
96
-
97
- if is_ens_domain(address) is False and not is_checksum_address(address):
98
- raise EthPMValidationError(
99
- f"{address} is not a valid registry address. "
100
- "Please try again with a valid registry URI."
101
- )
102
-
103
- if not is_supported_chain_id(to_int(text=chain_id)):
104
- raise EthPMValidationError(
105
- f"Chain ID: {chain_id} is not supported. Supported chain ids include: "
106
- "1 (mainnet), 5 (goerli), and 11155111 (sepolia)."
107
- "Please try again with a valid registry URI."
108
- )
109
-
110
-
111
- def validate_registry_uri_scheme(scheme: str) -> None:
112
- """
113
- Raise an exception if the scheme is not a valid registry URI scheme:
114
- - 'erc1319'
115
- - 'ethpm'
116
- """
117
- if scheme not in REGISTRY_URI_SCHEMES:
118
- raise EthPMValidationError(
119
- f"{scheme} is not a valid registry URI scheme. "
120
- f"Valid schemes include: {REGISTRY_URI_SCHEMES}"
121
- )
122
-
123
-
124
- def validate_single_matching_uri(all_blockchain_uris: List[str], w3: "Web3") -> str:
125
- """
126
- Return a single block URI after validating that it is the *only* URI in
127
- all_blockchain_uris that matches the w3 instance.
128
- """
129
- from ethpm.uri import (
130
- check_if_chain_matches_chain_uri,
131
- )
132
-
133
- matching_uris = [
134
- uri for uri in all_blockchain_uris if check_if_chain_matches_chain_uri(w3, uri)
135
- ]
136
-
137
- if not matching_uris:
138
- raise EthPMValidationError("Package has no matching URIs on chain.")
139
- elif len(matching_uris) != 1:
140
- raise EthPMValidationError(
141
- f"Package has too many ({len(matching_uris)}) "
142
- "matching URIs: {matching_uris}."
143
- )
144
- return matching_uris[0]
145
-
146
-
147
- def validate_blob_uri_contents(contents: bytes, blob_uri: str) -> None:
148
- """
149
- Raises an exception if the sha1 hash of the contents does not match the
150
- hash found in the blob_uri. Formula for how git calculates the hash
151
- found here: http://alblue.bandlem.com/2011/08/git-tip-of-week-objects.html
152
- """
153
- blob_path = parse.urlparse(blob_uri).path
154
- blob_hash = blob_path.split("/")[-1]
155
- contents_str = to_text(contents)
156
- content_length = len(contents_str)
157
- hashable_contents = "blob " + str(content_length) + "\0" + contents_str
158
- hash_object = hashlib.sha1(to_bytes(text=hashable_contents))
159
- if hash_object.hexdigest() != blob_hash:
160
- raise EthPMValidationError(
161
- f"Hash of contents fetched from {blob_uri} do not "
162
- f"match its hash: {blob_hash}."
163
- )
web3/_utils/caching.py DELETED
@@ -1,155 +0,0 @@
1
- import collections
2
- import hashlib
3
- import threading
4
- from typing import (
5
- TYPE_CHECKING,
6
- Any,
7
- Callable,
8
- Coroutine,
9
- List,
10
- Tuple,
11
- TypeVar,
12
- Union,
13
- )
14
-
15
- from eth_utils import (
16
- is_boolean,
17
- is_bytes,
18
- is_dict,
19
- is_list_like,
20
- is_null,
21
- is_number,
22
- is_text,
23
- to_bytes,
24
- )
25
-
26
- if TYPE_CHECKING:
27
- from web3.providers import ( # noqa: F401
28
- AsyncBaseProvider,
29
- BaseProvider,
30
- )
31
- from web3.types import ( # noqa: F401
32
- AsyncMakeRequestFn,
33
- MakeRequestFn,
34
- RPCEndpoint,
35
- RPCResponse,
36
- )
37
-
38
-
39
- SYNC_PROVIDER_TYPE = TypeVar("SYNC_PROVIDER_TYPE", bound="BaseProvider")
40
- ASYNC_PROVIDER_TYPE = TypeVar("ASYNC_PROVIDER_TYPE", bound="AsyncBaseProvider")
41
-
42
-
43
- def generate_cache_key(value: Any) -> str:
44
- """
45
- Generates a cache key for the *args and **kwargs
46
- """
47
- if is_bytes(value):
48
- return hashlib.md5(value).hexdigest()
49
- elif is_text(value):
50
- return generate_cache_key(to_bytes(text=value))
51
- elif is_boolean(value) or is_null(value) or is_number(value):
52
- return generate_cache_key(repr(value))
53
- elif is_dict(value):
54
- return generate_cache_key(((key, value[key]) for key in sorted(value.keys())))
55
- elif is_list_like(value) or isinstance(value, collections.abc.Generator):
56
- return generate_cache_key("".join((generate_cache_key(item) for item in value)))
57
- else:
58
- raise TypeError(
59
- f"Cannot generate cache key for value {value} of type {type(value)}"
60
- )
61
-
62
-
63
- class RequestInformation:
64
- def __init__(
65
- self,
66
- method: "RPCEndpoint",
67
- params: Any,
68
- response_formatters: Tuple[Callable[..., Any], ...],
69
- subscription_id: str = None,
70
- ):
71
- self.method = method
72
- self.params = params
73
- self.response_formatters = response_formatters
74
- self.subscription_id = subscription_id
75
- self.middleware_response_processors: List[Callable[..., Any]] = []
76
-
77
-
78
- def is_cacheable_request(
79
- provider: Union[ASYNC_PROVIDER_TYPE, SYNC_PROVIDER_TYPE], method: "RPCEndpoint"
80
- ) -> bool:
81
- if provider.cache_allowed_requests and method in provider.cacheable_requests:
82
- return True
83
- return False
84
-
85
-
86
- # -- request caching decorators -- #
87
-
88
-
89
- def _should_cache_response(response: "RPCResponse") -> bool:
90
- return (
91
- "error" not in response
92
- and "result" in response
93
- and not is_null(response["result"])
94
- )
95
-
96
-
97
- def handle_request_caching(
98
- func: Callable[[SYNC_PROVIDER_TYPE, "RPCEndpoint", Any], "RPCResponse"]
99
- ) -> Callable[..., "RPCResponse"]:
100
- def wrapper(
101
- provider: SYNC_PROVIDER_TYPE, method: "RPCEndpoint", params: Any
102
- ) -> "RPCResponse":
103
- if is_cacheable_request(provider, method):
104
- request_cache = provider._request_cache
105
- cache_key = generate_cache_key(
106
- f"{threading.get_ident()}:{(method, params)}"
107
- )
108
- cache_result = request_cache.get_cache_entry(cache_key)
109
- if cache_result is not None:
110
- return cache_result
111
- else:
112
- response = func(provider, method, params)
113
- if _should_cache_response(response):
114
- with provider._request_cache_lock:
115
- request_cache.cache(cache_key, response)
116
- return response
117
- else:
118
- return func(provider, method, params)
119
-
120
- # save a reference to the decorator on the wrapped function
121
- wrapper._decorator = handle_request_caching # type: ignore
122
- return wrapper
123
-
124
-
125
- # -- async -- #
126
-
127
-
128
- def async_handle_request_caching(
129
- func: Callable[
130
- [ASYNC_PROVIDER_TYPE, "RPCEndpoint", Any], Coroutine[Any, Any, "RPCResponse"]
131
- ],
132
- ) -> Callable[..., Coroutine[Any, Any, "RPCResponse"]]:
133
- async def wrapper(
134
- provider: ASYNC_PROVIDER_TYPE, method: "RPCEndpoint", params: Any
135
- ) -> "RPCResponse":
136
- if is_cacheable_request(provider, method):
137
- request_cache = provider._request_cache
138
- cache_key = generate_cache_key(
139
- f"{threading.get_ident()}:{(method, params)}"
140
- )
141
- cache_result = request_cache.get_cache_entry(cache_key)
142
- if cache_result is not None:
143
- return cache_result
144
- else:
145
- response = await func(provider, method, params)
146
- if _should_cache_response(response):
147
- async with provider._request_cache_lock:
148
- request_cache.cache(cache_key, response)
149
- return response
150
- else:
151
- return await func(provider, method, params)
152
-
153
- # save a reference to the decorator on the wrapped function
154
- wrapper._decorator = async_handle_request_caching # type: ignore
155
- return wrapper
@@ -1,29 +0,0 @@
1
- """
2
- Generated by `compile_contract_sources.py` script.
3
- Compiled with Solidity v0.8.17.
4
- """
5
-
6
- # source: web3/_utils/contract_sources/AddressReflector.sol:AddressReflector
7
- ADDRESS_REFLECTOR_BYTECODE = "0x608060405234801561001057600080fd5b50610430806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80630b816c161461003b578063c04d11fc1461006b575b600080fd5b61005560048036038101906100509190610121565b61009b565b604051610062919061015d565b60405180910390f35b610085600480360381019061008091906102d1565b6100a5565b60405161009291906103d8565b60405180910390f35b6000819050919050565b6060819050919050565b6000604051905090565b600080fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006100ee826100c3565b9050919050565b6100fe816100e3565b811461010957600080fd5b50565b60008135905061011b816100f5565b92915050565b600060208284031215610137576101366100b9565b5b60006101458482850161010c565b91505092915050565b610157816100e3565b82525050565b6000602082019050610172600083018461014e565b92915050565b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6101c68261017d565b810181811067ffffffffffffffff821117156101e5576101e461018e565b5b80604052505050565b60006101f86100af565b905061020482826101bd565b919050565b600067ffffffffffffffff8211156102245761022361018e565b5b602082029050602081019050919050565b600080fd5b600061024d61024884610209565b6101ee565b905080838252602082019050602084028301858111156102705761026f610235565b5b835b818110156102995780610285888261010c565b845260208401935050602081019050610272565b5050509392505050565b600082601f8301126102b8576102b7610178565b5b81356102c884826020860161023a565b91505092915050565b6000602082840312156102e7576102e66100b9565b5b600082013567ffffffffffffffff811115610305576103046100be565b5b610311848285016102a3565b91505092915050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b61034f816100e3565b82525050565b60006103618383610346565b60208301905092915050565b6000602082019050919050565b60006103858261031a565b61038f8185610325565b935061039a83610336565b8060005b838110156103cb5781516103b28882610355565b97506103bd8361036d565b92505060018101905061039e565b5085935050505092915050565b600060208201905081810360008301526103f2818461037a565b90509291505056fea264697066735822122035083763a0f4c4f5a71055f0da2f3d4f78e64159a8f3bc215c430daec7ac5e2064736f6c63430008110033" # noqa: E501
8
- ADDRESS_REFLECTOR_RUNTIME = "0x608060405234801561001057600080fd5b50600436106100365760003560e01c80630b816c161461003b578063c04d11fc1461006b575b600080fd5b61005560048036038101906100509190610121565b61009b565b604051610062919061015d565b60405180910390f35b610085600480360381019061008091906102d1565b6100a5565b60405161009291906103d8565b60405180910390f35b6000819050919050565b6060819050919050565b6000604051905090565b600080fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006100ee826100c3565b9050919050565b6100fe816100e3565b811461010957600080fd5b50565b60008135905061011b816100f5565b92915050565b600060208284031215610137576101366100b9565b5b60006101458482850161010c565b91505092915050565b610157816100e3565b82525050565b6000602082019050610172600083018461014e565b92915050565b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6101c68261017d565b810181811067ffffffffffffffff821117156101e5576101e461018e565b5b80604052505050565b60006101f86100af565b905061020482826101bd565b919050565b600067ffffffffffffffff8211156102245761022361018e565b5b602082029050602081019050919050565b600080fd5b600061024d61024884610209565b6101ee565b905080838252602082019050602084028301858111156102705761026f610235565b5b835b818110156102995780610285888261010c565b845260208401935050602081019050610272565b5050509392505050565b600082601f8301126102b8576102b7610178565b5b81356102c884826020860161023a565b91505092915050565b6000602082840312156102e7576102e66100b9565b5b600082013567ffffffffffffffff811115610305576103046100be565b5b610311848285016102a3565b91505092915050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b61034f816100e3565b82525050565b60006103618383610346565b60208301905092915050565b6000602082019050919050565b60006103858261031a565b61038f8185610325565b935061039a83610336565b8060005b838110156103cb5781516103b28882610355565b97506103bd8361036d565b92505060018101905061039e565b5085935050505092915050565b600060208201905081810360008301526103f2818461037a565b90509291505056fea264697066735822122035083763a0f4c4f5a71055f0da2f3d4f78e64159a8f3bc215c430daec7ac5e2064736f6c63430008110033" # noqa: E501
9
- ADDRESS_REFLECTOR_ABI = [
10
- {
11
- "inputs": [{"internalType": "address", "name": "arg", "type": "address"}],
12
- "name": "reflect",
13
- "outputs": [{"internalType": "address", "name": "", "type": "address"}],
14
- "stateMutability": "pure",
15
- "type": "function",
16
- },
17
- {
18
- "inputs": [{"internalType": "address[]", "name": "arg", "type": "address[]"}],
19
- "name": "reflect",
20
- "outputs": [{"internalType": "address[]", "name": "", "type": "address[]"}],
21
- "stateMutability": "pure",
22
- "type": "function",
23
- },
24
- ]
25
- ADDRESS_REFLECTOR_DATA = {
26
- "bytecode": ADDRESS_REFLECTOR_BYTECODE,
27
- "bytecode_runtime": ADDRESS_REFLECTOR_RUNTIME,
28
- "abi": ADDRESS_REFLECTOR_ABI,
29
- }