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.
- ens/__init__.py +13 -2
- ens/_normalization.py +4 -4
- ens/async_ens.py +31 -21
- ens/base_ens.py +3 -1
- ens/contract_data.py +2 -2
- ens/ens.py +14 -11
- ens/exceptions.py +16 -29
- ens/specs/nf.json +1 -1
- ens/specs/normalization_spec.json +1 -1
- ens/utils.py +33 -41
- web3/__init__.py +23 -12
- web3/_utils/abi.py +162 -274
- web3/_utils/async_transactions.py +34 -20
- web3/_utils/batching.py +217 -0
- web3/_utils/blocks.py +6 -2
- web3/_utils/caching/__init__.py +12 -0
- web3/_utils/caching/caching_utils.py +433 -0
- web3/_utils/caching/request_caching_validation.py +287 -0
- web3/_utils/compat/__init__.py +2 -3
- web3/_utils/contract_sources/compile_contracts.py +1 -1
- web3/_utils/contract_sources/contract_data/ambiguous_function_contract.py +42 -0
- web3/_utils/contract_sources/contract_data/arrays_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/bytes_contracts.py +5 -5
- web3/_utils/contract_sources/contract_data/constructor_contracts.py +7 -7
- web3/_utils/contract_sources/contract_data/contract_caller_tester.py +3 -3
- web3/_utils/contract_sources/contract_data/emitter_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/event_contracts.py +50 -5
- web3/_utils/contract_sources/contract_data/extended_resolver.py +3 -3
- web3/_utils/contract_sources/contract_data/fallback_function_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/function_name_tester_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/math_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/offchain_lookup.py +3 -3
- web3/_utils/contract_sources/contract_data/offchain_resolver.py +3 -3
- web3/_utils/contract_sources/contract_data/panic_errors_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/payable_tester.py +3 -3
- web3/_utils/contract_sources/contract_data/receive_function_contracts.py +5 -5
- web3/_utils/contract_sources/contract_data/reflector_contracts.py +3 -3
- web3/_utils/contract_sources/contract_data/revert_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/simple_resolver.py +3 -3
- web3/_utils/contract_sources/contract_data/storage_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/string_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/tuple_contracts.py +5 -5
- web3/_utils/contracts.py +172 -220
- web3/_utils/datatypes.py +5 -1
- web3/_utils/decorators.py +6 -1
- web3/_utils/empty.py +1 -1
- web3/_utils/encoding.py +16 -12
- web3/_utils/error_formatters_utils.py +5 -3
- web3/_utils/events.py +78 -72
- web3/_utils/fee_utils.py +1 -3
- web3/_utils/filters.py +24 -22
- web3/_utils/formatters.py +2 -2
- web3/_utils/http.py +8 -2
- web3/_utils/http_session_manager.py +314 -0
- web3/_utils/math.py +14 -15
- web3/_utils/method_formatters.py +161 -34
- web3/_utils/module.py +2 -1
- web3/_utils/module_testing/__init__.py +3 -2
- web3/_utils/module_testing/eth_module.py +736 -583
- web3/_utils/module_testing/go_ethereum_debug_module.py +128 -0
- web3/_utils/module_testing/module_testing_utils.py +81 -24
- web3/_utils/module_testing/persistent_connection_provider.py +702 -220
- web3/_utils/module_testing/utils.py +114 -33
- web3/_utils/module_testing/web3_module.py +438 -17
- web3/_utils/normalizers.py +13 -11
- web3/_utils/rpc_abi.py +10 -22
- web3/_utils/threads.py +8 -7
- web3/_utils/transactions.py +32 -25
- web3/_utils/type_conversion.py +5 -1
- web3/_utils/validation.py +20 -17
- web3/beacon/__init__.py +5 -0
- web3/beacon/api_endpoints.py +3 -0
- web3/beacon/async_beacon.py +29 -6
- web3/beacon/beacon.py +24 -6
- web3/contract/__init__.py +7 -0
- web3/contract/async_contract.py +285 -82
- web3/contract/base_contract.py +556 -258
- web3/contract/contract.py +295 -84
- web3/contract/utils.py +251 -55
- web3/datastructures.py +56 -41
- web3/eth/__init__.py +7 -0
- web3/eth/async_eth.py +89 -69
- web3/eth/base_eth.py +7 -3
- web3/eth/eth.py +43 -66
- web3/exceptions.py +158 -83
- web3/gas_strategies/time_based.py +8 -6
- web3/geth.py +53 -184
- web3/main.py +77 -43
- web3/manager.py +368 -101
- web3/method.py +43 -15
- web3/middleware/__init__.py +26 -8
- web3/middleware/attrdict.py +12 -22
- web3/middleware/base.py +55 -2
- web3/middleware/filter.py +45 -23
- web3/middleware/formatting.py +6 -3
- web3/middleware/names.py +4 -1
- web3/middleware/signing.py +15 -6
- web3/middleware/stalecheck.py +2 -1
- web3/module.py +62 -26
- web3/providers/__init__.py +21 -0
- web3/providers/async_base.py +93 -38
- web3/providers/base.py +85 -40
- web3/providers/eth_tester/__init__.py +5 -0
- web3/providers/eth_tester/defaults.py +2 -55
- web3/providers/eth_tester/main.py +57 -35
- web3/providers/eth_tester/middleware.py +16 -17
- web3/providers/ipc.py +42 -18
- web3/providers/legacy_websocket.py +27 -2
- web3/providers/persistent/__init__.py +7 -0
- web3/providers/persistent/async_ipc.py +61 -121
- web3/providers/persistent/persistent.py +324 -17
- web3/providers/persistent/persistent_connection.py +54 -5
- web3/providers/persistent/request_processor.py +136 -56
- web3/providers/persistent/subscription_container.py +56 -0
- web3/providers/persistent/subscription_manager.py +233 -0
- web3/providers/persistent/websocket.py +29 -92
- web3/providers/rpc/__init__.py +5 -0
- web3/providers/rpc/async_rpc.py +73 -18
- web3/providers/rpc/rpc.py +73 -30
- web3/providers/rpc/utils.py +1 -13
- web3/scripts/install_pre_releases.py +33 -0
- web3/scripts/parse_pygeth_version.py +16 -0
- web3/testing.py +4 -4
- web3/tracing.py +9 -5
- web3/types.py +141 -74
- web3/utils/__init__.py +64 -5
- web3/utils/abi.py +790 -10
- web3/utils/address.py +8 -0
- web3/utils/async_exception_handling.py +20 -11
- web3/utils/caching.py +34 -4
- web3/utils/exception_handling.py +9 -12
- web3/utils/subscriptions.py +285 -0
- {web3-7.0.0b1.dist-info → web3-7.7.0.dist-info}/LICENSE +1 -1
- web3-7.7.0.dist-info/METADATA +130 -0
- web3-7.7.0.dist-info/RECORD +171 -0
- {web3-7.0.0b1.dist-info → web3-7.7.0.dist-info}/WHEEL +1 -1
- {web3-7.0.0b1.dist-info → web3-7.7.0.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/_utils/caching.py +0 -155
- web3/_utils/contract_sources/contract_data/address_reflector.py +0 -29
- web3/_utils/module_testing/go_ethereum_personal_module.py +0 -300
- web3/_utils/request.py +0 -265
- web3/pm.py +0 -602
- web3/tools/__init__.py +0 -4
- web3/tools/benchmark/__init__.py +0 -0
- web3/tools/benchmark/main.py +0 -185
- web3/tools/benchmark/node.py +0 -126
- web3/tools/benchmark/reporting.py +0 -39
- web3/tools/benchmark/utils.py +0 -69
- 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/METADATA +0 -114
- web3-7.0.0b1.dist-info/RECORD +0 -280
- web3-7.0.0b1.dist-info/entry_points.txt +0 -2
- /web3/_utils/{function_identifiers.py → abi_element_identifiers.py} +0 -0
web3/geth.py
CHANGED
|
@@ -1,26 +1,17 @@
|
|
|
1
1
|
from typing import (
|
|
2
|
-
Any,
|
|
3
2
|
Awaitable,
|
|
4
3
|
Callable,
|
|
5
|
-
Dict,
|
|
6
4
|
List,
|
|
7
5
|
Optional,
|
|
6
|
+
Protocol,
|
|
8
7
|
Tuple,
|
|
8
|
+
Union,
|
|
9
9
|
)
|
|
10
10
|
|
|
11
|
-
from eth_typing.encoding import (
|
|
12
|
-
HexStr,
|
|
13
|
-
)
|
|
14
11
|
from eth_typing.evm import (
|
|
15
12
|
ChecksumAddress,
|
|
16
13
|
)
|
|
17
|
-
from hexbytes.main import (
|
|
18
|
-
HexBytes,
|
|
19
|
-
)
|
|
20
14
|
|
|
21
|
-
from web3._utils.compat import (
|
|
22
|
-
Protocol,
|
|
23
|
-
)
|
|
24
15
|
from web3._utils.rpc_abi import (
|
|
25
16
|
RPC,
|
|
26
17
|
)
|
|
@@ -32,14 +23,19 @@ from web3.module import (
|
|
|
32
23
|
Module,
|
|
33
24
|
)
|
|
34
25
|
from web3.types import (
|
|
26
|
+
CallTrace,
|
|
27
|
+
DiffModeTrace,
|
|
35
28
|
EnodeURI,
|
|
36
|
-
|
|
29
|
+
FourByteTrace,
|
|
37
30
|
NodeInfo,
|
|
31
|
+
OpcodeTrace,
|
|
38
32
|
Peer,
|
|
39
|
-
|
|
33
|
+
PrestateTrace,
|
|
34
|
+
TraceConfig,
|
|
40
35
|
TxPoolContent,
|
|
41
36
|
TxPoolInspect,
|
|
42
37
|
TxPoolStatus,
|
|
38
|
+
_Hash32,
|
|
43
39
|
)
|
|
44
40
|
|
|
45
41
|
|
|
@@ -53,66 +49,6 @@ class UnlockAccountWrapper(Protocol):
|
|
|
53
49
|
pass
|
|
54
50
|
|
|
55
51
|
|
|
56
|
-
class GethPersonal(Module):
|
|
57
|
-
"""
|
|
58
|
-
https://geth.ethereum.org/docs/interacting-with-geth/rpc/ns-personal
|
|
59
|
-
"""
|
|
60
|
-
|
|
61
|
-
is_async = False
|
|
62
|
-
|
|
63
|
-
ec_recover: Method[Callable[[str, HexStr], ChecksumAddress]] = Method(
|
|
64
|
-
RPC.personal_ecRecover,
|
|
65
|
-
mungers=[default_root_munger],
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
import_raw_key: Method[Callable[[str, str], ChecksumAddress]] = Method(
|
|
69
|
-
RPC.personal_importRawKey,
|
|
70
|
-
mungers=[default_root_munger],
|
|
71
|
-
)
|
|
72
|
-
|
|
73
|
-
list_accounts: Method[Callable[[], List[ChecksumAddress]]] = Method(
|
|
74
|
-
RPC.personal_listAccounts,
|
|
75
|
-
is_property=True,
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
list_wallets: Method[Callable[[], List[GethWallet]]] = Method(
|
|
79
|
-
RPC.personal_listWallets,
|
|
80
|
-
is_property=True,
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
send_transaction: Method[Callable[[TxParams, str], HexBytes]] = Method(
|
|
84
|
-
RPC.personal_sendTransaction,
|
|
85
|
-
mungers=[default_root_munger],
|
|
86
|
-
)
|
|
87
|
-
|
|
88
|
-
sign: Method[Callable[[str, ChecksumAddress, Optional[str]], HexStr]] = Method(
|
|
89
|
-
RPC.personal_sign,
|
|
90
|
-
mungers=[default_root_munger],
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
sign_typed_data: Method[
|
|
94
|
-
Callable[[Dict[str, Any], ChecksumAddress, str], HexStr]
|
|
95
|
-
] = Method(
|
|
96
|
-
RPC.personal_signTypedData,
|
|
97
|
-
mungers=[default_root_munger],
|
|
98
|
-
)
|
|
99
|
-
|
|
100
|
-
new_account: Method[Callable[[str], ChecksumAddress]] = Method(
|
|
101
|
-
RPC.personal_newAccount,
|
|
102
|
-
mungers=[default_root_munger],
|
|
103
|
-
)
|
|
104
|
-
|
|
105
|
-
lock_account: Method[Callable[[ChecksumAddress], bool]] = Method(
|
|
106
|
-
RPC.personal_lockAccount,
|
|
107
|
-
mungers=[default_root_munger],
|
|
108
|
-
)
|
|
109
|
-
|
|
110
|
-
unlock_account: Method[UnlockAccountWrapper] = Method(
|
|
111
|
-
RPC.personal_unlockAccount,
|
|
112
|
-
mungers=[default_root_munger],
|
|
113
|
-
)
|
|
114
|
-
|
|
115
|
-
|
|
116
52
|
class GethTxPool(Module):
|
|
117
53
|
"""
|
|
118
54
|
https://geth.ethereum.org/docs/interacting-with-geth/rpc/ns-txpool
|
|
@@ -205,10 +141,33 @@ class GethAdmin(Module):
|
|
|
205
141
|
)
|
|
206
142
|
|
|
207
143
|
|
|
144
|
+
class GethDebug(Module):
|
|
145
|
+
"""
|
|
146
|
+
https://geth.ethereum.org/docs/interacting-with-geth/rpc/ns-debug
|
|
147
|
+
"""
|
|
148
|
+
|
|
149
|
+
def trace_transaction_munger(
|
|
150
|
+
self,
|
|
151
|
+
transaction_hash: _Hash32,
|
|
152
|
+
trace_config: Optional[TraceConfig] = None,
|
|
153
|
+
) -> Tuple[_Hash32, TraceConfig]:
|
|
154
|
+
return (transaction_hash, trace_config)
|
|
155
|
+
|
|
156
|
+
trace_transaction: Method[
|
|
157
|
+
Callable[
|
|
158
|
+
...,
|
|
159
|
+
Union[CallTrace, PrestateTrace, OpcodeTrace, DiffModeTrace, FourByteTrace],
|
|
160
|
+
]
|
|
161
|
+
] = Method(
|
|
162
|
+
RPC.debug_traceTransaction,
|
|
163
|
+
mungers=[trace_transaction_munger],
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
|
|
208
167
|
class Geth(Module):
|
|
209
|
-
personal: GethPersonal
|
|
210
168
|
admin: GethAdmin
|
|
211
169
|
txpool: GethTxPool
|
|
170
|
+
debug: GethDebug
|
|
212
171
|
|
|
213
172
|
|
|
214
173
|
# --- async --- #
|
|
@@ -334,125 +293,35 @@ class AsyncGethAdmin(Module):
|
|
|
334
293
|
return await self._stop_ws()
|
|
335
294
|
|
|
336
295
|
|
|
337
|
-
class
|
|
296
|
+
class AsyncGethDebug(Module):
|
|
338
297
|
"""
|
|
339
|
-
https://geth.ethereum.org/docs/interacting-with-geth/rpc/ns-
|
|
298
|
+
https://geth.ethereum.org/docs/interacting-with-geth/rpc/ns-debug
|
|
340
299
|
"""
|
|
341
300
|
|
|
342
301
|
is_async = True
|
|
343
302
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
)
|
|
360
|
-
|
|
361
|
-
async def import_raw_key(
|
|
362
|
-
self, private_key: str, passphrase: str
|
|
363
|
-
) -> ChecksumAddress:
|
|
364
|
-
return await self._import_raw_key(private_key, passphrase)
|
|
365
|
-
|
|
366
|
-
# list_accounts and list_wallets
|
|
367
|
-
|
|
368
|
-
_list_accounts: Method[Callable[[], Awaitable[List[ChecksumAddress]]]] = Method(
|
|
369
|
-
RPC.personal_listAccounts,
|
|
370
|
-
is_property=True,
|
|
371
|
-
)
|
|
372
|
-
|
|
373
|
-
_list_wallets: Method[Callable[[], Awaitable[List[GethWallet]]]] = Method(
|
|
374
|
-
RPC.personal_listWallets,
|
|
375
|
-
is_property=True,
|
|
376
|
-
)
|
|
377
|
-
|
|
378
|
-
async def list_accounts(self) -> List[ChecksumAddress]:
|
|
379
|
-
return await self._list_accounts()
|
|
380
|
-
|
|
381
|
-
async def list_wallets(self) -> List[GethWallet]:
|
|
382
|
-
return await self._list_wallets()
|
|
383
|
-
|
|
384
|
-
# send_transaction
|
|
385
|
-
|
|
386
|
-
_send_transaction: Method[Callable[[TxParams, str], Awaitable[HexBytes]]] = Method(
|
|
387
|
-
RPC.personal_sendTransaction,
|
|
388
|
-
mungers=[default_root_munger],
|
|
389
|
-
)
|
|
390
|
-
|
|
391
|
-
async def send_transaction(
|
|
392
|
-
self, transaction: TxParams, passphrase: str
|
|
393
|
-
) -> HexBytes:
|
|
394
|
-
return await self._send_transaction(transaction, passphrase)
|
|
395
|
-
|
|
396
|
-
# sign and sign_typed_data
|
|
397
|
-
|
|
398
|
-
_sign: Method[
|
|
399
|
-
Callable[[str, ChecksumAddress, Optional[str]], Awaitable[HexStr]]
|
|
400
|
-
] = Method(
|
|
401
|
-
RPC.personal_sign,
|
|
402
|
-
mungers=[default_root_munger],
|
|
403
|
-
)
|
|
404
|
-
|
|
405
|
-
_sign_typed_data: Method[
|
|
406
|
-
Callable[[Dict[str, Any], ChecksumAddress, str], Awaitable[HexStr]]
|
|
407
|
-
] = Method(
|
|
408
|
-
RPC.personal_signTypedData,
|
|
409
|
-
mungers=[default_root_munger],
|
|
410
|
-
)
|
|
411
|
-
|
|
412
|
-
async def sign(
|
|
413
|
-
self, message: str, account: ChecksumAddress, passphrase: str
|
|
414
|
-
) -> HexStr:
|
|
415
|
-
return await self._sign(message, account, passphrase)
|
|
416
|
-
|
|
417
|
-
async def sign_typed_data(
|
|
418
|
-
self, message: Dict[str, Any], account: ChecksumAddress, passphrase: str
|
|
419
|
-
) -> HexStr:
|
|
420
|
-
return await self._sign_typed_data(message, account, passphrase)
|
|
421
|
-
|
|
422
|
-
# new_account, lock_account, and unlock_account
|
|
423
|
-
|
|
424
|
-
_new_account: Method[Callable[[str], Awaitable[ChecksumAddress]]] = Method(
|
|
425
|
-
RPC.personal_newAccount,
|
|
426
|
-
mungers=[default_root_munger],
|
|
427
|
-
)
|
|
428
|
-
|
|
429
|
-
_lock_account: Method[Callable[[ChecksumAddress], Awaitable[bool]]] = Method(
|
|
430
|
-
RPC.personal_lockAccount,
|
|
431
|
-
mungers=[default_root_munger],
|
|
432
|
-
)
|
|
433
|
-
|
|
434
|
-
_unlock_account: Method[
|
|
435
|
-
Callable[[ChecksumAddress, str, Optional[int]], Awaitable[bool]]
|
|
436
|
-
] = Method(
|
|
437
|
-
RPC.personal_unlockAccount,
|
|
438
|
-
mungers=[default_root_munger],
|
|
439
|
-
)
|
|
440
|
-
|
|
441
|
-
async def new_account(self, passphrase: str) -> ChecksumAddress:
|
|
442
|
-
return await self._new_account(passphrase)
|
|
443
|
-
|
|
444
|
-
async def lock_account(self, account: ChecksumAddress) -> bool:
|
|
445
|
-
return await self._lock_account(account)
|
|
446
|
-
|
|
447
|
-
async def unlock_account(
|
|
448
|
-
self, account: ChecksumAddress, passphrase: str, duration: Optional[int] = None
|
|
449
|
-
) -> bool:
|
|
450
|
-
return await self._unlock_account(account, passphrase, duration)
|
|
303
|
+
_trace_transaction: Method[
|
|
304
|
+
Callable[
|
|
305
|
+
...,
|
|
306
|
+
Awaitable[
|
|
307
|
+
Union[
|
|
308
|
+
CallTrace, PrestateTrace, OpcodeTrace, FourByteTrace, DiffModeTrace
|
|
309
|
+
]
|
|
310
|
+
],
|
|
311
|
+
]
|
|
312
|
+
] = Method(RPC.debug_traceTransaction)
|
|
313
|
+
|
|
314
|
+
async def trace_transaction(
|
|
315
|
+
self,
|
|
316
|
+
transaction_hash: _Hash32,
|
|
317
|
+
trace_config: Optional[TraceConfig] = None,
|
|
318
|
+
) -> Union[CallTrace, PrestateTrace, OpcodeTrace, FourByteTrace, DiffModeTrace]:
|
|
319
|
+
return await self._trace_transaction(transaction_hash, trace_config)
|
|
451
320
|
|
|
452
321
|
|
|
453
322
|
class AsyncGeth(Module):
|
|
454
323
|
is_async = True
|
|
455
324
|
|
|
456
|
-
personal: AsyncGethPersonal
|
|
457
325
|
admin: AsyncGethAdmin
|
|
458
326
|
txpool: AsyncGethTxPool
|
|
327
|
+
debug: AsyncGethDebug
|
web3/main.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import decimal
|
|
2
|
-
import warnings
|
|
3
2
|
from types import (
|
|
4
3
|
TracebackType,
|
|
5
4
|
)
|
|
@@ -35,6 +34,7 @@ from typing import (
|
|
|
35
34
|
TYPE_CHECKING,
|
|
36
35
|
Any,
|
|
37
36
|
AsyncIterator,
|
|
37
|
+
Callable,
|
|
38
38
|
Dict,
|
|
39
39
|
Generator,
|
|
40
40
|
List,
|
|
@@ -85,20 +85,28 @@ from web3.eth import (
|
|
|
85
85
|
AsyncEth,
|
|
86
86
|
Eth,
|
|
87
87
|
)
|
|
88
|
+
from web3.exceptions import (
|
|
89
|
+
Web3TypeError,
|
|
90
|
+
Web3ValidationError,
|
|
91
|
+
Web3ValueError,
|
|
92
|
+
)
|
|
88
93
|
from web3.geth import (
|
|
89
94
|
AsyncGeth,
|
|
90
95
|
AsyncGethAdmin,
|
|
91
|
-
|
|
96
|
+
AsyncGethDebug,
|
|
92
97
|
AsyncGethTxPool,
|
|
93
98
|
Geth,
|
|
94
99
|
GethAdmin,
|
|
95
|
-
|
|
100
|
+
GethDebug,
|
|
96
101
|
GethTxPool,
|
|
97
102
|
)
|
|
98
103
|
from web3.manager import (
|
|
99
104
|
RequestManager as DefaultRequestManager,
|
|
100
105
|
)
|
|
101
106
|
from web3.middleware.base import MiddlewareOnion
|
|
107
|
+
from web3.method import (
|
|
108
|
+
Method,
|
|
109
|
+
)
|
|
102
110
|
from web3.module import (
|
|
103
111
|
Module,
|
|
104
112
|
)
|
|
@@ -140,10 +148,14 @@ from web3.tracing import (
|
|
|
140
148
|
from web3.types import (
|
|
141
149
|
Wei,
|
|
142
150
|
)
|
|
151
|
+
from web3.providers.persistent.subscription_manager import (
|
|
152
|
+
SubscriptionManager,
|
|
153
|
+
)
|
|
143
154
|
|
|
144
155
|
if TYPE_CHECKING:
|
|
145
|
-
from web3.
|
|
156
|
+
from web3._utils.batching import RequestBatcher # noqa: F401
|
|
146
157
|
from web3._utils.empty import Empty # noqa: F401
|
|
158
|
+
from web3.providers.persistent import PersistentConnectionProvider # noqa: F401
|
|
147
159
|
|
|
148
160
|
|
|
149
161
|
def get_async_default_modules() -> Dict[str, Union[Type[Module], Sequence[Any]]]:
|
|
@@ -154,8 +166,8 @@ def get_async_default_modules() -> Dict[str, Union[Type[Module], Sequence[Any]]]
|
|
|
154
166
|
AsyncGeth,
|
|
155
167
|
{
|
|
156
168
|
"admin": AsyncGethAdmin,
|
|
157
|
-
"personal": AsyncGethPersonal,
|
|
158
169
|
"txpool": AsyncGethTxPool,
|
|
170
|
+
"debug": AsyncGethDebug,
|
|
159
171
|
},
|
|
160
172
|
),
|
|
161
173
|
}
|
|
@@ -169,8 +181,8 @@ def get_default_modules() -> Dict[str, Union[Type[Module], Sequence[Any]]]:
|
|
|
169
181
|
Geth,
|
|
170
182
|
{
|
|
171
183
|
"admin": GethAdmin,
|
|
172
|
-
"personal": GethPersonal,
|
|
173
184
|
"txpool": GethTxPool,
|
|
185
|
+
"debug": GethDebug,
|
|
174
186
|
},
|
|
175
187
|
),
|
|
176
188
|
"tracing": Tracing,
|
|
@@ -285,7 +297,7 @@ class BaseWeb3:
|
|
|
285
297
|
input_bytes = to_bytes(primitive, hexstr=hexstr, text=text)
|
|
286
298
|
return eth_utils_keccak(input_bytes)
|
|
287
299
|
|
|
288
|
-
raise
|
|
300
|
+
raise Web3TypeError(
|
|
289
301
|
f"You called keccak with first arg {primitive!r} and keywords "
|
|
290
302
|
f"{{'text': {text!r}, 'hexstr': {hexstr!r}}}. You must call it with "
|
|
291
303
|
"one of these approaches: keccak(text='txt'), keccak(hexstr='0x747874'), "
|
|
@@ -306,7 +318,7 @@ class BaseWeb3:
|
|
|
306
318
|
and list of corresponding values -- `[20, [-1, 5, 0], True]`
|
|
307
319
|
"""
|
|
308
320
|
if len(abi_types) != len(values):
|
|
309
|
-
raise
|
|
321
|
+
raise Web3ValueError(
|
|
310
322
|
"Length mismatch between provided abi types and values. Got "
|
|
311
323
|
f"{len(abi_types)} types and {len(values)} values."
|
|
312
324
|
)
|
|
@@ -338,29 +350,30 @@ class BaseWeb3:
|
|
|
338
350
|
def is_encodable(self, _type: TypeStr, value: Any) -> bool:
|
|
339
351
|
return self.codec.is_encodable(_type, value)
|
|
340
352
|
|
|
341
|
-
|
|
342
|
-
def pm(self) -> "PM":
|
|
343
|
-
if hasattr(self, "_pm"):
|
|
344
|
-
# ignored b/c property is dynamically set
|
|
345
|
-
# via enable_unstable_package_management_api
|
|
346
|
-
return self._pm
|
|
347
|
-
else:
|
|
348
|
-
raise AttributeError(
|
|
349
|
-
"The Package Management feature is disabled by default until "
|
|
350
|
-
"its API stabilizes. To use these features, please enable them by "
|
|
351
|
-
"running `w3.enable_unstable_package_management_api()` and try again."
|
|
352
|
-
)
|
|
353
|
+
# -- APIs for high-level requests -- #
|
|
353
354
|
|
|
354
|
-
def
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
355
|
+
def batch_requests(
|
|
356
|
+
self,
|
|
357
|
+
) -> "RequestBatcher[Method[Callable[..., Any]]]":
|
|
358
|
+
return self.manager._batch_requests()
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
def _validate_provider(
|
|
362
|
+
w3: Union["Web3", "AsyncWeb3"],
|
|
363
|
+
provider: Optional[Union[BaseProvider, AsyncBaseProvider]],
|
|
364
|
+
) -> None:
|
|
365
|
+
if provider is not None:
|
|
366
|
+
if isinstance(w3, AsyncWeb3) and not isinstance(provider, AsyncBaseProvider):
|
|
367
|
+
raise Web3ValidationError(
|
|
368
|
+
"Provider must be an instance of `AsyncBaseProvider` for "
|
|
369
|
+
f"`AsyncWeb3`, got {type(provider)}."
|
|
360
370
|
)
|
|
361
|
-
from web3.pm import PM # noqa: F811
|
|
362
371
|
|
|
363
|
-
|
|
372
|
+
if isinstance(w3, Web3) and not isinstance(provider, BaseProvider):
|
|
373
|
+
raise Web3ValidationError(
|
|
374
|
+
"Provider must be an instance of `BaseProvider` for `Web3`, "
|
|
375
|
+
f"got {type(provider)}."
|
|
376
|
+
)
|
|
364
377
|
|
|
365
378
|
|
|
366
379
|
class Web3(BaseWeb3):
|
|
@@ -378,14 +391,16 @@ class Web3(BaseWeb3):
|
|
|
378
391
|
def __init__(
|
|
379
392
|
self,
|
|
380
393
|
provider: Optional[BaseProvider] = None,
|
|
381
|
-
|
|
394
|
+
middleware: Optional[Sequence[Any]] = None,
|
|
382
395
|
modules: Optional[Dict[str, Union[Type[Module], Sequence[Any]]]] = None,
|
|
383
396
|
external_modules: Optional[
|
|
384
397
|
Dict[str, Union[Type[Module], Sequence[Any]]]
|
|
385
398
|
] = None,
|
|
386
399
|
ens: Union[ENS, "Empty"] = empty,
|
|
387
400
|
) -> None:
|
|
388
|
-
|
|
401
|
+
_validate_provider(self, provider)
|
|
402
|
+
|
|
403
|
+
self.manager = self.RequestManager(self, provider, middleware)
|
|
389
404
|
self.codec = ABICodec(build_strict_registry())
|
|
390
405
|
|
|
391
406
|
if modules is None:
|
|
@@ -446,14 +461,16 @@ class AsyncWeb3(BaseWeb3):
|
|
|
446
461
|
def __init__(
|
|
447
462
|
self,
|
|
448
463
|
provider: Optional[AsyncBaseProvider] = None,
|
|
449
|
-
|
|
464
|
+
middleware: Optional[Sequence[Any]] = None,
|
|
450
465
|
modules: Optional[Dict[str, Union[Type[Module], Sequence[Any]]]] = None,
|
|
451
466
|
external_modules: Optional[
|
|
452
467
|
Dict[str, Union[Type[Module], Sequence[Any]]]
|
|
453
468
|
] = None,
|
|
454
469
|
ens: Union[AsyncENS, "Empty"] = empty,
|
|
455
470
|
) -> None:
|
|
456
|
-
|
|
471
|
+
_validate_provider(self, provider)
|
|
472
|
+
|
|
473
|
+
self.manager = self.RequestManager(self, provider, middleware)
|
|
457
474
|
self.codec = ABICodec(build_strict_registry())
|
|
458
475
|
|
|
459
476
|
self._modules = get_async_default_modules() if modules is None else modules
|
|
@@ -494,12 +511,27 @@ class AsyncWeb3(BaseWeb3):
|
|
|
494
511
|
new_ens.w3 = self # set self object reference for ``AsyncENS.w3``
|
|
495
512
|
self._ens = new_ens
|
|
496
513
|
|
|
497
|
-
|
|
514
|
+
# -- persistent connection settings -- #
|
|
515
|
+
|
|
516
|
+
_subscription_manager: Optional[SubscriptionManager] = None
|
|
517
|
+
_persistent_connection: Optional["PersistentConnection"] = None
|
|
518
|
+
|
|
519
|
+
@property
|
|
520
|
+
@persistent_connection_provider_method()
|
|
521
|
+
def subscription_manager(self) -> SubscriptionManager:
|
|
522
|
+
"""
|
|
523
|
+
Access the subscription manager for the current PersistentConnectionProvider.
|
|
524
|
+
"""
|
|
525
|
+
if not self._subscription_manager:
|
|
526
|
+
self._subscription_manager = SubscriptionManager(self)
|
|
527
|
+
return self._subscription_manager
|
|
498
528
|
|
|
499
529
|
@property
|
|
500
530
|
@persistent_connection_provider_method()
|
|
501
531
|
def socket(self) -> PersistentConnection:
|
|
502
|
-
|
|
532
|
+
if self._persistent_connection is None:
|
|
533
|
+
self._persistent_connection = PersistentConnection(self)
|
|
534
|
+
return self._persistent_connection
|
|
503
535
|
|
|
504
536
|
# w3 = await AsyncWeb3(PersistentConnectionProvider(...))
|
|
505
537
|
@persistent_connection_provider_method(
|
|
@@ -508,7 +540,10 @@ class AsyncWeb3(BaseWeb3):
|
|
|
508
540
|
)
|
|
509
541
|
def __await__(self) -> Generator[Any, None, Self]:
|
|
510
542
|
async def __async_init__() -> Self:
|
|
511
|
-
|
|
543
|
+
provider = cast("PersistentConnectionProvider", self.provider)
|
|
544
|
+
await provider.connect()
|
|
545
|
+
# set signal handlers since not within a context manager
|
|
546
|
+
provider._set_signal_handlers()
|
|
512
547
|
return self
|
|
513
548
|
|
|
514
549
|
return __async_init__().__await__()
|
|
@@ -537,12 +572,11 @@ class AsyncWeb3(BaseWeb3):
|
|
|
537
572
|
"when instantiating via ``async for``."
|
|
538
573
|
)
|
|
539
574
|
async def __aiter__(self) -> AsyncIterator[Self]:
|
|
540
|
-
|
|
541
|
-
await self.provider.connect()
|
|
542
|
-
|
|
575
|
+
provider = self.provider
|
|
543
576
|
while True:
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
577
|
+
await provider.connect()
|
|
578
|
+
yield self
|
|
579
|
+
cast("PersistentConnectionProvider", provider).logger.error(
|
|
580
|
+
"Connection interrupted, attempting to reconnect..."
|
|
581
|
+
)
|
|
582
|
+
await provider.disconnect()
|