web3 7.0.0b1__py3-none-any.whl → 7.0.0b3__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.
- ens/async_ens.py +6 -8
- ens/ens.py +6 -6
- ens/utils.py +18 -16
- web3/_utils/abi.py +9 -15
- web3/_utils/events.py +15 -6
- web3/_utils/math.py +12 -14
- web3/_utils/method_formatters.py +7 -0
- web3/_utils/module_testing/eth_module.py +67 -6
- web3/_utils/module_testing/module_testing_utils.py +2 -2
- web3/_utils/request.py +1 -1
- web3/_utils/rpc_abi.py +1 -0
- web3/_utils/transactions.py +4 -0
- web3/contract/base_contract.py +1 -1
- web3/datastructures.py +7 -7
- web3/eth/async_eth.py +20 -2
- web3/eth/eth.py +13 -1
- web3/exceptions.py +11 -0
- web3/main.py +4 -30
- web3/manager.py +12 -13
- web3/middleware/__init__.py +9 -8
- web3/module.py +1 -1
- web3/providers/async_base.py +6 -6
- web3/providers/base.py +8 -8
- web3/providers/eth_tester/main.py +16 -20
- web3/providers/ipc.py +1 -1
- web3/providers/legacy_websocket.py +1 -1
- web3/providers/persistent/persistent.py +2 -2
- web3/providers/persistent/request_processor.py +3 -5
- web3/tools/benchmark/main.py +2 -2
- web3/types.py +4 -0
- web3/utils/caching.py +2 -4
- {web3-7.0.0b1.dist-info → web3-7.0.0b3.dist-info}/METADATA +3 -9
- web3-7.0.0b3.dist-info/RECORD +168 -0
- {web3-7.0.0b1.dist-info → web3-7.0.0b3.dist-info}/WHEEL +1 -1
- {web3-7.0.0b1.dist-info → web3-7.0.0b3.dist-info}/top_level.txt +0 -1
- ethpm/__init__.py +0 -20
- ethpm/_utils/__init__.py +0 -0
- ethpm/_utils/backend.py +0 -93
- ethpm/_utils/cache.py +0 -44
- ethpm/_utils/chains.py +0 -119
- ethpm/_utils/contract.py +0 -35
- ethpm/_utils/deployments.py +0 -145
- ethpm/_utils/ipfs.py +0 -116
- ethpm/_utils/protobuf/__init__.py +0 -0
- ethpm/_utils/protobuf/ipfs_file_pb2.py +0 -33
- ethpm/_utils/registry.py +0 -29
- ethpm/assets/__init__.py +0 -0
- ethpm/assets/ens/v3.json +0 -1
- ethpm/assets/escrow/with_bytecode_v3.json +0 -1
- ethpm/assets/ipfs_file.proto +0 -32
- ethpm/assets/owned/output_v3.json +0 -1
- ethpm/assets/owned/with_contract_type_v3.json +0 -1
- ethpm/assets/registry/contracts/Authority.sol +0 -156
- ethpm/assets/registry/contracts/IndexedOrderedSetLib.sol +0 -106
- ethpm/assets/registry/contracts/PackageDB.sol +0 -225
- ethpm/assets/registry/contracts/PackageRegistry.sol +0 -361
- ethpm/assets/registry/contracts/PackageRegistryInterface.sol +0 -97
- ethpm/assets/registry/contracts/ReleaseDB.sol +0 -309
- ethpm/assets/registry/contracts/ReleaseValidator.sol +0 -152
- ethpm/assets/registry/solc_input.json +0 -1
- ethpm/assets/registry/solc_output.json +0 -1
- ethpm/assets/registry/v3.json +0 -1
- ethpm/assets/safe-math-lib/v3-strict-no-deployments.json +0 -1
- ethpm/assets/simple-registry/contracts/Ownable.sol +0 -63
- ethpm/assets/simple-registry/contracts/PackageRegistry.sol +0 -373
- ethpm/assets/simple-registry/contracts/PackageRegistryInterface.sol +0 -96
- ethpm/assets/simple-registry/solc_input.json +0 -33
- ethpm/assets/simple-registry/solc_output.json +0 -1
- ethpm/assets/simple-registry/v3.json +0 -1
- ethpm/assets/standard-token/output_v3.json +0 -1
- ethpm/assets/standard-token/with_bytecode_v3.json +0 -1
- ethpm/assets/vyper_registry/0.1.0.json +0 -1
- ethpm/assets/vyper_registry/registry.vy +0 -216
- ethpm/assets/vyper_registry/registry_with_delete.vy +0 -244
- ethpm/backends/__init__.py +0 -0
- ethpm/backends/base.py +0 -43
- ethpm/backends/http.py +0 -108
- ethpm/backends/ipfs.py +0 -219
- ethpm/backends/registry.py +0 -154
- ethpm/constants.py +0 -17
- ethpm/contract.py +0 -187
- ethpm/dependencies.py +0 -58
- ethpm/deployments.py +0 -80
- ethpm/ethpm-spec/examples/escrow/1.0.0-pretty.json +0 -146
- ethpm/ethpm-spec/examples/escrow/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/escrow/contracts/Escrow.sol +0 -32
- ethpm/ethpm-spec/examples/escrow/contracts/SafeSendLib.sol +0 -20
- ethpm/ethpm-spec/examples/escrow/v3-pretty.json +0 -171
- ethpm/ethpm-spec/examples/escrow/v3.json +0 -1
- ethpm/ethpm-spec/examples/owned/1.0.0-pretty.json +0 -21
- ethpm/ethpm-spec/examples/owned/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/owned/contracts/Owned.sol +0 -12
- ethpm/ethpm-spec/examples/owned/v3-pretty.json +0 -27
- ethpm/ethpm-spec/examples/owned/v3.json +0 -1
- ethpm/ethpm-spec/examples/piper-coin/1.0.0-pretty.json +0 -31
- ethpm/ethpm-spec/examples/piper-coin/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/piper-coin/v3-pretty.json +0 -21
- ethpm/ethpm-spec/examples/piper-coin/v3.json +0 -1
- ethpm/ethpm-spec/examples/safe-math-lib/1.0.0-pretty.json +0 -85
- ethpm/ethpm-spec/examples/safe-math-lib/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/safe-math-lib/contracts/SafeMathLib.sol +0 -24
- ethpm/ethpm-spec/examples/safe-math-lib/v3-pretty.json +0 -117
- ethpm/ethpm-spec/examples/safe-math-lib/v3.json +0 -1
- ethpm/ethpm-spec/examples/standard-token/1.0.0-pretty.json +0 -55
- ethpm/ethpm-spec/examples/standard-token/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/standard-token/contracts/AbstractToken.sol +0 -20
- ethpm/ethpm-spec/examples/standard-token/contracts/StandardToken.sol +0 -84
- ethpm/ethpm-spec/examples/standard-token/v3-pretty.json +0 -460
- ethpm/ethpm-spec/examples/standard-token/v3.json +0 -1
- ethpm/ethpm-spec/examples/transferable/1.0.0-pretty.json +0 -21
- ethpm/ethpm-spec/examples/transferable/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/transferable/contracts/Transferable.sol +0 -14
- ethpm/ethpm-spec/examples/transferable/v3-pretty.json +0 -27
- ethpm/ethpm-spec/examples/transferable/v3.json +0 -1
- ethpm/ethpm-spec/examples/wallet/1.0.0-pretty.json +0 -120
- ethpm/ethpm-spec/examples/wallet/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/wallet/contracts/Wallet.sol +0 -41
- ethpm/ethpm-spec/examples/wallet/v3-pretty.json +0 -181
- ethpm/ethpm-spec/examples/wallet/v3.json +0 -1
- ethpm/ethpm-spec/examples/wallet-with-send/1.0.0-pretty.json +0 -135
- ethpm/ethpm-spec/examples/wallet-with-send/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/wallet-with-send/contracts/WalletWithSend.sol +0 -18
- ethpm/ethpm-spec/examples/wallet-with-send/v3-pretty.json +0 -207
- ethpm/ethpm-spec/examples/wallet-with-send/v3.json +0 -1
- ethpm/ethpm-spec/spec/package.spec.json +0 -379
- ethpm/ethpm-spec/spec/v3.spec.json +0 -483
- ethpm/exceptions.py +0 -68
- ethpm/package.py +0 -438
- ethpm/tools/__init__.py +0 -4
- ethpm/tools/builder.py +0 -930
- ethpm/tools/checker.py +0 -312
- ethpm/tools/get_manifest.py +0 -19
- ethpm/uri.py +0 -141
- ethpm/validation/__init__.py +0 -0
- ethpm/validation/manifest.py +0 -146
- ethpm/validation/misc.py +0 -39
- ethpm/validation/package.py +0 -80
- ethpm/validation/uri.py +0 -163
- web3/pm.py +0 -602
- web3/tools/__init__.py +0 -4
- web3/tools/pytest_ethereum/__init__.py +0 -0
- web3/tools/pytest_ethereum/_utils.py +0 -145
- web3/tools/pytest_ethereum/deployer.py +0 -48
- web3/tools/pytest_ethereum/exceptions.py +0 -22
- web3/tools/pytest_ethereum/linker.py +0 -128
- web3/tools/pytest_ethereum/plugins.py +0 -33
- web3-7.0.0b1.dist-info/RECORD +0 -280
- web3-7.0.0b1.dist-info/entry_points.txt +0 -2
- {web3-7.0.0b1.dist-info → web3-7.0.0b3.dist-info}/LICENSE +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