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
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
- )