web3 6.20.2__py3-none-any.whl → 7.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ens/__init__.py +13 -2
- ens/_normalization.py +2 -17
- ens/async_ens.py +33 -21
- ens/base_ens.py +3 -1
- ens/ens.py +16 -11
- ens/exceptions.py +16 -29
- ens/specs/nf.json +1 -1
- ens/specs/normalization_spec.json +1 -1
- ens/utils.py +52 -63
- web3/__init__.py +20 -24
- web3/_utils/abi.py +115 -271
- web3/_utils/async_transactions.py +7 -4
- web3/_utils/batching.py +217 -0
- web3/_utils/blocks.py +6 -2
- web3/_utils/caching.py +128 -5
- web3/_utils/compat/__init__.py +2 -3
- web3/_utils/contract_sources/compile_contracts.py +1 -1
- 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 +5 -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 +130 -236
- web3/_utils/datatypes.py +5 -1
- web3/_utils/decorators.py +13 -23
- web3/_utils/empty.py +1 -1
- web3/_utils/encoding.py +16 -12
- web3/_utils/ens.py +2 -1
- web3/_utils/error_formatters_utils.py +5 -3
- web3/_utils/events.py +66 -69
- web3/_utils/fee_utils.py +1 -3
- web3/_utils/filters.py +24 -22
- web3/_utils/formatters.py +2 -2
- web3/_utils/http.py +5 -3
- web3/_utils/http_session_manager.py +303 -0
- web3/_utils/math.py +14 -15
- web3/_utils/method_formatters.py +34 -36
- web3/_utils/module.py +2 -1
- web3/_utils/module_testing/__init__.py +0 -3
- web3/_utils/module_testing/eth_module.py +695 -643
- web3/_utils/module_testing/module_testing_utils.py +61 -34
- web3/_utils/module_testing/persistent_connection_provider.py +56 -25
- web3/_utils/module_testing/utils.py +258 -0
- web3/_utils/module_testing/web3_module.py +438 -17
- web3/_utils/normalizers.py +13 -11
- web3/_utils/rpc_abi.py +5 -32
- web3/_utils/threads.py +8 -7
- web3/_utils/transactions.py +14 -12
- web3/_utils/type_conversion.py +5 -1
- web3/_utils/validation.py +17 -17
- web3/auto/gethdev.py +7 -2
- web3/beacon/__init__.py +6 -1
- web3/beacon/async_beacon.py +9 -5
- web3/beacon/{main.py → beacon.py} +7 -5
- web3/contract/__init__.py +7 -0
- web3/contract/async_contract.py +47 -46
- web3/contract/base_contract.py +183 -158
- web3/contract/contract.py +49 -43
- web3/contract/utils.py +203 -59
- web3/datastructures.py +79 -31
- web3/eth/__init__.py +7 -0
- web3/eth/async_eth.py +39 -51
- web3/eth/base_eth.py +17 -10
- web3/eth/eth.py +30 -68
- web3/exceptions.py +108 -82
- web3/gas_strategies/time_based.py +8 -6
- web3/geth.py +1 -254
- web3/main.py +75 -122
- web3/manager.py +316 -146
- web3/method.py +38 -31
- web3/middleware/__init__.py +67 -89
- web3/middleware/attrdict.py +36 -49
- web3/middleware/base.py +174 -0
- web3/middleware/buffered_gas_estimate.py +20 -21
- web3/middleware/filter.py +157 -117
- web3/middleware/formatting.py +124 -108
- web3/middleware/gas_price_strategy.py +20 -32
- web3/middleware/names.py +29 -26
- web3/middleware/proof_of_authority.py +68 -0
- web3/middleware/pythonic.py +2 -2
- web3/middleware/signing.py +74 -89
- web3/middleware/stalecheck.py +52 -79
- web3/middleware/validation.py +5 -13
- web3/module.py +54 -10
- web3/providers/__init__.py +10 -6
- web3/providers/async_base.py +117 -39
- web3/providers/auto.py +3 -3
- web3/providers/base.py +89 -33
- web3/providers/eth_tester/__init__.py +5 -0
- web3/providers/eth_tester/defaults.py +1 -64
- web3/providers/eth_tester/main.py +99 -31
- web3/providers/eth_tester/middleware.py +45 -73
- web3/providers/ipc.py +42 -46
- web3/providers/{websocket/websocket.py → legacy_websocket.py} +32 -7
- web3/providers/persistent/__init__.py +22 -0
- web3/providers/persistent/async_ipc.py +153 -0
- web3/providers/{persistent.py → persistent/persistent.py} +106 -25
- web3/providers/persistent/persistent_connection.py +84 -0
- web3/providers/{websocket → persistent}/request_processor.py +94 -32
- web3/providers/persistent/utils.py +43 -0
- web3/providers/{websocket/websocket_v2.py → persistent/websocket.py} +29 -28
- web3/providers/rpc/__init__.py +11 -0
- web3/providers/rpc/async_rpc.py +171 -0
- web3/providers/rpc/rpc.py +179 -0
- web3/providers/rpc/utils.py +92 -0
- web3/testing.py +4 -4
- web3/tools/benchmark/main.py +22 -22
- web3/tools/benchmark/node.py +2 -8
- web3/tools/benchmark/reporting.py +2 -2
- web3/tools/benchmark/utils.py +1 -1
- web3/tracing.py +9 -5
- web3/types.py +30 -107
- web3/utils/__init__.py +58 -5
- web3/utils/abi.py +575 -10
- web3/utils/async_exception_handling.py +19 -7
- web3/utils/caching.py +32 -13
- web3/utils/exception_handling.py +7 -5
- {web3-6.20.2.dist-info → web3-7.0.0.dist-info}/LICENSE +1 -1
- web3-7.0.0.dist-info/METADATA +112 -0
- web3-7.0.0.dist-info/RECORD +167 -0
- {web3-6.20.2.dist-info → web3-7.0.0.dist-info}/WHEEL +1 -1
- {web3-6.20.2.dist-info → web3-7.0.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/contract_sources/contract_data/address_reflector.py +0 -29
- web3/_utils/miner.py +0 -88
- web3/_utils/module_testing/go_ethereum_personal_module.py +0 -323
- web3/_utils/request.py +0 -265
- web3/middleware/abi.py +0 -11
- web3/middleware/async_cache.py +0 -99
- web3/middleware/cache.py +0 -374
- web3/middleware/exception_handling.py +0 -49
- web3/middleware/exception_retry_request.py +0 -188
- web3/middleware/fixture.py +0 -190
- web3/middleware/geth_poa.py +0 -81
- web3/middleware/normalize_request_parameters.py +0 -11
- web3/middleware/simulate_unmined_transaction.py +0 -43
- web3/pm.py +0 -602
- web3/providers/async_rpc.py +0 -99
- web3/providers/rpc.py +0 -98
- web3/providers/websocket/__init__.py +0 -11
- web3/providers/websocket/websocket_connection.py +0 -42
- 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-6.20.2.dist-info/METADATA +0 -103
- web3-6.20.2.dist-info/RECORD +0 -283
- web3-6.20.2.dist-info/entry_points.txt +0 -2
- /web3/_utils/{function_identifiers.py → abi_element_identifiers.py} +0 -0
web3/geth.py
CHANGED
|
@@ -1,44 +1,20 @@
|
|
|
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,
|
|
9
8
|
)
|
|
10
9
|
|
|
11
|
-
from eth_typing.encoding import (
|
|
12
|
-
HexStr,
|
|
13
|
-
)
|
|
14
10
|
from eth_typing.evm import (
|
|
15
11
|
ChecksumAddress,
|
|
16
12
|
)
|
|
17
|
-
from hexbytes.main import (
|
|
18
|
-
HexBytes,
|
|
19
|
-
)
|
|
20
13
|
|
|
21
|
-
from web3._utils.compat import (
|
|
22
|
-
Protocol,
|
|
23
|
-
)
|
|
24
|
-
from web3._utils.decorators import (
|
|
25
|
-
deprecate_method,
|
|
26
|
-
)
|
|
27
|
-
from web3._utils.miner import (
|
|
28
|
-
make_dag,
|
|
29
|
-
set_etherbase,
|
|
30
|
-
set_extra,
|
|
31
|
-
set_gas_price,
|
|
32
|
-
start,
|
|
33
|
-
start_auto_dag,
|
|
34
|
-
stop,
|
|
35
|
-
stop_auto_dag,
|
|
36
|
-
)
|
|
37
14
|
from web3._utils.rpc_abi import (
|
|
38
15
|
RPC,
|
|
39
16
|
)
|
|
40
17
|
from web3.method import (
|
|
41
|
-
DeprecatedMethod,
|
|
42
18
|
Method,
|
|
43
19
|
default_root_munger,
|
|
44
20
|
)
|
|
@@ -47,10 +23,8 @@ from web3.module import (
|
|
|
47
23
|
)
|
|
48
24
|
from web3.types import (
|
|
49
25
|
EnodeURI,
|
|
50
|
-
GethWallet,
|
|
51
26
|
NodeInfo,
|
|
52
27
|
Peer,
|
|
53
|
-
TxParams,
|
|
54
28
|
TxPoolContent,
|
|
55
29
|
TxPoolInspect,
|
|
56
30
|
TxPoolStatus,
|
|
@@ -67,90 +41,6 @@ class UnlockAccountWrapper(Protocol):
|
|
|
67
41
|
pass
|
|
68
42
|
|
|
69
43
|
|
|
70
|
-
GETH_PERSONAL_DEPRECATION_MSG = (
|
|
71
|
-
"Geth now uses `clef` for account and key management. This method will be removed "
|
|
72
|
-
"in web3.py `v7`."
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
class GethPersonal(Module):
|
|
77
|
-
"""
|
|
78
|
-
https://geth.ethereum.org/docs/interacting-with-geth/rpc/ns-personal
|
|
79
|
-
"""
|
|
80
|
-
|
|
81
|
-
is_async = False
|
|
82
|
-
|
|
83
|
-
_ec_recover: Method[Callable[[str, HexStr], ChecksumAddress]] = Method(
|
|
84
|
-
RPC.personal_ecRecover,
|
|
85
|
-
mungers=[default_root_munger],
|
|
86
|
-
)
|
|
87
|
-
ec_recover = DeprecatedMethod(_ec_recover, msg=GETH_PERSONAL_DEPRECATION_MSG)
|
|
88
|
-
|
|
89
|
-
_import_raw_key: Method[Callable[[str, str], ChecksumAddress]] = Method(
|
|
90
|
-
RPC.personal_importRawKey,
|
|
91
|
-
mungers=[default_root_munger],
|
|
92
|
-
)
|
|
93
|
-
import_raw_key = DeprecatedMethod(
|
|
94
|
-
_import_raw_key, msg=GETH_PERSONAL_DEPRECATION_MSG
|
|
95
|
-
)
|
|
96
|
-
|
|
97
|
-
_list_accounts: Method[Callable[[], List[ChecksumAddress]]] = Method(
|
|
98
|
-
RPC.personal_listAccounts,
|
|
99
|
-
is_property=True,
|
|
100
|
-
)
|
|
101
|
-
list_accounts = DeprecatedMethod(_list_accounts, msg=GETH_PERSONAL_DEPRECATION_MSG)
|
|
102
|
-
|
|
103
|
-
_list_wallets: Method[Callable[[], List[GethWallet]]] = Method(
|
|
104
|
-
RPC.personal_listWallets,
|
|
105
|
-
is_property=True,
|
|
106
|
-
)
|
|
107
|
-
list_wallets = DeprecatedMethod(_list_wallets, msg=GETH_PERSONAL_DEPRECATION_MSG)
|
|
108
|
-
|
|
109
|
-
_send_transaction: Method[Callable[[TxParams, str], HexBytes]] = Method(
|
|
110
|
-
RPC.personal_sendTransaction,
|
|
111
|
-
mungers=[default_root_munger],
|
|
112
|
-
)
|
|
113
|
-
send_transaction = DeprecatedMethod(
|
|
114
|
-
_send_transaction, msg=GETH_PERSONAL_DEPRECATION_MSG
|
|
115
|
-
)
|
|
116
|
-
|
|
117
|
-
_sign: Method[Callable[[str, ChecksumAddress, Optional[str]], HexStr]] = Method(
|
|
118
|
-
RPC.personal_sign,
|
|
119
|
-
mungers=[default_root_munger],
|
|
120
|
-
)
|
|
121
|
-
sign = DeprecatedMethod(_sign, msg=GETH_PERSONAL_DEPRECATION_MSG)
|
|
122
|
-
|
|
123
|
-
_sign_typed_data: Method[
|
|
124
|
-
Callable[[Dict[str, Any], ChecksumAddress, str], HexStr]
|
|
125
|
-
] = Method(
|
|
126
|
-
RPC.personal_signTypedData,
|
|
127
|
-
mungers=[default_root_munger],
|
|
128
|
-
)
|
|
129
|
-
sign_typed_data = DeprecatedMethod(
|
|
130
|
-
_sign_typed_data, msg=GETH_PERSONAL_DEPRECATION_MSG
|
|
131
|
-
)
|
|
132
|
-
|
|
133
|
-
_new_account: Method[Callable[[str], ChecksumAddress]] = Method(
|
|
134
|
-
RPC.personal_newAccount,
|
|
135
|
-
mungers=[default_root_munger],
|
|
136
|
-
)
|
|
137
|
-
new_account = DeprecatedMethod(_new_account, msg=GETH_PERSONAL_DEPRECATION_MSG)
|
|
138
|
-
|
|
139
|
-
_lock_account: Method[Callable[[ChecksumAddress], bool]] = Method(
|
|
140
|
-
RPC.personal_lockAccount,
|
|
141
|
-
mungers=[default_root_munger],
|
|
142
|
-
)
|
|
143
|
-
lock_account = DeprecatedMethod(_lock_account, msg=GETH_PERSONAL_DEPRECATION_MSG)
|
|
144
|
-
|
|
145
|
-
_unlock_account: Method[UnlockAccountWrapper] = Method(
|
|
146
|
-
RPC.personal_unlockAccount,
|
|
147
|
-
mungers=[default_root_munger],
|
|
148
|
-
)
|
|
149
|
-
unlock_account = DeprecatedMethod(
|
|
150
|
-
_unlock_account, msg=GETH_PERSONAL_DEPRECATION_MSG
|
|
151
|
-
)
|
|
152
|
-
|
|
153
|
-
|
|
154
44
|
class GethTxPool(Module):
|
|
155
45
|
"""
|
|
156
46
|
https://geth.ethereum.org/docs/interacting-with-geth/rpc/ns-txpool
|
|
@@ -243,23 +133,7 @@ class GethAdmin(Module):
|
|
|
243
133
|
)
|
|
244
134
|
|
|
245
135
|
|
|
246
|
-
class GethMiner(Module):
|
|
247
|
-
"""
|
|
248
|
-
https://geth.ethereum.org/docs/interacting-with-geth/rpc/ns-miner
|
|
249
|
-
"""
|
|
250
|
-
|
|
251
|
-
make_dag = make_dag
|
|
252
|
-
set_extra = set_extra
|
|
253
|
-
set_etherbase = set_etherbase
|
|
254
|
-
set_gas_price = set_gas_price
|
|
255
|
-
start = start
|
|
256
|
-
stop = stop
|
|
257
|
-
start_auto_dag = start_auto_dag
|
|
258
|
-
stop_auto_dag = stop_auto_dag
|
|
259
|
-
|
|
260
|
-
|
|
261
136
|
class Geth(Module):
|
|
262
|
-
personal: GethPersonal
|
|
263
137
|
admin: GethAdmin
|
|
264
138
|
txpool: GethTxPool
|
|
265
139
|
|
|
@@ -387,135 +261,8 @@ class AsyncGethAdmin(Module):
|
|
|
387
261
|
return await self._stop_ws()
|
|
388
262
|
|
|
389
263
|
|
|
390
|
-
class AsyncGethPersonal(Module):
|
|
391
|
-
"""
|
|
392
|
-
https://geth.ethereum.org/docs/interacting-with-geth/rpc/ns-personal
|
|
393
|
-
"""
|
|
394
|
-
|
|
395
|
-
is_async = True
|
|
396
|
-
|
|
397
|
-
# ec_recover
|
|
398
|
-
|
|
399
|
-
_ec_recover: Method[Callable[[str, HexStr], Awaitable[ChecksumAddress]]] = Method(
|
|
400
|
-
RPC.personal_ecRecover,
|
|
401
|
-
mungers=[default_root_munger],
|
|
402
|
-
)
|
|
403
|
-
|
|
404
|
-
@deprecate_method(deprecation_msg=GETH_PERSONAL_DEPRECATION_MSG)
|
|
405
|
-
async def ec_recover(self, message: str, signature: HexStr) -> ChecksumAddress:
|
|
406
|
-
return await self._ec_recover(message, signature)
|
|
407
|
-
|
|
408
|
-
# import_raw_key
|
|
409
|
-
|
|
410
|
-
_import_raw_key: Method[Callable[[str, str], Awaitable[ChecksumAddress]]] = Method(
|
|
411
|
-
RPC.personal_importRawKey,
|
|
412
|
-
mungers=[default_root_munger],
|
|
413
|
-
)
|
|
414
|
-
|
|
415
|
-
@deprecate_method(deprecation_msg=GETH_PERSONAL_DEPRECATION_MSG)
|
|
416
|
-
async def import_raw_key(
|
|
417
|
-
self, private_key: str, passphrase: str
|
|
418
|
-
) -> ChecksumAddress:
|
|
419
|
-
return await self._import_raw_key(private_key, passphrase)
|
|
420
|
-
|
|
421
|
-
# list_accounts and list_wallets
|
|
422
|
-
|
|
423
|
-
_list_accounts: Method[Callable[[], Awaitable[List[ChecksumAddress]]]] = Method(
|
|
424
|
-
RPC.personal_listAccounts,
|
|
425
|
-
is_property=True,
|
|
426
|
-
)
|
|
427
|
-
|
|
428
|
-
_list_wallets: Method[Callable[[], Awaitable[List[GethWallet]]]] = Method(
|
|
429
|
-
RPC.personal_listWallets,
|
|
430
|
-
is_property=True,
|
|
431
|
-
)
|
|
432
|
-
|
|
433
|
-
@deprecate_method(deprecation_msg=GETH_PERSONAL_DEPRECATION_MSG)
|
|
434
|
-
async def list_accounts(self) -> List[ChecksumAddress]:
|
|
435
|
-
return await self._list_accounts()
|
|
436
|
-
|
|
437
|
-
@deprecate_method(deprecation_msg=GETH_PERSONAL_DEPRECATION_MSG)
|
|
438
|
-
async def list_wallets(self) -> List[GethWallet]:
|
|
439
|
-
return await self._list_wallets()
|
|
440
|
-
|
|
441
|
-
# send_transaction
|
|
442
|
-
|
|
443
|
-
_send_transaction: Method[Callable[[TxParams, str], Awaitable[HexBytes]]] = Method(
|
|
444
|
-
RPC.personal_sendTransaction,
|
|
445
|
-
mungers=[default_root_munger],
|
|
446
|
-
)
|
|
447
|
-
|
|
448
|
-
@deprecate_method(deprecation_msg=GETH_PERSONAL_DEPRECATION_MSG)
|
|
449
|
-
async def send_transaction(
|
|
450
|
-
self, transaction: TxParams, passphrase: str
|
|
451
|
-
) -> HexBytes:
|
|
452
|
-
return await self._send_transaction(transaction, passphrase)
|
|
453
|
-
|
|
454
|
-
# sign and sign_typed_data
|
|
455
|
-
|
|
456
|
-
_sign: Method[
|
|
457
|
-
Callable[[str, ChecksumAddress, Optional[str]], Awaitable[HexStr]]
|
|
458
|
-
] = Method(
|
|
459
|
-
RPC.personal_sign,
|
|
460
|
-
mungers=[default_root_munger],
|
|
461
|
-
)
|
|
462
|
-
|
|
463
|
-
_sign_typed_data: Method[
|
|
464
|
-
Callable[[Dict[str, Any], ChecksumAddress, str], Awaitable[HexStr]]
|
|
465
|
-
] = Method(
|
|
466
|
-
RPC.personal_signTypedData,
|
|
467
|
-
mungers=[default_root_munger],
|
|
468
|
-
)
|
|
469
|
-
|
|
470
|
-
@deprecate_method(deprecation_msg=GETH_PERSONAL_DEPRECATION_MSG)
|
|
471
|
-
async def sign(
|
|
472
|
-
self, message: str, account: ChecksumAddress, passphrase: str
|
|
473
|
-
) -> HexStr:
|
|
474
|
-
return await self._sign(message, account, passphrase)
|
|
475
|
-
|
|
476
|
-
@deprecate_method(deprecation_msg=GETH_PERSONAL_DEPRECATION_MSG)
|
|
477
|
-
async def sign_typed_data(
|
|
478
|
-
self, message: Dict[str, Any], account: ChecksumAddress, passphrase: str
|
|
479
|
-
) -> HexStr:
|
|
480
|
-
return await self._sign_typed_data(message, account, passphrase)
|
|
481
|
-
|
|
482
|
-
# new_account, lock_account, and unlock_account
|
|
483
|
-
|
|
484
|
-
_new_account: Method[Callable[[str], Awaitable[ChecksumAddress]]] = Method(
|
|
485
|
-
RPC.personal_newAccount,
|
|
486
|
-
mungers=[default_root_munger],
|
|
487
|
-
)
|
|
488
|
-
|
|
489
|
-
_lock_account: Method[Callable[[ChecksumAddress], Awaitable[bool]]] = Method(
|
|
490
|
-
RPC.personal_lockAccount,
|
|
491
|
-
mungers=[default_root_munger],
|
|
492
|
-
)
|
|
493
|
-
|
|
494
|
-
_unlock_account: Method[
|
|
495
|
-
Callable[[ChecksumAddress, str, Optional[int]], Awaitable[bool]]
|
|
496
|
-
] = Method(
|
|
497
|
-
RPC.personal_unlockAccount,
|
|
498
|
-
mungers=[default_root_munger],
|
|
499
|
-
)
|
|
500
|
-
|
|
501
|
-
@deprecate_method(deprecation_msg=GETH_PERSONAL_DEPRECATION_MSG)
|
|
502
|
-
async def new_account(self, passphrase: str) -> ChecksumAddress:
|
|
503
|
-
return await self._new_account(passphrase)
|
|
504
|
-
|
|
505
|
-
@deprecate_method(deprecation_msg=GETH_PERSONAL_DEPRECATION_MSG)
|
|
506
|
-
async def lock_account(self, account: ChecksumAddress) -> bool:
|
|
507
|
-
return await self._lock_account(account)
|
|
508
|
-
|
|
509
|
-
@deprecate_method(deprecation_msg=GETH_PERSONAL_DEPRECATION_MSG)
|
|
510
|
-
async def unlock_account(
|
|
511
|
-
self, account: ChecksumAddress, passphrase: str, duration: Optional[int] = None
|
|
512
|
-
) -> bool:
|
|
513
|
-
return await self._unlock_account(account, passphrase, duration)
|
|
514
|
-
|
|
515
|
-
|
|
516
264
|
class AsyncGeth(Module):
|
|
517
265
|
is_async = True
|
|
518
266
|
|
|
519
|
-
personal: AsyncGethPersonal
|
|
520
267
|
admin: AsyncGethAdmin
|
|
521
268
|
txpool: AsyncGethTxPool
|
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,
|
|
@@ -86,22 +86,24 @@ from web3.eth import (
|
|
|
86
86
|
Eth,
|
|
87
87
|
)
|
|
88
88
|
from web3.exceptions import (
|
|
89
|
-
|
|
89
|
+
Web3TypeError,
|
|
90
|
+
Web3ValueError,
|
|
90
91
|
)
|
|
91
92
|
from web3.geth import (
|
|
92
93
|
AsyncGeth,
|
|
93
94
|
AsyncGethAdmin,
|
|
94
|
-
AsyncGethPersonal,
|
|
95
95
|
AsyncGethTxPool,
|
|
96
96
|
Geth,
|
|
97
97
|
GethAdmin,
|
|
98
|
-
GethMiner,
|
|
99
|
-
GethPersonal,
|
|
100
98
|
GethTxPool,
|
|
101
99
|
)
|
|
102
100
|
from web3.manager import (
|
|
103
101
|
RequestManager as DefaultRequestManager,
|
|
104
102
|
)
|
|
103
|
+
from web3.middleware.base import MiddlewareOnion
|
|
104
|
+
from web3.method import (
|
|
105
|
+
Method,
|
|
106
|
+
)
|
|
105
107
|
from web3.module import (
|
|
106
108
|
Module,
|
|
107
109
|
)
|
|
@@ -114,25 +116,25 @@ from web3.providers import (
|
|
|
114
116
|
BaseProvider,
|
|
115
117
|
)
|
|
116
118
|
from web3.providers.eth_tester import (
|
|
119
|
+
AsyncEthereumTesterProvider,
|
|
117
120
|
EthereumTesterProvider,
|
|
118
121
|
)
|
|
119
122
|
from web3.providers.ipc import (
|
|
120
123
|
IPCProvider,
|
|
121
124
|
)
|
|
122
|
-
from web3.providers.
|
|
123
|
-
|
|
124
|
-
)
|
|
125
|
-
from web3.providers.persistent import (
|
|
126
|
-
PersistentConnectionProvider,
|
|
125
|
+
from web3.providers.persistent.utils import (
|
|
126
|
+
persistent_connection_provider_method,
|
|
127
127
|
)
|
|
128
128
|
from web3.providers.rpc import (
|
|
129
|
+
AsyncHTTPProvider,
|
|
129
130
|
HTTPProvider,
|
|
130
131
|
)
|
|
131
|
-
from web3.providers
|
|
132
|
-
|
|
132
|
+
from web3.providers import (
|
|
133
|
+
LegacyWebSocketProvider,
|
|
134
|
+
WebSocketProvider,
|
|
133
135
|
)
|
|
134
|
-
from web3.providers.
|
|
135
|
-
|
|
136
|
+
from web3.providers.persistent import (
|
|
137
|
+
PersistentConnection,
|
|
136
138
|
)
|
|
137
139
|
from web3.testing import (
|
|
138
140
|
Testing,
|
|
@@ -141,14 +143,13 @@ from web3.tracing import (
|
|
|
141
143
|
Tracing,
|
|
142
144
|
)
|
|
143
145
|
from web3.types import (
|
|
144
|
-
AsyncMiddlewareOnion,
|
|
145
|
-
MiddlewareOnion,
|
|
146
146
|
Wei,
|
|
147
147
|
)
|
|
148
148
|
|
|
149
149
|
if TYPE_CHECKING:
|
|
150
|
-
from web3.
|
|
150
|
+
from web3._utils.batching import RequestBatcher # noqa: F401
|
|
151
151
|
from web3._utils.empty import Empty # noqa: F401
|
|
152
|
+
from web3.providers.persistent import PersistentConnectionProvider # noqa: F401
|
|
152
153
|
|
|
153
154
|
|
|
154
155
|
def get_async_default_modules() -> Dict[str, Union[Type[Module], Sequence[Any]]]:
|
|
@@ -159,7 +160,6 @@ def get_async_default_modules() -> Dict[str, Union[Type[Module], Sequence[Any]]]
|
|
|
159
160
|
AsyncGeth,
|
|
160
161
|
{
|
|
161
162
|
"admin": AsyncGethAdmin,
|
|
162
|
-
"personal": AsyncGethPersonal,
|
|
163
163
|
"txpool": AsyncGethTxPool,
|
|
164
164
|
},
|
|
165
165
|
),
|
|
@@ -174,8 +174,6 @@ def get_default_modules() -> Dict[str, Union[Type[Module], Sequence[Any]]]:
|
|
|
174
174
|
Geth,
|
|
175
175
|
{
|
|
176
176
|
"admin": GethAdmin,
|
|
177
|
-
"miner": GethMiner,
|
|
178
|
-
"personal": GethPersonal,
|
|
179
177
|
"txpool": GethTxPool,
|
|
180
178
|
},
|
|
181
179
|
),
|
|
@@ -187,21 +185,19 @@ def get_default_modules() -> Dict[str, Union[Type[Module], Sequence[Any]]]:
|
|
|
187
185
|
class BaseWeb3:
|
|
188
186
|
_strict_bytes_type_checking = True
|
|
189
187
|
|
|
190
|
-
# Providers
|
|
191
|
-
HTTPProvider = HTTPProvider
|
|
192
|
-
IPCProvider = IPCProvider
|
|
193
|
-
EthereumTesterProvider = EthereumTesterProvider
|
|
194
|
-
WebsocketProvider = WebsocketProvider
|
|
195
|
-
AsyncHTTPProvider = AsyncHTTPProvider
|
|
196
|
-
|
|
197
188
|
# Managers
|
|
198
189
|
RequestManager = DefaultRequestManager
|
|
190
|
+
manager: DefaultRequestManager
|
|
199
191
|
|
|
200
192
|
# mypy types
|
|
201
193
|
eth: Union[Eth, AsyncEth]
|
|
202
194
|
net: Union[Net, AsyncNet]
|
|
203
195
|
geth: Union[Geth, AsyncGeth]
|
|
204
196
|
|
|
197
|
+
@property
|
|
198
|
+
def middleware_onion(self) -> MiddlewareOnion:
|
|
199
|
+
return cast(MiddlewareOnion, self.manager.middleware_onion)
|
|
200
|
+
|
|
205
201
|
# Encoding and Decoding
|
|
206
202
|
@staticmethod
|
|
207
203
|
@wraps(to_bytes)
|
|
@@ -293,7 +289,7 @@ class BaseWeb3:
|
|
|
293
289
|
input_bytes = to_bytes(primitive, hexstr=hexstr, text=text)
|
|
294
290
|
return eth_utils_keccak(input_bytes)
|
|
295
291
|
|
|
296
|
-
raise
|
|
292
|
+
raise Web3TypeError(
|
|
297
293
|
f"You called keccak with first arg {primitive!r} and keywords "
|
|
298
294
|
f"{{'text': {text!r}, 'hexstr': {hexstr!r}}}. You must call it with "
|
|
299
295
|
"one of these approaches: keccak(text='txt'), keccak(hexstr='0x747874'), "
|
|
@@ -314,7 +310,7 @@ class BaseWeb3:
|
|
|
314
310
|
and list of corresponding values -- `[20, [-1, 5, 0], True]`
|
|
315
311
|
"""
|
|
316
312
|
if len(abi_types) != len(values):
|
|
317
|
-
raise
|
|
313
|
+
raise Web3ValueError(
|
|
318
314
|
"Length mismatch between provided abi types and values. Got "
|
|
319
315
|
f"{len(abi_types)} types and {len(values)} values."
|
|
320
316
|
)
|
|
@@ -346,29 +342,12 @@ class BaseWeb3:
|
|
|
346
342
|
def is_encodable(self, _type: TypeStr, value: Any) -> bool:
|
|
347
343
|
return self.codec.is_encodable(_type, value)
|
|
348
344
|
|
|
349
|
-
|
|
350
|
-
def pm(self) -> "PM":
|
|
351
|
-
if hasattr(self, "_pm"):
|
|
352
|
-
# ignored b/c property is dynamically set
|
|
353
|
-
# via enable_unstable_package_management_api
|
|
354
|
-
return self._pm
|
|
355
|
-
else:
|
|
356
|
-
raise AttributeError(
|
|
357
|
-
"The Package Management feature is disabled by default until "
|
|
358
|
-
"its API stabilizes. To use these features, please enable them by "
|
|
359
|
-
"running `w3.enable_unstable_package_management_api()` and try again."
|
|
360
|
-
)
|
|
361
|
-
|
|
362
|
-
def enable_unstable_package_management_api(self) -> None:
|
|
363
|
-
if not hasattr(self, "_pm"):
|
|
364
|
-
warnings.warn(
|
|
365
|
-
"The ``ethPM`` module is no longer being maintained and will be "
|
|
366
|
-
"deprecated with ``web3.py`` version 7",
|
|
367
|
-
UserWarning,
|
|
368
|
-
)
|
|
369
|
-
from web3.pm import PM # noqa: F811
|
|
345
|
+
# -- APIs for high-level requests -- #
|
|
370
346
|
|
|
371
|
-
|
|
347
|
+
def batch_requests(
|
|
348
|
+
self,
|
|
349
|
+
) -> "RequestBatcher[Method[Callable[..., Any]]]":
|
|
350
|
+
return self.manager._batch_requests()
|
|
372
351
|
|
|
373
352
|
|
|
374
353
|
class Web3(BaseWeb3):
|
|
@@ -377,17 +356,23 @@ class Web3(BaseWeb3):
|
|
|
377
356
|
net: Net
|
|
378
357
|
geth: Geth
|
|
379
358
|
|
|
359
|
+
# Providers
|
|
360
|
+
HTTPProvider = HTTPProvider
|
|
361
|
+
IPCProvider = IPCProvider
|
|
362
|
+
EthereumTesterProvider = EthereumTesterProvider
|
|
363
|
+
LegacyWebSocketProvider = LegacyWebSocketProvider
|
|
364
|
+
|
|
380
365
|
def __init__(
|
|
381
366
|
self,
|
|
382
367
|
provider: Optional[BaseProvider] = None,
|
|
383
|
-
|
|
368
|
+
middleware: Optional[Sequence[Any]] = None,
|
|
384
369
|
modules: Optional[Dict[str, Union[Type[Module], Sequence[Any]]]] = None,
|
|
385
370
|
external_modules: Optional[
|
|
386
371
|
Dict[str, Union[Type[Module], Sequence[Any]]]
|
|
387
372
|
] = None,
|
|
388
373
|
ens: Union[ENS, "Empty"] = empty,
|
|
389
374
|
) -> None:
|
|
390
|
-
self.manager = self.RequestManager(self, provider,
|
|
375
|
+
self.manager = self.RequestManager(self, provider, middleware)
|
|
391
376
|
self.codec = ABICodec(build_strict_registry())
|
|
392
377
|
|
|
393
378
|
if modules is None:
|
|
@@ -403,10 +388,6 @@ class Web3(BaseWeb3):
|
|
|
403
388
|
def is_connected(self, show_traceback: bool = False) -> bool:
|
|
404
389
|
return self.provider.is_connected(show_traceback)
|
|
405
390
|
|
|
406
|
-
@property
|
|
407
|
-
def middleware_onion(self) -> MiddlewareOnion:
|
|
408
|
-
return cast(MiddlewareOnion, self.manager.middleware_onion)
|
|
409
|
-
|
|
410
391
|
@property
|
|
411
392
|
def provider(self) -> BaseProvider:
|
|
412
393
|
return cast(BaseProvider, self.manager.provider)
|
|
@@ -444,25 +425,28 @@ class AsyncWeb3(BaseWeb3):
|
|
|
444
425
|
net: AsyncNet
|
|
445
426
|
geth: AsyncGeth
|
|
446
427
|
|
|
428
|
+
# Providers
|
|
429
|
+
AsyncHTTPProvider = AsyncHTTPProvider
|
|
430
|
+
WebSocketProvider = WebSocketProvider
|
|
431
|
+
AsyncEthereumTesterProvider = AsyncEthereumTesterProvider
|
|
432
|
+
|
|
447
433
|
def __init__(
|
|
448
434
|
self,
|
|
449
435
|
provider: Optional[AsyncBaseProvider] = None,
|
|
450
|
-
|
|
436
|
+
middleware: Optional[Sequence[Any]] = None,
|
|
451
437
|
modules: Optional[Dict[str, Union[Type[Module], Sequence[Any]]]] = None,
|
|
452
438
|
external_modules: Optional[
|
|
453
439
|
Dict[str, Union[Type[Module], Sequence[Any]]]
|
|
454
440
|
] = None,
|
|
455
441
|
ens: Union[AsyncENS, "Empty"] = empty,
|
|
456
|
-
**kwargs: Any,
|
|
457
442
|
) -> None:
|
|
458
|
-
self.manager = self.RequestManager(self, provider,
|
|
443
|
+
self.manager = self.RequestManager(self, provider, middleware)
|
|
459
444
|
self.codec = ABICodec(build_strict_registry())
|
|
460
445
|
|
|
461
|
-
if modules is None
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
self.attach_modules(modules)
|
|
446
|
+
self._modules = get_async_default_modules() if modules is None else modules
|
|
447
|
+
self._external_modules = None if external_modules is None else external_modules
|
|
465
448
|
|
|
449
|
+
self.attach_modules(self._modules)
|
|
466
450
|
if external_modules is not None:
|
|
467
451
|
self.attach_modules(external_modules)
|
|
468
452
|
|
|
@@ -471,10 +455,6 @@ class AsyncWeb3(BaseWeb3):
|
|
|
471
455
|
async def is_connected(self, show_traceback: bool = False) -> bool:
|
|
472
456
|
return await self.provider.is_connected(show_traceback)
|
|
473
457
|
|
|
474
|
-
@property
|
|
475
|
-
def middleware_onion(self) -> AsyncMiddlewareOnion:
|
|
476
|
-
return cast(AsyncMiddlewareOnion, self.manager.middleware_onion)
|
|
477
|
-
|
|
478
458
|
@property
|
|
479
459
|
def provider(self) -> AsyncBaseProvider:
|
|
480
460
|
return cast(AsyncBaseProvider, self.manager.provider)
|
|
@@ -501,68 +481,35 @@ class AsyncWeb3(BaseWeb3):
|
|
|
501
481
|
new_ens.w3 = self # set self object reference for ``AsyncENS.w3``
|
|
502
482
|
self._ens = new_ens
|
|
503
483
|
|
|
504
|
-
|
|
505
|
-
def persistent_websocket(
|
|
506
|
-
provider: PersistentConnectionProvider,
|
|
507
|
-
middlewares: Optional[Sequence[Any]] = None,
|
|
508
|
-
modules: Optional[Dict[str, Union[Type[Module], Sequence[Any]]]] = None,
|
|
509
|
-
external_modules: Optional[
|
|
510
|
-
Dict[str, Union[Type[Module], Sequence[Any]]]
|
|
511
|
-
] = None,
|
|
512
|
-
ens: Union[AsyncENS, "Empty"] = empty,
|
|
513
|
-
) -> "_PersistentConnectionWeb3":
|
|
514
|
-
"""
|
|
515
|
-
Establish a persistent connection via websockets to a websocket provider using
|
|
516
|
-
a ``PersistentConnectionProvider`` instance.
|
|
517
|
-
"""
|
|
518
|
-
return _PersistentConnectionWeb3(
|
|
519
|
-
provider,
|
|
520
|
-
middlewares,
|
|
521
|
-
modules,
|
|
522
|
-
external_modules,
|
|
523
|
-
ens,
|
|
524
|
-
)
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
class _PersistentConnectionWeb3(AsyncWeb3):
|
|
528
|
-
provider: PersistentConnectionProvider
|
|
529
|
-
|
|
530
|
-
# w3 = AsyncWeb3.persistent_websocket(provider)
|
|
531
|
-
# await w3.provider.connect()
|
|
532
|
-
def __init__(
|
|
533
|
-
self,
|
|
534
|
-
provider: PersistentConnectionProvider = None,
|
|
535
|
-
middlewares: Optional[Sequence[Any]] = None,
|
|
536
|
-
modules: Optional[Dict[str, Union[Type[Module], Sequence[Any]]]] = None,
|
|
537
|
-
external_modules: Optional[
|
|
538
|
-
Dict[str, Union[Type[Module], Sequence[Any]]]
|
|
539
|
-
] = None,
|
|
540
|
-
ens: Union[AsyncENS, "Empty"] = empty,
|
|
541
|
-
) -> None:
|
|
542
|
-
if not isinstance(provider, PersistentConnectionProvider):
|
|
543
|
-
raise Web3ValidationError(
|
|
544
|
-
"Provider must inherit from PersistentConnectionProvider class."
|
|
545
|
-
)
|
|
546
|
-
AsyncWeb3.__init__(self, provider, middlewares, modules, external_modules, ens)
|
|
547
|
-
self.ws = WebsocketConnection(self)
|
|
484
|
+
# -- persistent connection methods -- #
|
|
548
485
|
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
486
|
+
@property
|
|
487
|
+
@persistent_connection_provider_method()
|
|
488
|
+
def socket(self) -> PersistentConnection:
|
|
489
|
+
return PersistentConnection(self)
|
|
490
|
+
|
|
491
|
+
# w3 = await AsyncWeb3(PersistentConnectionProvider(...))
|
|
492
|
+
@persistent_connection_provider_method(
|
|
493
|
+
"Provider must inherit from ``PersistentConnectionProvider`` class "
|
|
494
|
+
"when instantiating via ``await``."
|
|
495
|
+
)
|
|
496
|
+
def __await__(self) -> Generator[Any, None, Self]:
|
|
553
497
|
async def __async_init__() -> Self:
|
|
554
|
-
|
|
555
|
-
await self.provider.connect()
|
|
556
|
-
|
|
498
|
+
await self.provider.connect()
|
|
557
499
|
return self
|
|
558
500
|
|
|
559
501
|
return __async_init__().__await__()
|
|
560
502
|
|
|
561
|
-
# async with
|
|
503
|
+
# async with AsyncWeb3(PersistentConnectionProvider(...)) as w3:
|
|
504
|
+
@persistent_connection_provider_method(
|
|
505
|
+
message="Provider must inherit from ``PersistentConnectionProvider`` class "
|
|
506
|
+
"when instantiating via ``async with``."
|
|
507
|
+
)
|
|
562
508
|
async def __aenter__(self) -> Self:
|
|
563
509
|
await self.provider.connect()
|
|
564
510
|
return self
|
|
565
511
|
|
|
512
|
+
@persistent_connection_provider_method()
|
|
566
513
|
async def __aexit__(
|
|
567
514
|
self,
|
|
568
515
|
exc_type: Type[BaseException],
|
|
@@ -571,11 +518,17 @@ class _PersistentConnectionWeb3(AsyncWeb3):
|
|
|
571
518
|
) -> None:
|
|
572
519
|
await self.provider.disconnect()
|
|
573
520
|
|
|
574
|
-
# async for w3 in
|
|
521
|
+
# async for w3 in AsyncWeb3(PersistentConnectionProvider(...)):
|
|
522
|
+
@persistent_connection_provider_method(
|
|
523
|
+
message="Provider must inherit from ``PersistentConnectionProvider`` class "
|
|
524
|
+
"when instantiating via ``async for``."
|
|
525
|
+
)
|
|
575
526
|
async def __aiter__(self) -> AsyncIterator[Self]:
|
|
576
527
|
provider = self.provider
|
|
577
528
|
while True:
|
|
578
529
|
await provider.connect()
|
|
579
530
|
yield self
|
|
580
|
-
provider.logger.error(
|
|
531
|
+
cast("PersistentConnectionProvider", provider).logger.error(
|
|
532
|
+
"Connection interrupted, attempting to reconnect..."
|
|
533
|
+
)
|
|
581
534
|
await provider.disconnect()
|