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
ethpm/_utils/chains.py DELETED
@@ -1,119 +0,0 @@
1
- import re
2
- from typing import (
3
- TYPE_CHECKING,
4
- Any,
5
- Tuple,
6
- )
7
- from urllib import (
8
- parse,
9
- )
10
-
11
- from eth_typing import (
12
- URI,
13
- BlockNumber,
14
- HexStr,
15
- )
16
- from eth_utils import (
17
- add_0x_prefix,
18
- is_integer,
19
- remove_0x_prefix,
20
- )
21
- from hexbytes import (
22
- HexBytes,
23
- )
24
-
25
- from ethpm.constants import (
26
- SUPPORTED_CHAIN_IDS,
27
- )
28
-
29
- if TYPE_CHECKING:
30
- from web3 import Web3 # noqa: F401
31
-
32
-
33
- def get_genesis_block_hash(w3: "Web3") -> HexBytes:
34
- return w3.eth.get_block(BlockNumber(0))["hash"]
35
-
36
-
37
- BLOCK = "block"
38
-
39
- BIP122_URL_REGEX = (
40
- "^"
41
- "blockchain://"
42
- "(?P<chain_id>[a-zA-Z0-9]{64})"
43
- "/"
44
- "(?P<resource_type>block|transaction)"
45
- "/"
46
- "(?P<resource_hash>[a-zA-Z0-9]{64})"
47
- "$"
48
- )
49
-
50
-
51
- def is_BIP122_uri(value: URI) -> bool:
52
- return bool(re.match(BIP122_URL_REGEX, value))
53
-
54
-
55
- def parse_BIP122_uri(blockchain_uri: URI) -> Tuple[HexStr, str, HexStr]:
56
- match = re.match(BIP122_URL_REGEX, blockchain_uri)
57
- if match is None:
58
- raise ValueError(f"Invalid URI format: '{blockchain_uri}'")
59
- chain_id, resource_type, resource_hash = match.groups()
60
- return (
61
- add_0x_prefix(HexStr(chain_id)),
62
- resource_type,
63
- add_0x_prefix(HexStr(resource_hash)),
64
- )
65
-
66
-
67
- def is_BIP122_block_uri(value: URI) -> bool:
68
- if not is_BIP122_uri(value):
69
- return False
70
- _, resource_type, _ = parse_BIP122_uri(value)
71
- return resource_type == BLOCK
72
-
73
-
74
- BLOCK_OR_TRANSACTION_HASH_REGEX = "^(?:0x)?[a-zA-Z0-9]{64}$"
75
-
76
-
77
- def is_block_or_transaction_hash(value: str) -> bool:
78
- return bool(re.match(BLOCK_OR_TRANSACTION_HASH_REGEX, value))
79
-
80
-
81
- def create_BIP122_uri(
82
- chain_id: HexStr, resource_type: str, resource_identifier: HexStr
83
- ) -> URI:
84
- """
85
- See: https://github.com/bitcoin/bips/blob/master/bip-0122.mediawiki
86
- """
87
- if resource_type != BLOCK:
88
- raise ValueError("Invalid resource_type. Must be one of 'block'")
89
- elif not is_block_or_transaction_hash(resource_identifier):
90
- raise ValueError(
91
- "Invalid resource_identifier. Must be a hex encoded 32 byte value"
92
- )
93
- elif not is_block_or_transaction_hash(chain_id):
94
- raise ValueError("Invalid chain_id. Must be a hex encoded 32 byte value")
95
-
96
- return URI(
97
- parse.urlunsplit(
98
- [
99
- "blockchain",
100
- remove_0x_prefix(chain_id),
101
- f"{resource_type}/{remove_0x_prefix(resource_identifier)}",
102
- "",
103
- "",
104
- ]
105
- )
106
- )
107
-
108
-
109
- def create_block_uri(chain_id: HexStr, block_identifier: HexStr) -> URI:
110
- return create_BIP122_uri(chain_id, "block", remove_0x_prefix(block_identifier))
111
-
112
-
113
- def is_supported_chain_id(chain_id: Any) -> bool:
114
- if not is_integer(chain_id):
115
- return False
116
-
117
- if chain_id not in SUPPORTED_CHAIN_IDS.keys():
118
- return False
119
- return True
ethpm/_utils/contract.py DELETED
@@ -1,35 +0,0 @@
1
- from typing import (
2
- Any,
3
- Dict,
4
- Generator,
5
- Tuple,
6
- )
7
-
8
- from eth_utils import (
9
- to_dict,
10
- )
11
-
12
-
13
- @to_dict
14
- def generate_contract_factory_kwargs(
15
- contract_data: Dict[str, Any]
16
- ) -> Generator[Tuple[str, Any], None, None]:
17
- """
18
- Build a dictionary of kwargs to be passed into contract factory.
19
- """
20
- if "abi" in contract_data:
21
- yield "abi", contract_data["abi"]
22
-
23
- if "deploymentBytecode" in contract_data:
24
- yield "bytecode", contract_data["deploymentBytecode"]["bytecode"]
25
- if "linkReferences" in contract_data["deploymentBytecode"]:
26
- yield "unlinked_references", tuple(
27
- contract_data["deploymentBytecode"]["linkReferences"]
28
- )
29
-
30
- if "runtimeBytecode" in contract_data:
31
- yield "bytecode_runtime", contract_data["runtimeBytecode"]["bytecode"]
32
- if "linkReferences" in contract_data["runtimeBytecode"]:
33
- yield "linked_references", tuple(
34
- contract_data["runtimeBytecode"]["linkReferences"]
35
- )
@@ -1,145 +0,0 @@
1
- from typing import (
2
- TYPE_CHECKING,
3
- Any,
4
- Dict,
5
- Generator,
6
- List,
7
- Tuple,
8
- )
9
-
10
- from eth_utils import (
11
- is_same_address,
12
- to_bytes,
13
- to_tuple,
14
- )
15
- from eth_utils.toolz import (
16
- get_in,
17
- )
18
- from hexbytes import (
19
- HexBytes,
20
- )
21
-
22
- from ethpm.exceptions import (
23
- BytecodeLinkingError,
24
- EthPMValidationError,
25
- )
26
-
27
- if TYPE_CHECKING:
28
- from web3 import Web3 # noqa: F401
29
-
30
-
31
- def get_linked_deployments(deployments: Dict[str, Any]) -> Dict[str, Any]:
32
- """
33
- Returns all deployments found in a chain URI's deployment data that
34
- contain link dependencies.
35
- """
36
- linked_deployments = {
37
- dep: data
38
- for dep, data in deployments.items()
39
- if get_in(("runtimeBytecode", "linkDependencies"), data)
40
- }
41
- for deployment, data in linked_deployments.items():
42
- if any(
43
- link_dep["value"] == deployment
44
- for link_dep in data["runtimeBytecode"]["linkDependencies"]
45
- ):
46
- raise BytecodeLinkingError(
47
- f"Link dependency found in {deployment} deployment that references its "
48
- "own contract instance, which is disallowed"
49
- )
50
- return linked_deployments
51
-
52
-
53
- def validate_linked_references(
54
- link_deps: Tuple[Tuple[int, bytes], ...], bytecode: HexBytes
55
- ) -> None:
56
- """
57
- Validates that normalized linked_references (offset, expected_bytes)
58
- match the corresponding bytecode.
59
- """
60
- offsets, values = zip(*link_deps)
61
- for idx, offset in enumerate(offsets):
62
- value = values[idx]
63
- # https://github.com/python/mypy/issues/4975
64
- offset_value = int(offset)
65
- dep_length = len(value)
66
- end_of_bytes = offset_value + dep_length
67
- # Ignore b/c whitespace around ':' conflict b/w black & flake8
68
- actual_bytes = bytecode[offset_value:end_of_bytes] # noqa: E203
69
- if actual_bytes != values[idx]:
70
- raise EthPMValidationError(
71
- "Error validating linked reference. "
72
- f"Offset: {offset} "
73
- f"Value: {values[idx]} "
74
- f"Bytecode: {bytecode!r} ."
75
- )
76
-
77
-
78
- @to_tuple
79
- def normalize_linked_references(
80
- data: List[Dict[str, Any]]
81
- ) -> Generator[Tuple[int, str, str], None, None]:
82
- """
83
- Return a tuple of information representing all insertions of a linked reference.
84
- (offset, type, value)
85
- """
86
- for deployment in data:
87
- for offset in deployment["offsets"]:
88
- yield offset, deployment["type"], deployment["value"]
89
-
90
-
91
- def validate_deployments_tx_receipt(
92
- deployments: Dict[str, Any], w3: "Web3", allow_missing_data: bool = False
93
- ) -> None:
94
- """
95
- Validate that address and block hash found in deployment data match
96
- what is found on-chain. :allow_missing_data: by default, enforces
97
- validation of address and blockHash.
98
- """
99
- # todo: provide hook to lazily look up tx receipt via binary search if missing data
100
- for name, data in deployments.items():
101
- if "transaction" in data:
102
- tx_hash = data["transaction"]
103
- tx_receipt = w3.eth.get_transaction_receipt(tx_hash)
104
- # tx_address will be None if contract created via contract factory
105
- tx_address = tx_receipt["contractAddress"]
106
-
107
- if tx_address is None and allow_missing_data is False:
108
- raise EthPMValidationError(
109
- "No contract address found in tx receipt. Unable to verify "
110
- "address found in tx receipt matches address in manifest's "
111
- "deployment data. If this validation is not necessary, "
112
- "please enable `allow_missing_data` arg. "
113
- )
114
-
115
- if tx_address is not None and not is_same_address(
116
- tx_address, data["address"]
117
- ):
118
- raise EthPMValidationError(
119
- f"Error validating tx_receipt for {name} deployment. "
120
- f"Address found in manifest's deployment data: {data['address']} "
121
- f"Does not match address found on tx_receipt: {tx_address}."
122
- )
123
-
124
- if "block" in data:
125
- if tx_receipt["blockHash"] != to_bytes(hexstr=data["block"]):
126
- raise EthPMValidationError(
127
- f"Error validating tx_receipt for {name} deployment. "
128
- f"Block found in manifest's deployment data: {data['block']!r} "
129
- "Does not match block found on "
130
- f"tx_receipt: {tx_receipt['blockHash']!r}."
131
- )
132
- elif allow_missing_data is False:
133
- raise EthPMValidationError(
134
- "No block hash found in deployment data. "
135
- "Unable to verify block hash on tx receipt. "
136
- "If this validation is not necessary, please enable "
137
- "`allow_missing_data` arg."
138
- )
139
- elif allow_missing_data is False:
140
- raise EthPMValidationError(
141
- "No transaction hash found in deployment data. "
142
- "Unable to validate tx_receipt. "
143
- "If this validation is not necessary, please "
144
- "enable `allow_missing_data` arg."
145
- )
ethpm/_utils/ipfs.py DELETED
@@ -1,116 +0,0 @@
1
- import hashlib
2
- from pathlib import (
3
- Path,
4
- )
5
- from typing import (
6
- Dict,
7
- )
8
- from urllib import (
9
- parse,
10
- )
11
-
12
- from eth_utils import (
13
- to_text,
14
- )
15
- from google.protobuf.descriptor import ( # type: ignore
16
- Descriptor,
17
- )
18
-
19
- from ethpm._utils.protobuf.ipfs_file_pb2 import ( # type: ignore
20
- Data,
21
- PBNode,
22
- )
23
-
24
- try:
25
- # `ipfshttpclient` backend is optional. This is only imported if the "web3[ipfs]"
26
- # install extra is installed
27
- from base58 import (
28
- b58encode,
29
- )
30
- except ImportError:
31
- pass
32
-
33
-
34
- def dummy_ipfs_pin(path: Path) -> Dict[str, str]:
35
- """
36
- Return IPFS data as if file was pinned to an actual node.
37
- """
38
- ipfs_return = {
39
- "Hash": generate_file_hash(path.read_bytes()),
40
- "Name": path.name,
41
- "Size": str(path.stat().st_size),
42
- }
43
- return ipfs_return
44
-
45
-
46
- def create_ipfs_uri(ipfs_hash: str) -> str:
47
- return f"ipfs://{ipfs_hash}"
48
-
49
-
50
- def extract_ipfs_path_from_uri(value: str) -> str:
51
- """
52
- Return the path from an IPFS URI.
53
- Path = IPFS hash & following path.
54
- """
55
- parse_result = parse.urlparse(value)
56
-
57
- if parse_result.netloc:
58
- if parse_result.path:
59
- return "".join((parse_result.netloc, parse_result.path.rstrip("/")))
60
- else:
61
- return parse_result.netloc
62
- else:
63
- return parse_result.path.strip("/")
64
-
65
-
66
- def is_ipfs_uri(value: str) -> bool:
67
- """
68
- Return a bool indicating whether or not the value is a valid IPFS URI.
69
- """
70
- parse_result = parse.urlparse(value)
71
- if parse_result.scheme != "ipfs":
72
- return False
73
- if not parse_result.netloc and not parse_result.path:
74
- return False
75
-
76
- return True
77
-
78
-
79
- #
80
- # Generate IPFS hash
81
- # Lifted from https://github.com/ethereum/populus/blob/feat%2Fv2/populus/utils/ipfs.py
82
- #
83
-
84
-
85
- SHA2_256 = b"\x12"
86
- LENGTH_32 = b"\x20"
87
-
88
-
89
- def multihash(value: bytes) -> bytes:
90
- data_hash = hashlib.sha256(value).digest()
91
-
92
- multihash_bytes = SHA2_256 + LENGTH_32 + data_hash
93
- return multihash_bytes
94
-
95
-
96
- def serialize_bytes(file_bytes: bytes) -> Descriptor:
97
- file_size = len(file_bytes)
98
-
99
- data_protobuf = Data(
100
- Type=Data.DataType.Value("File"),
101
- Data=file_bytes,
102
- filesize=file_size,
103
- )
104
- data_protobuf_bytes = data_protobuf.SerializeToString()
105
-
106
- file_protobuf = PBNode(Links=[], Data=data_protobuf_bytes)
107
-
108
- return file_protobuf
109
-
110
-
111
- def generate_file_hash(content_bytes: bytes) -> str:
112
- file_protobuf: Descriptor = serialize_bytes(content_bytes)
113
- # type ignored b/c SerializeToString is manually attached in ipfs_file_pb2.py
114
- file_protobuf_bytes = file_protobuf.SerializeToString() # type: ignore
115
- file_multihash = multihash(file_protobuf_bytes)
116
- return to_text(b58encode(file_multihash))
File without changes
@@ -1,33 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- # type: ignore
3
- # Generated by the protocol buffer compiler. DO NOT EDIT!
4
- # source: ipfs_file.proto
5
- """Generated protocol buffer code."""
6
- from google.protobuf.internal import builder as _builder
7
- from google.protobuf import descriptor as _descriptor
8
- from google.protobuf import descriptor_pool as _descriptor_pool
9
- from google.protobuf import symbol_database as _symbol_database
10
-
11
- # @@protoc_insertion_point(imports)
12
-
13
- _sym_db = _symbol_database.Default()
14
-
15
-
16
- DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(
17
- b'\n\x0fipfs_file.proto"\xc1\x01\n\x04\x44\x61ta\x12\x1c\n\x04Type\x18\x01 \x01(\x0e\x32\x0e.Data.DataType\x12\x11\n\x04\x44\x61ta\x18\x02 \x01(\x0cH\x00\x88\x01\x01\x12\x15\n\x08\x66ilesize\x18\x03 \x01(\x04H\x01\x88\x01\x01\x12\x12\n\nblocksizes\x18\x04 \x03(\x04"G\n\x08\x44\x61taType\x12\x07\n\x03Raw\x10\x00\x12\r\n\tDirectory\x10\x01\x12\x08\n\x04\x46ile\x10\x02\x12\x0c\n\x08Metadata\x10\x03\x12\x0b\n\x07Symlink\x10\x04\x42\x07\n\x05_DataB\x0b\n\t_filesize"^\n\x06PBLink\x12\x11\n\x04Hash\x18\x01 \x01(\x0cH\x00\x88\x01\x01\x12\x11\n\x04Name\x18\x02 \x01(\tH\x01\x88\x01\x01\x12\x12\n\x05Tsize\x18\x03 \x01(\x04H\x02\x88\x01\x01\x42\x07\n\x05_HashB\x07\n\x05_NameB\x08\n\x06_Tsize"<\n\x06PBNode\x12\x16\n\x05Links\x18\x02 \x03(\x0b\x32\x07.PBLink\x12\x11\n\x04\x44\x61ta\x18\x01 \x01(\x0cH\x00\x88\x01\x01\x42\x07\n\x05_Datab\x06proto3'
18
- )
19
-
20
- _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals())
21
- _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, "ipfs_file_pb2", globals())
22
- if _descriptor._USE_C_DESCRIPTORS == False:
23
-
24
- DESCRIPTOR._options = None
25
- _DATA._serialized_start = 20
26
- _DATA._serialized_end = 213
27
- _DATA_DATATYPE._serialized_start = 120
28
- _DATA_DATATYPE._serialized_end = 191
29
- _PBLINK._serialized_start = 215
30
- _PBLINK._serialized_end = 309
31
- _PBNODE._serialized_start = 311
32
- _PBNODE._serialized_end = 371
33
- # @@protoc_insertion_point(module_scope)
ethpm/_utils/registry.py DELETED
@@ -1,29 +0,0 @@
1
- import json
2
- from typing import (
3
- Any,
4
- Dict,
5
- )
6
-
7
-
8
- def is_ens_domain(authority: str) -> bool:
9
- """
10
- Return false if authority is not a valid ENS domain.
11
- """
12
- # check that authority ends with the tld '.eth'
13
- # check that there are either 2 or 3 subdomains in the authority
14
- # i.e. zeppelinos.eth or packages.zeppelinos.eth
15
- if authority[-4:] != ".eth" or len(authority.split(".")) not in [2, 3]:
16
- return False
17
- return True
18
-
19
-
20
- def fetch_standard_registry_abi() -> Dict[str, Any]:
21
- """
22
- Return the standard Registry ABI to interact with a deployed Registry.
23
- TODO: Update once the standard is finalized via ERC process.
24
- """
25
- # In-lining abi here since it needs to be updated to a registry conforming to
26
- # https://github.com/ethereum/EIPs/issues/1319
27
- return json.loads(
28
- '[{"constant":true,"inputs":[{"name":"_name","type":"bytes32"}],"name":"lookupPackage","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"bytes32"}],"name":"index","outputs":[{"name":"uri","type":"string"},{"name":"version","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_name","type":"bytes32"},{"name":"_version","type":"string"},{"name":"_uri","type":"string"}],"name":"registerPackage","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]' # noqa: E501
29
- )
ethpm/assets/__init__.py DELETED
File without changes