web3 6.20.2__py3-none-any.whl → 7.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (270) hide show
  1. ens/__init__.py +13 -2
  2. ens/_normalization.py +2 -17
  3. ens/async_ens.py +33 -21
  4. ens/base_ens.py +3 -1
  5. ens/ens.py +16 -11
  6. ens/exceptions.py +16 -29
  7. ens/specs/nf.json +1 -1
  8. ens/specs/normalization_spec.json +1 -1
  9. ens/utils.py +52 -63
  10. web3/__init__.py +20 -24
  11. web3/_utils/abi.py +115 -271
  12. web3/_utils/async_transactions.py +7 -4
  13. web3/_utils/batching.py +217 -0
  14. web3/_utils/blocks.py +6 -2
  15. web3/_utils/caching.py +128 -5
  16. web3/_utils/compat/__init__.py +2 -3
  17. web3/_utils/contract_sources/compile_contracts.py +1 -1
  18. web3/_utils/contract_sources/contract_data/arrays_contract.py +3 -3
  19. web3/_utils/contract_sources/contract_data/bytes_contracts.py +5 -5
  20. web3/_utils/contract_sources/contract_data/constructor_contracts.py +7 -7
  21. web3/_utils/contract_sources/contract_data/contract_caller_tester.py +3 -3
  22. web3/_utils/contract_sources/contract_data/emitter_contract.py +3 -3
  23. web3/_utils/contract_sources/contract_data/event_contracts.py +5 -5
  24. web3/_utils/contract_sources/contract_data/extended_resolver.py +3 -3
  25. web3/_utils/contract_sources/contract_data/fallback_function_contract.py +3 -3
  26. web3/_utils/contract_sources/contract_data/function_name_tester_contract.py +3 -3
  27. web3/_utils/contract_sources/contract_data/math_contract.py +3 -3
  28. web3/_utils/contract_sources/contract_data/offchain_lookup.py +3 -3
  29. web3/_utils/contract_sources/contract_data/offchain_resolver.py +3 -3
  30. web3/_utils/contract_sources/contract_data/panic_errors_contract.py +3 -3
  31. web3/_utils/contract_sources/contract_data/payable_tester.py +3 -3
  32. web3/_utils/contract_sources/contract_data/receive_function_contracts.py +5 -5
  33. web3/_utils/contract_sources/contract_data/reflector_contracts.py +3 -3
  34. web3/_utils/contract_sources/contract_data/revert_contract.py +3 -3
  35. web3/_utils/contract_sources/contract_data/simple_resolver.py +3 -3
  36. web3/_utils/contract_sources/contract_data/storage_contract.py +3 -3
  37. web3/_utils/contract_sources/contract_data/string_contract.py +3 -3
  38. web3/_utils/contract_sources/contract_data/tuple_contracts.py +5 -5
  39. web3/_utils/contracts.py +130 -236
  40. web3/_utils/datatypes.py +5 -1
  41. web3/_utils/decorators.py +13 -23
  42. web3/_utils/empty.py +1 -1
  43. web3/_utils/encoding.py +16 -12
  44. web3/_utils/ens.py +2 -1
  45. web3/_utils/error_formatters_utils.py +5 -3
  46. web3/_utils/events.py +66 -69
  47. web3/_utils/fee_utils.py +1 -3
  48. web3/_utils/filters.py +24 -22
  49. web3/_utils/formatters.py +2 -2
  50. web3/_utils/http.py +5 -3
  51. web3/_utils/http_session_manager.py +303 -0
  52. web3/_utils/math.py +14 -15
  53. web3/_utils/method_formatters.py +34 -36
  54. web3/_utils/module.py +2 -1
  55. web3/_utils/module_testing/__init__.py +0 -3
  56. web3/_utils/module_testing/eth_module.py +695 -643
  57. web3/_utils/module_testing/module_testing_utils.py +61 -34
  58. web3/_utils/module_testing/persistent_connection_provider.py +56 -25
  59. web3/_utils/module_testing/utils.py +258 -0
  60. web3/_utils/module_testing/web3_module.py +438 -17
  61. web3/_utils/normalizers.py +13 -11
  62. web3/_utils/rpc_abi.py +5 -32
  63. web3/_utils/threads.py +8 -7
  64. web3/_utils/transactions.py +14 -12
  65. web3/_utils/type_conversion.py +5 -1
  66. web3/_utils/validation.py +17 -17
  67. web3/auto/gethdev.py +7 -2
  68. web3/beacon/__init__.py +6 -1
  69. web3/beacon/async_beacon.py +9 -5
  70. web3/beacon/{main.py → beacon.py} +7 -5
  71. web3/contract/__init__.py +7 -0
  72. web3/contract/async_contract.py +47 -46
  73. web3/contract/base_contract.py +183 -158
  74. web3/contract/contract.py +49 -43
  75. web3/contract/utils.py +203 -59
  76. web3/datastructures.py +79 -31
  77. web3/eth/__init__.py +7 -0
  78. web3/eth/async_eth.py +39 -51
  79. web3/eth/base_eth.py +17 -10
  80. web3/eth/eth.py +30 -68
  81. web3/exceptions.py +108 -82
  82. web3/gas_strategies/time_based.py +8 -6
  83. web3/geth.py +1 -254
  84. web3/main.py +75 -122
  85. web3/manager.py +316 -146
  86. web3/method.py +38 -31
  87. web3/middleware/__init__.py +67 -89
  88. web3/middleware/attrdict.py +36 -49
  89. web3/middleware/base.py +174 -0
  90. web3/middleware/buffered_gas_estimate.py +20 -21
  91. web3/middleware/filter.py +157 -117
  92. web3/middleware/formatting.py +124 -108
  93. web3/middleware/gas_price_strategy.py +20 -32
  94. web3/middleware/names.py +29 -26
  95. web3/middleware/proof_of_authority.py +68 -0
  96. web3/middleware/pythonic.py +2 -2
  97. web3/middleware/signing.py +74 -89
  98. web3/middleware/stalecheck.py +52 -79
  99. web3/middleware/validation.py +5 -13
  100. web3/module.py +54 -10
  101. web3/providers/__init__.py +10 -6
  102. web3/providers/async_base.py +117 -39
  103. web3/providers/auto.py +3 -3
  104. web3/providers/base.py +89 -33
  105. web3/providers/eth_tester/__init__.py +5 -0
  106. web3/providers/eth_tester/defaults.py +1 -64
  107. web3/providers/eth_tester/main.py +99 -31
  108. web3/providers/eth_tester/middleware.py +45 -73
  109. web3/providers/ipc.py +42 -46
  110. web3/providers/{websocket/websocket.py → legacy_websocket.py} +32 -7
  111. web3/providers/persistent/__init__.py +22 -0
  112. web3/providers/persistent/async_ipc.py +153 -0
  113. web3/providers/{persistent.py → persistent/persistent.py} +106 -25
  114. web3/providers/persistent/persistent_connection.py +84 -0
  115. web3/providers/{websocket → persistent}/request_processor.py +94 -32
  116. web3/providers/persistent/utils.py +43 -0
  117. web3/providers/{websocket/websocket_v2.py → persistent/websocket.py} +29 -28
  118. web3/providers/rpc/__init__.py +11 -0
  119. web3/providers/rpc/async_rpc.py +171 -0
  120. web3/providers/rpc/rpc.py +179 -0
  121. web3/providers/rpc/utils.py +92 -0
  122. web3/testing.py +4 -4
  123. web3/tools/benchmark/main.py +22 -22
  124. web3/tools/benchmark/node.py +2 -8
  125. web3/tools/benchmark/reporting.py +2 -2
  126. web3/tools/benchmark/utils.py +1 -1
  127. web3/tracing.py +9 -5
  128. web3/types.py +30 -107
  129. web3/utils/__init__.py +58 -5
  130. web3/utils/abi.py +575 -10
  131. web3/utils/async_exception_handling.py +19 -7
  132. web3/utils/caching.py +32 -13
  133. web3/utils/exception_handling.py +7 -5
  134. {web3-6.20.2.dist-info → web3-7.0.0.dist-info}/LICENSE +1 -1
  135. web3-7.0.0.dist-info/METADATA +112 -0
  136. web3-7.0.0.dist-info/RECORD +167 -0
  137. {web3-6.20.2.dist-info → web3-7.0.0.dist-info}/WHEEL +1 -1
  138. {web3-6.20.2.dist-info → web3-7.0.0.dist-info}/top_level.txt +0 -1
  139. ethpm/__init__.py +0 -20
  140. ethpm/_utils/__init__.py +0 -0
  141. ethpm/_utils/backend.py +0 -93
  142. ethpm/_utils/cache.py +0 -44
  143. ethpm/_utils/chains.py +0 -119
  144. ethpm/_utils/contract.py +0 -35
  145. ethpm/_utils/deployments.py +0 -145
  146. ethpm/_utils/ipfs.py +0 -116
  147. ethpm/_utils/protobuf/__init__.py +0 -0
  148. ethpm/_utils/protobuf/ipfs_file_pb2.py +0 -33
  149. ethpm/_utils/registry.py +0 -29
  150. ethpm/assets/__init__.py +0 -0
  151. ethpm/assets/ens/v3.json +0 -1
  152. ethpm/assets/escrow/with_bytecode_v3.json +0 -1
  153. ethpm/assets/ipfs_file.proto +0 -32
  154. ethpm/assets/owned/output_v3.json +0 -1
  155. ethpm/assets/owned/with_contract_type_v3.json +0 -1
  156. ethpm/assets/registry/contracts/Authority.sol +0 -156
  157. ethpm/assets/registry/contracts/IndexedOrderedSetLib.sol +0 -106
  158. ethpm/assets/registry/contracts/PackageDB.sol +0 -225
  159. ethpm/assets/registry/contracts/PackageRegistry.sol +0 -361
  160. ethpm/assets/registry/contracts/PackageRegistryInterface.sol +0 -97
  161. ethpm/assets/registry/contracts/ReleaseDB.sol +0 -309
  162. ethpm/assets/registry/contracts/ReleaseValidator.sol +0 -152
  163. ethpm/assets/registry/solc_input.json +0 -1
  164. ethpm/assets/registry/solc_output.json +0 -1
  165. ethpm/assets/registry/v3.json +0 -1
  166. ethpm/assets/safe-math-lib/v3-strict-no-deployments.json +0 -1
  167. ethpm/assets/simple-registry/contracts/Ownable.sol +0 -63
  168. ethpm/assets/simple-registry/contracts/PackageRegistry.sol +0 -373
  169. ethpm/assets/simple-registry/contracts/PackageRegistryInterface.sol +0 -96
  170. ethpm/assets/simple-registry/solc_input.json +0 -33
  171. ethpm/assets/simple-registry/solc_output.json +0 -1
  172. ethpm/assets/simple-registry/v3.json +0 -1
  173. ethpm/assets/standard-token/output_v3.json +0 -1
  174. ethpm/assets/standard-token/with_bytecode_v3.json +0 -1
  175. ethpm/assets/vyper_registry/0.1.0.json +0 -1
  176. ethpm/assets/vyper_registry/registry.vy +0 -216
  177. ethpm/assets/vyper_registry/registry_with_delete.vy +0 -244
  178. ethpm/backends/__init__.py +0 -0
  179. ethpm/backends/base.py +0 -43
  180. ethpm/backends/http.py +0 -108
  181. ethpm/backends/ipfs.py +0 -219
  182. ethpm/backends/registry.py +0 -154
  183. ethpm/constants.py +0 -17
  184. ethpm/contract.py +0 -187
  185. ethpm/dependencies.py +0 -58
  186. ethpm/deployments.py +0 -80
  187. ethpm/ethpm-spec/examples/escrow/1.0.0-pretty.json +0 -146
  188. ethpm/ethpm-spec/examples/escrow/1.0.0.json +0 -1
  189. ethpm/ethpm-spec/examples/escrow/contracts/Escrow.sol +0 -32
  190. ethpm/ethpm-spec/examples/escrow/contracts/SafeSendLib.sol +0 -20
  191. ethpm/ethpm-spec/examples/escrow/v3-pretty.json +0 -171
  192. ethpm/ethpm-spec/examples/escrow/v3.json +0 -1
  193. ethpm/ethpm-spec/examples/owned/1.0.0-pretty.json +0 -21
  194. ethpm/ethpm-spec/examples/owned/1.0.0.json +0 -1
  195. ethpm/ethpm-spec/examples/owned/contracts/Owned.sol +0 -12
  196. ethpm/ethpm-spec/examples/owned/v3-pretty.json +0 -27
  197. ethpm/ethpm-spec/examples/owned/v3.json +0 -1
  198. ethpm/ethpm-spec/examples/piper-coin/1.0.0-pretty.json +0 -31
  199. ethpm/ethpm-spec/examples/piper-coin/1.0.0.json +0 -1
  200. ethpm/ethpm-spec/examples/piper-coin/v3-pretty.json +0 -21
  201. ethpm/ethpm-spec/examples/piper-coin/v3.json +0 -1
  202. ethpm/ethpm-spec/examples/safe-math-lib/1.0.0-pretty.json +0 -85
  203. ethpm/ethpm-spec/examples/safe-math-lib/1.0.0.json +0 -1
  204. ethpm/ethpm-spec/examples/safe-math-lib/contracts/SafeMathLib.sol +0 -24
  205. ethpm/ethpm-spec/examples/safe-math-lib/v3-pretty.json +0 -117
  206. ethpm/ethpm-spec/examples/safe-math-lib/v3.json +0 -1
  207. ethpm/ethpm-spec/examples/standard-token/1.0.0-pretty.json +0 -55
  208. ethpm/ethpm-spec/examples/standard-token/1.0.0.json +0 -1
  209. ethpm/ethpm-spec/examples/standard-token/contracts/AbstractToken.sol +0 -20
  210. ethpm/ethpm-spec/examples/standard-token/contracts/StandardToken.sol +0 -84
  211. ethpm/ethpm-spec/examples/standard-token/v3-pretty.json +0 -460
  212. ethpm/ethpm-spec/examples/standard-token/v3.json +0 -1
  213. ethpm/ethpm-spec/examples/transferable/1.0.0-pretty.json +0 -21
  214. ethpm/ethpm-spec/examples/transferable/1.0.0.json +0 -1
  215. ethpm/ethpm-spec/examples/transferable/contracts/Transferable.sol +0 -14
  216. ethpm/ethpm-spec/examples/transferable/v3-pretty.json +0 -27
  217. ethpm/ethpm-spec/examples/transferable/v3.json +0 -1
  218. ethpm/ethpm-spec/examples/wallet/1.0.0-pretty.json +0 -120
  219. ethpm/ethpm-spec/examples/wallet/1.0.0.json +0 -1
  220. ethpm/ethpm-spec/examples/wallet/contracts/Wallet.sol +0 -41
  221. ethpm/ethpm-spec/examples/wallet/v3-pretty.json +0 -181
  222. ethpm/ethpm-spec/examples/wallet/v3.json +0 -1
  223. ethpm/ethpm-spec/examples/wallet-with-send/1.0.0-pretty.json +0 -135
  224. ethpm/ethpm-spec/examples/wallet-with-send/1.0.0.json +0 -1
  225. ethpm/ethpm-spec/examples/wallet-with-send/contracts/WalletWithSend.sol +0 -18
  226. ethpm/ethpm-spec/examples/wallet-with-send/v3-pretty.json +0 -207
  227. ethpm/ethpm-spec/examples/wallet-with-send/v3.json +0 -1
  228. ethpm/ethpm-spec/spec/package.spec.json +0 -379
  229. ethpm/ethpm-spec/spec/v3.spec.json +0 -483
  230. ethpm/exceptions.py +0 -68
  231. ethpm/package.py +0 -438
  232. ethpm/tools/__init__.py +0 -4
  233. ethpm/tools/builder.py +0 -930
  234. ethpm/tools/checker.py +0 -312
  235. ethpm/tools/get_manifest.py +0 -19
  236. ethpm/uri.py +0 -141
  237. ethpm/validation/__init__.py +0 -0
  238. ethpm/validation/manifest.py +0 -146
  239. ethpm/validation/misc.py +0 -39
  240. ethpm/validation/package.py +0 -80
  241. ethpm/validation/uri.py +0 -163
  242. web3/_utils/contract_sources/contract_data/address_reflector.py +0 -29
  243. web3/_utils/miner.py +0 -88
  244. web3/_utils/module_testing/go_ethereum_personal_module.py +0 -323
  245. web3/_utils/request.py +0 -265
  246. web3/middleware/abi.py +0 -11
  247. web3/middleware/async_cache.py +0 -99
  248. web3/middleware/cache.py +0 -374
  249. web3/middleware/exception_handling.py +0 -49
  250. web3/middleware/exception_retry_request.py +0 -188
  251. web3/middleware/fixture.py +0 -190
  252. web3/middleware/geth_poa.py +0 -81
  253. web3/middleware/normalize_request_parameters.py +0 -11
  254. web3/middleware/simulate_unmined_transaction.py +0 -43
  255. web3/pm.py +0 -602
  256. web3/providers/async_rpc.py +0 -99
  257. web3/providers/rpc.py +0 -98
  258. web3/providers/websocket/__init__.py +0 -11
  259. web3/providers/websocket/websocket_connection.py +0 -42
  260. web3/tools/__init__.py +0 -4
  261. web3/tools/pytest_ethereum/__init__.py +0 -0
  262. web3/tools/pytest_ethereum/_utils.py +0 -145
  263. web3/tools/pytest_ethereum/deployer.py +0 -48
  264. web3/tools/pytest_ethereum/exceptions.py +0 -22
  265. web3/tools/pytest_ethereum/linker.py +0 -128
  266. web3/tools/pytest_ethereum/plugins.py +0 -33
  267. web3-6.20.2.dist-info/METADATA +0 -103
  268. web3-6.20.2.dist-info/RECORD +0 -283
  269. web3-6.20.2.dist-info/entry_points.txt +0 -2
  270. /web3/_utils/{function_identifiers.py → abi_element_identifiers.py} +0 -0
ethpm/package.py DELETED
@@ -1,438 +0,0 @@
1
- import json
2
- from pathlib import (
3
- Path,
4
- )
5
- from typing import (
6
- TYPE_CHECKING,
7
- Any,
8
- Dict,
9
- Generator,
10
- Iterable,
11
- List,
12
- Optional,
13
- Tuple,
14
- Type,
15
- Union,
16
- cast,
17
- )
18
-
19
- from eth_typing import (
20
- URI,
21
- Address,
22
- ContractName,
23
- Manifest,
24
- )
25
- from eth_utils import (
26
- to_canonical_address,
27
- to_dict,
28
- to_text,
29
- to_tuple,
30
- )
31
-
32
- from ethpm._utils.cache import (
33
- cached_property,
34
- )
35
- from ethpm._utils.contract import (
36
- generate_contract_factory_kwargs,
37
- )
38
- from ethpm._utils.deployments import (
39
- get_linked_deployments,
40
- normalize_linked_references,
41
- validate_deployments_tx_receipt,
42
- validate_linked_references,
43
- )
44
- from ethpm.contract import (
45
- LinkableContract,
46
- )
47
- from ethpm.dependencies import (
48
- Dependencies,
49
- )
50
- from ethpm.deployments import (
51
- DeploymentData,
52
- Deployments,
53
- )
54
- from ethpm.exceptions import (
55
- BytecodeLinkingError,
56
- EthPMException,
57
- EthPMValidationError,
58
- FailureToFetchIPFSAssetsError,
59
- InsufficientAssetsError,
60
- )
61
- from ethpm.uri import (
62
- resolve_uri_contents,
63
- )
64
- from ethpm.validation.manifest import (
65
- check_for_deployments,
66
- validate_build_dependencies_are_present,
67
- validate_manifest_against_schema,
68
- validate_manifest_deployments,
69
- validate_raw_manifest_format,
70
- )
71
- from ethpm.validation.misc import (
72
- validate_w3_instance,
73
- )
74
- from ethpm.validation.package import (
75
- validate_build_dependency,
76
- validate_contract_name,
77
- validate_minimal_contract_factory_data,
78
- )
79
- from ethpm.validation.uri import (
80
- validate_single_matching_uri,
81
- )
82
- from web3._utils.validation import (
83
- validate_address,
84
- )
85
- from web3.eth import (
86
- Contract,
87
- )
88
-
89
- if TYPE_CHECKING:
90
- from web3 import Web3 # noqa: F401
91
-
92
-
93
- class Package(object):
94
- def __init__(
95
- self, manifest: Dict[str, Any], w3: "Web3", uri: Optional[str] = None
96
- ) -> None:
97
- """
98
- A package should be created using one of the available
99
- classmethods and a valid w3 instance.
100
- """
101
- if not isinstance(manifest, dict):
102
- raise TypeError(
103
- "Package object must be initialized with a dictionary. "
104
- f"Got {type(manifest)}"
105
- )
106
-
107
- if "manifest" not in manifest or manifest["manifest"] != "ethpm/3":
108
- raise EthPMValidationError(
109
- "Py-Ethpm currently only supports v3 ethpm manifests. "
110
- "Please use the CLI to update or re-generate a v3 manifest. "
111
- )
112
-
113
- validate_manifest_against_schema(manifest)
114
- validate_manifest_deployments(manifest)
115
- validate_w3_instance(w3)
116
-
117
- self.w3 = w3
118
- self.w3.eth._default_contract_factory = cast(Type[Contract], LinkableContract)
119
- self.manifest = manifest
120
- self._uri = uri
121
-
122
- def update_w3(self, w3: "Web3") -> "Package":
123
- """
124
- Returns a new instance of `Package` containing the same manifest,
125
- but connected to a different web3 instance.
126
-
127
- .. doctest::
128
-
129
- >>> new_w3 = Web3(Web3.EthereumTesterProvider())
130
- >>> NewPackage = OwnedPackage.update_w3(new_w3)
131
- >>> assert NewPackage.w3 == new_w3
132
- >>> assert OwnedPackage.manifest == NewPackage.manifest
133
- """
134
- validate_w3_instance(w3)
135
- return Package(self.manifest, w3, self.uri)
136
-
137
- def __repr__(self) -> str:
138
- """
139
- String readable representation of the Package.
140
-
141
- .. doctest::
142
-
143
- >>> OwnedPackage.__repr__()
144
- '<Package owned==1.0.0>'
145
- """
146
- name = self.name
147
- version = self.version
148
- return f"<Package {name}=={version}>"
149
-
150
- @property
151
- def name(self) -> str:
152
- """
153
- The name of this ``Package``.
154
-
155
- .. doctest::
156
-
157
- >>> OwnedPackage.name
158
- 'owned'
159
- """
160
- return self.manifest["name"]
161
-
162
- @property
163
- def version(self) -> str:
164
- """
165
- The package version of a ``Package``.
166
-
167
- .. doctest::
168
-
169
- >>> OwnedPackage.version
170
- '1.0.0'
171
- """
172
- return self.manifest["version"]
173
-
174
- @property
175
- def manifest_version(self) -> str:
176
- """
177
- The manifest version of a ``Package``.
178
-
179
- .. doctest::
180
-
181
- >>> OwnedPackage.manifest_version
182
- 'ethpm/3'
183
- """
184
- return self.manifest["manifest"]
185
-
186
- @property
187
- def uri(self) -> Optional[str]:
188
- """
189
- The uri (local file_path / content-addressed URI) of a ``Package``'s manifest.
190
- """
191
- return self._uri
192
-
193
- @property
194
- def contract_types(self) -> List[str]:
195
- """
196
- All contract types included in this package.
197
- """
198
- if "contractTypes" in self.manifest:
199
- return sorted(self.manifest["contractTypes"].keys())
200
- else:
201
- raise ValueError("No contract types found in manifest; {self.__repr__()}.")
202
-
203
- @classmethod
204
- def from_file(cls, file_path: Path, w3: "Web3") -> "Package":
205
- """
206
- Returns a ``Package`` instantiated by a manifest located at the provided Path.
207
- ``file_path`` arg must be a ``pathlib.Path`` instance.
208
- A valid ``Web3`` instance is required to instantiate a ``Package``.
209
- """
210
- if isinstance(file_path, Path):
211
- raw_manifest = file_path.read_text()
212
- validate_raw_manifest_format(raw_manifest)
213
- manifest = json.loads(raw_manifest)
214
- else:
215
- raise TypeError(
216
- "The Package.from_file method expects a pathlib.Path instance."
217
- f"Got {type(file_path)} instead."
218
- )
219
- return cls(manifest, w3, file_path.as_uri())
220
-
221
- @classmethod
222
- def from_uri(cls, uri: URI, w3: "Web3") -> "Package":
223
- """
224
- Returns a Package object instantiated by a manifest located at a content-addressed URI.
225
- A valid ``Web3`` instance is also required.
226
- URI schemes supported:
227
-
228
- - IPFS: `ipfs://Qm...`
229
-
230
- - HTTP: `https://api.github.com/repos/:owner/:repo/git/blobs/:file_sha`
231
-
232
- - Registry: `erc1319://registry.eth:1/greeter?version=1.0.0`
233
-
234
- .. code:: python
235
-
236
- OwnedPackage = Package.from_uri('ipfs://QmbeVyFLSuEUxiXKwSsEjef7icpdTdA4kGG9BcrJXKNKUW', w3) # noqa: E501
237
- """
238
- contents = to_text(resolve_uri_contents(uri))
239
- validate_raw_manifest_format(contents)
240
- manifest = json.loads(contents)
241
- return cls(manifest, w3, uri)
242
-
243
- #
244
- # Contracts
245
- #
246
-
247
- def get_contract_factory(self, name: ContractName) -> LinkableContract:
248
- """
249
- Return the contract factory for a given contract type, generated from
250
- the data available in ``Package.manifest``. Contract factories are
251
- accessible from the package class.
252
-
253
- .. code:: python
254
-
255
- Owned = OwnedPackage.get_contract_factory('owned')
256
-
257
- In cases where a contract uses a library, the contract factory will have
258
- unlinked bytecode. The ``ethpm`` package ships with its own subclass of
259
- ``web3.contract.Contract``, ``ethpm.contract.LinkableContract`` with a few extra
260
- methods and properties related to bytecode linking.
261
-
262
- .. code:: python
263
-
264
- >>> math = owned_package.contract_factories.math
265
- >>> math.needs_bytecode_linking
266
- True
267
- >>> linked_math = math.link_bytecode({'MathLib': '0x1234...'})
268
- >>> linked_math.needs_bytecode_linking
269
- False
270
- """
271
- validate_contract_name(name)
272
-
273
- if "contractTypes" not in self.manifest:
274
- raise InsufficientAssetsError(
275
- "This package does not contain any contract type data."
276
- )
277
-
278
- try:
279
- contract_data = self.manifest["contractTypes"][name]
280
- except KeyError:
281
- raise InsufficientAssetsError(
282
- "This package does not contain any package data to generate "
283
- f"a contract factory for contract type: {name}. Available contract"
284
- f" types include: {self.contract_types}."
285
- )
286
-
287
- validate_minimal_contract_factory_data(contract_data)
288
- contract_kwargs = generate_contract_factory_kwargs(contract_data)
289
- contract_factory = self.w3.eth.contract(**contract_kwargs)
290
- return contract_factory
291
-
292
- def get_contract_instance(self, name: ContractName, address: Address) -> Contract:
293
- """
294
- Will return a ``Web3.contract`` instance generated from the contract type
295
- data available in ``Package.manifest`` and the provided ``address``.
296
- The provided ``address`` must be valid on the connected chain available
297
- through ``Package.w3``.
298
- """
299
- validate_address(address)
300
- validate_contract_name(name)
301
- try:
302
- self.manifest["contractTypes"][name]["abi"]
303
- except KeyError:
304
- raise InsufficientAssetsError(
305
- "Package does not have the ABI required to generate a "
306
- f"contract instance for contract: {name} at address: {address!r}."
307
- )
308
- contract_kwargs = generate_contract_factory_kwargs(
309
- self.manifest["contractTypes"][name]
310
- )
311
- contract_instance = self.w3.eth.contract(address=address, **contract_kwargs)
312
- return contract_instance
313
-
314
- #
315
- # Build Dependencies
316
- #
317
-
318
- @cached_property
319
- def build_dependencies(self) -> "Dependencies":
320
- """
321
- Return `Dependencies` instance containing the build dependencies
322
- available on this Package.
323
-
324
- The ``Package`` class should provide access to the full dependency tree.
325
-
326
- .. code:: python
327
-
328
- >>> owned_package.build_dependencies['zeppelin']
329
- <ZeppelinPackage>
330
- """
331
- validate_build_dependencies_are_present(self.manifest)
332
-
333
- dependencies = self.manifest["buildDependencies"]
334
- dependency_packages = {}
335
- for name, uri in dependencies.items():
336
- try:
337
- validate_build_dependency(name, uri)
338
- dependency_package = Package.from_uri(uri, self.w3)
339
- except EthPMException as e:
340
- raise FailureToFetchIPFSAssetsError(
341
- f"Failed to retrieve build dependency: {name} from URI: {uri}.\n"
342
- f"Got error: {e}."
343
- )
344
- else:
345
- dependency_packages[name] = dependency_package
346
-
347
- return Dependencies(dependency_packages)
348
-
349
- #
350
- # Deployments
351
- #
352
-
353
- @cached_property
354
- def deployments(self) -> Union["Deployments", Dict[None, None]]:
355
- """
356
- Returns a ``Deployments`` object containing all the deployment data and contract
357
- instances of a ``Package``'s `contract_types`. Automatically filters deployments
358
- to only expose those available on the current ``Package.w3`` instance.
359
-
360
- .. code:: python
361
-
362
- package.deployments.get_instance("ContractType")
363
- """
364
- if not check_for_deployments(self.manifest):
365
- return {}
366
-
367
- all_blockchain_uris = self.manifest["deployments"].keys()
368
- matching_uri = validate_single_matching_uri(all_blockchain_uris, self.w3)
369
-
370
- deployments = self.manifest["deployments"][matching_uri]
371
- all_contract_instances = self._get_all_contract_instances(deployments)
372
- validate_deployments_tx_receipt(deployments, self.w3, allow_missing_data=True)
373
- linked_deployments = get_linked_deployments(deployments)
374
- if linked_deployments:
375
- for deployment_data in linked_deployments.values():
376
- on_chain_bytecode = self.w3.eth.get_code(deployment_data["address"])
377
- unresolved_linked_refs = normalize_linked_references(
378
- deployment_data["runtimeBytecode"]["linkDependencies"]
379
- )
380
- resolved_linked_refs = tuple(
381
- self._resolve_linked_references(link_ref, deployments)
382
- for link_ref in unresolved_linked_refs
383
- )
384
- for linked_ref in resolved_linked_refs:
385
- validate_linked_references(linked_ref, on_chain_bytecode)
386
-
387
- return Deployments(deployments, all_contract_instances)
388
-
389
- @to_dict
390
- def _get_all_contract_instances(
391
- self, deployments: Dict[str, DeploymentData]
392
- ) -> Iterable[Tuple[str, Contract]]:
393
- for deployment_name, deployment_data in deployments.items():
394
- if deployment_data["contractType"] not in self.contract_types:
395
- raise EthPMValidationError(
396
- f"Contract type: {deployment_data['contractType']} for alias: "
397
- f"{deployment_name} not found. Available contract types include: "
398
- f"{self.contract_types}."
399
- )
400
- contract_instance = self.get_contract_instance(
401
- ContractName(deployment_data["contractType"]),
402
- deployment_data["address"],
403
- )
404
- yield deployment_name, contract_instance
405
-
406
- @to_tuple
407
- def _resolve_linked_references(
408
- self, link_ref: Tuple[int, str, str], deployments: Dict[str, Any]
409
- ) -> Generator[Tuple[int, bytes], None, None]:
410
- # No nested deployment: i.e. 'Owned'
411
- offset, link_type, value = link_ref
412
- if link_type == "literal":
413
- yield offset, to_canonical_address(value)
414
- elif value in deployments:
415
- yield offset, to_canonical_address(deployments[value]["address"])
416
- # No nested deployment, but invalid ref
417
- elif ":" not in value:
418
- raise BytecodeLinkingError(
419
- f"Contract instance reference: {value} not found "
420
- "in package's deployment data."
421
- )
422
- # Expects child pkg in build_dependencies
423
- elif value.split(":")[0] not in self.build_dependencies:
424
- raise BytecodeLinkingError(
425
- f"Expected build dependency: {value.split(':')[0]} not found "
426
- "in package's build dependencies."
427
- )
428
- # Find and return resolved, nested ref
429
- else:
430
- unresolved_linked_ref = value.split(":", 1)[-1]
431
- build_dependency = self.build_dependencies[value.split(":")[0]]
432
- yield build_dependency._resolve_link_dependencies(unresolved_linked_ref)
433
-
434
-
435
- def format_manifest(manifest: Manifest, *, prettify: bool = None) -> str:
436
- if prettify:
437
- return json.dumps(manifest, sort_keys=True, indent=4)
438
- return json.dumps(manifest, sort_keys=True, separators=(",", ":"))
ethpm/tools/__init__.py DELETED
@@ -1,4 +0,0 @@
1
- from .get_manifest import ( # noqa: F401
2
- get_ethpm_local_manifest,
3
- get_ethpm_spec_manifest,
4
- )