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
web3/pm.py DELETED
@@ -1,602 +0,0 @@
1
- from abc import (
2
- ABC,
3
- abstractmethod,
4
- )
5
- import json
6
- from pathlib import (
7
- Path,
8
- )
9
- from typing import (
10
- Any,
11
- Dict,
12
- Iterable,
13
- NamedTuple,
14
- Tuple,
15
- Type,
16
- TypeVar,
17
- Union,
18
- cast,
19
- )
20
-
21
- from eth_typing import (
22
- URI,
23
- Address,
24
- ChecksumAddress,
25
- ContractName,
26
- Manifest,
27
- )
28
- from eth_utils import (
29
- is_canonical_address,
30
- is_checksum_address,
31
- to_checksum_address,
32
- to_text,
33
- to_tuple,
34
- )
35
-
36
- from ens import (
37
- ENS,
38
- )
39
- from ethpm import (
40
- ASSETS_DIR,
41
- Package,
42
- )
43
- from ethpm.exceptions import (
44
- EthPMException,
45
- ManifestValidationError,
46
- )
47
- from ethpm.uri import (
48
- is_supported_content_addressed_uri,
49
- resolve_uri_contents,
50
- )
51
- from ethpm.validation.manifest import (
52
- validate_manifest_against_schema,
53
- validate_raw_manifest_format,
54
- )
55
- from ethpm.validation.package import (
56
- validate_package_name,
57
- validate_package_version,
58
- )
59
- from web3 import (
60
- Web3,
61
- )
62
- from web3._utils.ens import (
63
- is_ens_name,
64
- )
65
- from web3.exceptions import (
66
- InvalidAddress,
67
- NameNotFound,
68
- )
69
- from web3.module import (
70
- Module,
71
- )
72
-
73
- # Package Management is still in alpha, and its API is likely to change, so it
74
- # is not automatically available on a web3 instance. To use the `PM` module,
75
- # please enable the package management API on an individual web3 instance.
76
- #
77
- # >>> from web3 import Web3, IPCProvider
78
- # >>> w3 = Web3(IPCProvider(...))
79
- # >>> w3.pm
80
- # AttributeError: The Package Management feature is disabled by default ...
81
- # >>> w3.enable_unstable_package_management_api()
82
- # >>> w3.pm
83
- # <web3.pm.PM at 0x....>
84
-
85
- T = TypeVar("T")
86
-
87
-
88
- class ReleaseData(NamedTuple):
89
- package_name: str
90
- version: str
91
- manifest_uri: URI
92
-
93
-
94
- class ERC1319Registry(ABC):
95
- """
96
- The ERC1319Registry class is a base class for all registry implementations
97
- to inherit from. It defines the methods specified in
98
- `ERC 1319 <https://github.com/ethereum/EIPs/issues/1319>`__. All of these
99
- methods are prefixed with an underscore, since they are not intended to be
100
- accessed directly, but rather through the methods on ``web3.pm``.
101
- They are unlikely to change, but must be implemented in a `ERC1319Registry`
102
- subclass in order to be compatible with the `PM` module. Any custom
103
- methods (eg. not defined in ERC1319) in a subclass should *not* be
104
- prefixed with an underscore.
105
-
106
- All of these methods must be implemented in any subclass in order to work
107
- with `web3.pm.PM`. Any implementation specific logic should be
108
- handled in a subclass.
109
- """
110
-
111
- @abstractmethod
112
- def __init__(self, address: Address, w3: Web3) -> None:
113
- """
114
- Initializes the class with the on-chain address of the registry, and a web3
115
- instance connected to the chain where the registry can be found.
116
-
117
- Must set the following properties...
118
-
119
- * ``self.registry``: A `web3.contract` instance of the target registry.
120
- * ``self.address``: The address of the target registry.
121
- * ``self.w3``: The *web3* instance connected to the chain where the
122
- registry can be found.
123
- """
124
- pass
125
-
126
- #
127
- # Write API
128
- #
129
-
130
- @abstractmethod
131
- def _release(self, package_name: str, version: str, manifest_uri: str) -> bytes:
132
- """
133
- Returns the releaseId created by successfully adding a release to the registry.
134
-
135
- * Parameters:
136
- * ``package_name``: Valid package name according the spec.
137
- * ``version``: Version identifier string, can conform to
138
- any versioning scheme.
139
- * ``manifest_uri``: URI location of a manifest which details the
140
- release contents
141
- """
142
- pass
143
-
144
- #
145
- # Read API
146
- #
147
-
148
- @abstractmethod
149
- def _get_package_name(self, package_id: bytes) -> str:
150
- """
151
- Returns the package name associated with the given package id, if the
152
- package id exists on the connected registry.
153
-
154
- * Parameters:
155
- * ``package_id``: 32 byte package identifier.
156
- """
157
- pass
158
-
159
- @abstractmethod
160
- def _get_all_package_ids(self) -> Iterable[bytes]:
161
- """
162
- Returns a tuple containing all of the package ids found on the
163
- connected registry.
164
- """
165
- pass
166
-
167
- @abstractmethod
168
- def _get_release_id(self, package_name: str, version: str) -> bytes:
169
- """
170
- Returns the 32 bytes release id associated with the given
171
- package name and version, if the release exists on the connected registry.
172
-
173
- * Parameters:
174
- * ``package_name``: Valid package name according the spec.
175
- * ``version``: Version identifier string, can conform to
176
- any versioning scheme.
177
- """
178
- pass
179
-
180
- @abstractmethod
181
- def _get_all_release_ids(self, package_name: str) -> Iterable[bytes]:
182
- """
183
- Returns a tuple containing all of the release ids belonging to the
184
- given package name, if the package has releases on the connected registry.
185
-
186
- * Parameters:
187
- * ``package_name``: Valid package name according the spec.
188
- """
189
- pass
190
-
191
- @abstractmethod
192
- def _get_release_data(self, release_id: bytes) -> ReleaseData:
193
- """
194
- Returns a tuple containing (package_name, version, manifest_uri) for the
195
- given release id, if the release exists on the connected registry.
196
-
197
- * Parameters:
198
- * ``release_id``: 32 byte release identifier.
199
- """
200
- pass
201
-
202
- @abstractmethod
203
- def _generate_release_id(self, package_name: str, version: str) -> bytes:
204
- """
205
- Returns the 32 byte release identifier that *would* be associated with the given
206
- package name and version according to the registry's hashing mechanism.
207
- The release *does not* have to exist on the connected registry.
208
-
209
- * Parameters:
210
- * ``package_name``: Valid package name according the spec.
211
- * ``version``: Version identifier string, can conform to
212
- any versioning scheme.
213
- """
214
- pass
215
-
216
- @abstractmethod
217
- def _num_package_ids(self) -> int:
218
- """
219
- Returns the number of packages that exist on the connected registry.
220
- """
221
- pass
222
-
223
- @abstractmethod
224
- def _num_release_ids(self, package_name: str) -> int:
225
- """
226
- Returns the number of releases found on the connected registry,
227
- that belong to the given package name.
228
-
229
- * Parameters:
230
- * ``package_name``: Valid package name according the spec.
231
- """
232
- pass
233
-
234
- @classmethod
235
- @abstractmethod
236
- def deploy_new_instance(cls: Type[T], w3: Web3) -> T:
237
- """
238
- Class method that returns a newly deployed instance of ERC1319Registry.
239
-
240
- * Parameters:
241
- * ``w3``: Web3 instance on which to deploy the new registry.
242
- """
243
- pass
244
-
245
-
246
- BATCH_SIZE = 100
247
-
248
-
249
- class SimpleRegistry(ERC1319Registry):
250
- """
251
- This class represents an instance of the `Solidity Reference Registry implementation
252
- <https://github.com/ethpm/solidity-registry>`__.
253
- """
254
-
255
- def __init__(self, address: ChecksumAddress, w3: Web3) -> None:
256
- abi = get_simple_registry_manifest()["contractTypes"]["PackageRegistry"]["abi"]
257
- self.registry = w3.eth.contract(address=address, abi=abi)
258
- self.address = address
259
- self.w3 = w3
260
-
261
- def _release(self, package_name: str, version: str, manifest_uri: str) -> bytes:
262
- tx_hash = self.registry.functions.release(
263
- package_name, version, manifest_uri
264
- ).transact()
265
- self.w3.eth.wait_for_transaction_receipt(tx_hash)
266
- return self._get_release_id(package_name, version)
267
-
268
- def _get_package_name(self, package_id: bytes) -> str:
269
- package_name = self.registry.functions.getPackageName(package_id).call()
270
- return package_name
271
-
272
- @to_tuple
273
- def _get_all_package_ids(self) -> Iterable[bytes]:
274
- num_packages = self._num_package_ids()
275
- pointer = 0
276
- while pointer < num_packages:
277
- new_ids, new_pointer = self.registry.functions.getAllPackageIds(
278
- pointer, (pointer + BATCH_SIZE)
279
- ).call()
280
- if not new_pointer > pointer:
281
- break
282
- yield from reversed(new_ids)
283
- pointer = new_pointer
284
-
285
- def _get_release_id(self, package_name: str, version: str) -> bytes:
286
- return self.registry.functions.getReleaseId(package_name, version).call()
287
-
288
- @to_tuple
289
- def _get_all_release_ids(self, package_name: str) -> Iterable[bytes]:
290
- num_releases = self._num_release_ids(package_name)
291
- pointer = 0
292
- while pointer < num_releases:
293
- new_ids, new_pointer = self.registry.functions.getAllReleaseIds(
294
- package_name, pointer, (pointer + BATCH_SIZE)
295
- ).call()
296
- if not new_pointer > pointer:
297
- break
298
- yield from reversed(new_ids)
299
- pointer = new_pointer
300
-
301
- def _get_release_data(self, release_id: bytes) -> ReleaseData:
302
- name, version, uri = self.registry.functions.getReleaseData(release_id).call()
303
- return ReleaseData(name, version, uri)
304
-
305
- def _generate_release_id(self, package_name: str, version: str) -> bytes:
306
- return self.registry.functions.generateReleaseId(package_name, version).call()
307
-
308
- def _num_package_ids(self) -> int:
309
- return self.registry.functions.numPackageIds().call()
310
-
311
- def _num_release_ids(self, package_name: str) -> int:
312
- return self.registry.functions.numReleaseIds(package_name).call()
313
-
314
- @classmethod
315
- def deploy_new_instance(cls, w3: Web3) -> "SimpleRegistry":
316
- manifest = get_simple_registry_manifest()
317
- registry_package = Package(manifest, w3)
318
- registry_factory = registry_package.get_contract_factory(
319
- ContractName("PackageRegistry")
320
- )
321
- tx_hash = registry_factory.constructor().transact()
322
- tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
323
- return cls(tx_receipt["contractAddress"], w3)
324
-
325
-
326
- class PM(Module):
327
- """
328
- The PM module will work with any subclass of ``ERC1319Registry``,
329
- tailored to a particular implementation of
330
- `ERC1319 <https://github.com/ethereum/EIPs/issues/1319>`__, set as
331
- its ``registry`` attribute.
332
- """
333
-
334
- # mypy types
335
- w3: "Web3"
336
-
337
- def get_package_from_manifest(self, manifest: Manifest) -> Package:
338
- """
339
- Returns a `Package <https://github.com/ethpm/py-ethpm/blob/master/ethpm/package.py>`__ # noqa: E501
340
- instance built with the given manifest.
341
-
342
- * Parameters:
343
- * ``manifest``: A dict representing a valid manifest
344
- """
345
- return Package(manifest, self.w3)
346
-
347
- def get_package_from_uri(self, manifest_uri: URI) -> Package:
348
- """
349
- Returns a `Package <https://github.com/ethpm/py-ethpm/blob/master/ethpm/package.py>`__ # noqa: E501
350
- instance built with the Manifest stored at the URI.
351
- If you want to use a specific IPFS backend, set ``ETHPM_IPFS_BACKEND_CLASS``
352
- to your desired backend. Defaults to Infura IPFS backend.
353
-
354
- * Parameters:
355
- * ``uri``: Must be a valid content-addressed URI
356
- """
357
- return Package.from_uri(manifest_uri, self.w3)
358
-
359
- def get_local_package(self, package_name: str, ethpm_dir: Path = None) -> Package:
360
- """
361
- Returns a `Package <https://github.com/ethpm/py-ethpm/blob/master/ethpm/package.py>`__ # noqa: E501
362
- instance built with the Manifest found at the package name in your local ethpm_dir.
363
-
364
- * Parameters:
365
- * ``package_name``: Must be the name of a package installed locally.
366
- * ``ethpm_dir``: Path pointing to the target ethpm directory (optional).
367
- """
368
- if not ethpm_dir:
369
- ethpm_dir = Path.cwd() / "_ethpm_packages"
370
-
371
- if not ethpm_dir.name == "_ethpm_packages" or not ethpm_dir.is_dir():
372
- raise EthPMException(
373
- f"{ethpm_dir} is not a valid ethPM packages directory."
374
- )
375
-
376
- local_packages = [pkg.name for pkg in ethpm_dir.iterdir() if pkg.is_dir()]
377
- if package_name not in local_packages:
378
- raise EthPMException(
379
- f"Package: {package_name} not found in {ethpm_dir}. "
380
- f"Available packages include: {local_packages}."
381
- )
382
-
383
- target_manifest = json.loads(
384
- (ethpm_dir / package_name / "manifest.json").read_text()
385
- )
386
- return self.get_package_from_manifest(target_manifest)
387
-
388
- def set_registry(self, address: Union[Address, ChecksumAddress, ENS]) -> None:
389
- """
390
- Sets the current registry used in ``web3.pm`` functions that read/write
391
- to an on-chain registry. This method accepts checksummed/canonical
392
- addresses or ENS names. Addresses must point to an on-chain instance
393
- of an ERC1319 registry implementation.
394
-
395
- To use an ENS domain as the address, make sure a valid ENS instance
396
- set as ``web3.ens``.
397
-
398
- * Parameters:
399
- * ``address``: Address of on-chain Registry.
400
- """
401
- if is_canonical_address(address):
402
- addr_string = to_text(address)
403
- self.registry = SimpleRegistry(to_checksum_address(addr_string), self.w3)
404
- elif is_checksum_address(address):
405
- self.registry = SimpleRegistry(cast(ChecksumAddress, address), self.w3)
406
- elif is_ens_name(address):
407
- self._validate_set_ens()
408
- ens = cast(ENS, self.w3.ens)
409
- addr_lookup = ens.address(str(address))
410
- if not addr_lookup:
411
- raise NameNotFound(
412
- f"No address found after ENS lookup for name: {address!r}."
413
- )
414
- self.registry = SimpleRegistry(addr_lookup, self.w3)
415
- else:
416
- raise EthPMException(
417
- "Expected a canonical/checksummed address or ENS name for the address, "
418
- f"instead received {type(address)}."
419
- )
420
-
421
- def deploy_and_set_registry(self) -> ChecksumAddress:
422
- """
423
- Returns the address of a freshly deployed instance of `SimpleRegistry`
424
- and sets the newly deployed registry as the active registry on
425
- ``web3.pm.registry``.
426
-
427
- To tie your registry to an ENS name, use web3's ENS module, ie.
428
-
429
- .. code-block:: python
430
-
431
- w3.ens.setup_address(ens_name, w3.pm.registry.address)
432
- """
433
- self.registry = SimpleRegistry.deploy_new_instance(self.w3)
434
- return to_checksum_address(self.registry.address)
435
-
436
- def release_package(
437
- self, package_name: str, version: str, manifest_uri: URI
438
- ) -> bytes:
439
- """
440
- Returns the release id generated by releasing a package on the current registry.
441
- Requires ``web3.PM`` to have a registry set. Requires
442
- ``web3.eth.default_account`` to be the registry owner.
443
-
444
- * Parameters:
445
- * ``package_name``: Must be a valid package name, matching the
446
- given manifest.
447
- * ``version``: Must be a valid package version, matching the given manifest.
448
- * ``manifest_uri``: Must be a valid content-addressed URI. Currently,
449
- only IPFS and Github content-addressed URIs are
450
- supported.
451
-
452
- """
453
- validate_is_supported_manifest_uri(manifest_uri)
454
- raw_manifest = to_text(resolve_uri_contents(manifest_uri))
455
- validate_raw_manifest_format(raw_manifest)
456
- manifest = json.loads(raw_manifest)
457
- validate_manifest_against_schema(manifest)
458
- if package_name != manifest["name"]:
459
- raise ManifestValidationError(
460
- f"Provided package name: {package_name} does not match the package "
461
- f"name found in the manifest: {manifest['name']}."
462
- )
463
-
464
- if version != manifest["version"]:
465
- raise ManifestValidationError(
466
- f"Provided package version: {version} does not match the package "
467
- f"version found in the manifest: {manifest['version']}."
468
- )
469
-
470
- self._validate_set_registry()
471
- return self.registry._release(package_name, version, manifest_uri)
472
-
473
- @to_tuple
474
- def get_all_package_names(self) -> Iterable[str]:
475
- """
476
- Returns a tuple containing all the package names
477
- available on the current registry.
478
- """
479
- self._validate_set_registry()
480
- package_ids = self.registry._get_all_package_ids()
481
- for package_id in package_ids:
482
- yield self.registry._get_package_name(package_id)
483
-
484
- def get_package_count(self) -> int:
485
- """
486
- Returns the number of packages available on the current registry.
487
- """
488
- self._validate_set_registry()
489
- return self.registry._num_package_ids()
490
-
491
- def get_release_count(self, package_name: str) -> int:
492
- """
493
- Returns the number of releases of the given package name
494
- available on the current registry.
495
- """
496
- validate_package_name(package_name)
497
- self._validate_set_registry()
498
- return self.registry._num_release_ids(package_name)
499
-
500
- def get_release_id(self, package_name: str, version: str) -> bytes:
501
- """
502
- Returns the 32 byte identifier of a release for the given package
503
- name and version, if they are available on the current registry.
504
- """
505
- validate_package_name(package_name)
506
- validate_package_version(version)
507
- self._validate_set_registry()
508
- return self.registry._get_release_id(package_name, version)
509
-
510
- @to_tuple
511
- def get_all_package_releases(self, package_name: str) -> Iterable[Tuple[str, str]]:
512
- """
513
- Returns a tuple of release data (version, manifest_ur) for every release of the
514
- given package name available on the current registry.
515
- """
516
- validate_package_name(package_name)
517
- self._validate_set_registry()
518
- release_ids = self.registry._get_all_release_ids(package_name)
519
- for release_id in release_ids:
520
- release_data = self.registry._get_release_data(release_id)
521
- yield (release_data.version, release_data.manifest_uri)
522
-
523
- def get_release_id_data(self, release_id: bytes) -> ReleaseData:
524
- """
525
- Returns ``(package_name, version, manifest_uri)`` associated with the given
526
- release id, *if* it is available on the current registry.
527
-
528
- * Parameters:
529
- * ``release_id``: 32 byte release identifier
530
- """
531
- self._validate_set_registry()
532
- return self.registry._get_release_data(release_id)
533
-
534
- def get_release_data(self, package_name: str, version: str) -> ReleaseData:
535
- """
536
- Returns ``(package_name, version, manifest_uri)`` associated with the given
537
- package name and version, *if* they are published to the currently set registry.
538
-
539
- * Parameters:
540
- * ``name``: Must be a valid package name.
541
- * ``version``: Must be a valid package version.
542
- """
543
- validate_package_name(package_name)
544
- validate_package_version(version)
545
- self._validate_set_registry()
546
- release_id = self.registry._get_release_id(package_name, version)
547
- return self.get_release_id_data(release_id)
548
-
549
- def get_package(self, package_name: str, version: str) -> Package:
550
- """
551
- Returns a ``Package`` instance, generated by the ``manifest_uri``
552
- associated with the given package name and version, if they are
553
- published to the currently set registry.
554
-
555
- * Parameters:
556
- * ``name``: Must be a valid package name.
557
- * ``version``: Must be a valid package version.
558
- """
559
- validate_package_name(package_name)
560
- validate_package_version(version)
561
- self._validate_set_registry()
562
- release_data = self.get_release_data(package_name, version)
563
- return self.get_package_from_uri(URI(release_data.manifest_uri))
564
-
565
- def _validate_set_registry(self) -> None:
566
- try:
567
- self.registry
568
- except AttributeError:
569
- raise EthPMException(
570
- "web3.pm does not have a set registry. "
571
- "Please set registry with either: "
572
- "web3.pm.set_registry(address) or "
573
- "web3.pm.deploy_and_set_registry()"
574
- )
575
- if not isinstance(self.registry, ERC1319Registry):
576
- raise EthPMException(
577
- "web3.pm requires an instance of a subclass of ERC1319Registry "
578
- "to be set as the web3.pm.registry attribute. Instead found: "
579
- f"{type(self.registry)}."
580
- )
581
-
582
- def _validate_set_ens(self) -> None:
583
- if not self.w3:
584
- raise InvalidAddress(
585
- "Could not look up ENS address because no web3 connection available"
586
- )
587
- elif not self.w3.ens:
588
- raise InvalidAddress(
589
- "Could not look up ENS address because web3.ens is not set up"
590
- )
591
-
592
-
593
- def get_simple_registry_manifest() -> Dict[str, Any]:
594
- return json.loads((ASSETS_DIR / "simple-registry" / "v3.json").read_text())
595
-
596
-
597
- def validate_is_supported_manifest_uri(uri: URI) -> None:
598
- if not is_supported_content_addressed_uri(uri):
599
- raise ManifestValidationError(
600
- f"URI: {uri} is not a valid content-addressed URI. "
601
- "Currently only IPFS and Github content-addressed URIs are supported."
602
- )
web3/tools/__init__.py DELETED
@@ -1,4 +0,0 @@
1
- from .pytest_ethereum import (
2
- deployer,
3
- linker,
4
- )
File without changes