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
|
@@ -2,9 +2,12 @@ from typing import (
|
|
|
2
2
|
TYPE_CHECKING,
|
|
3
3
|
Any,
|
|
4
4
|
Callable,
|
|
5
|
+
Coroutine,
|
|
5
6
|
Dict,
|
|
7
|
+
Literal,
|
|
6
8
|
Optional,
|
|
7
9
|
Union,
|
|
10
|
+
cast,
|
|
8
11
|
)
|
|
9
12
|
|
|
10
13
|
from eth_abi import (
|
|
@@ -17,16 +20,6 @@ from eth_utils import (
|
|
|
17
20
|
is_bytes,
|
|
18
21
|
)
|
|
19
22
|
|
|
20
|
-
from web3._utils.compat import (
|
|
21
|
-
Literal,
|
|
22
|
-
)
|
|
23
|
-
from web3.middleware.attrdict import (
|
|
24
|
-
async_attrdict_middleware,
|
|
25
|
-
attrdict_middleware,
|
|
26
|
-
)
|
|
27
|
-
from web3.middleware.buffered_gas_estimate import (
|
|
28
|
-
async_buffered_gas_estimate_middleware,
|
|
29
|
-
)
|
|
30
23
|
from web3.providers import (
|
|
31
24
|
BaseProvider,
|
|
32
25
|
)
|
|
@@ -39,9 +32,14 @@ from web3.types import (
|
|
|
39
32
|
RPCResponse,
|
|
40
33
|
)
|
|
41
34
|
|
|
35
|
+
from ...exceptions import (
|
|
36
|
+
Web3TypeError,
|
|
37
|
+
)
|
|
38
|
+
from ...middleware import (
|
|
39
|
+
async_combine_middleware,
|
|
40
|
+
combine_middleware,
|
|
41
|
+
)
|
|
42
42
|
from .middleware import (
|
|
43
|
-
async_default_transaction_fields_middleware,
|
|
44
|
-
async_ethereum_tester_middleware,
|
|
45
43
|
default_transaction_fields_middleware,
|
|
46
44
|
ethereum_tester_middleware,
|
|
47
45
|
)
|
|
@@ -50,13 +48,22 @@ if TYPE_CHECKING:
|
|
|
50
48
|
from eth_tester import EthereumTester # noqa: F401
|
|
51
49
|
from eth_tester.backends.base import BaseChainBackend # noqa: F401
|
|
52
50
|
|
|
51
|
+
from web3 import ( # noqa: F401
|
|
52
|
+
AsyncWeb3,
|
|
53
|
+
Web3,
|
|
54
|
+
)
|
|
55
|
+
from web3.middleware.base import ( # noqa: F401
|
|
56
|
+
Middleware,
|
|
57
|
+
MiddlewareOnion,
|
|
58
|
+
Web3Middleware,
|
|
59
|
+
)
|
|
60
|
+
|
|
53
61
|
|
|
54
62
|
class AsyncEthereumTesterProvider(AsyncBaseProvider):
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
async_ethereum_tester_middleware,
|
|
63
|
+
_current_request_id = 0
|
|
64
|
+
_middleware = (
|
|
65
|
+
default_transaction_fields_middleware,
|
|
66
|
+
ethereum_tester_middleware,
|
|
60
67
|
)
|
|
61
68
|
|
|
62
69
|
def __init__(self) -> None:
|
|
@@ -74,16 +81,43 @@ class AsyncEthereumTesterProvider(AsyncBaseProvider):
|
|
|
74
81
|
self.ethereum_tester = EthereumTester()
|
|
75
82
|
self.api_endpoints = API_ENDPOINTS
|
|
76
83
|
|
|
84
|
+
async def request_func(
|
|
85
|
+
self, async_w3: "AsyncWeb3", middleware_onion: "MiddlewareOnion"
|
|
86
|
+
) -> Callable[..., Coroutine[Any, Any, RPCResponse]]:
|
|
87
|
+
# override the request_func to add the ethereum_tester_middleware
|
|
88
|
+
|
|
89
|
+
middleware = middleware_onion.as_tuple_of_middleware() + tuple(self._middleware)
|
|
90
|
+
|
|
91
|
+
cache_key = self._request_func_cache[0]
|
|
92
|
+
if cache_key != middleware:
|
|
93
|
+
self._request_func_cache = (
|
|
94
|
+
middleware,
|
|
95
|
+
await async_combine_middleware(
|
|
96
|
+
middleware=middleware,
|
|
97
|
+
async_w3=async_w3,
|
|
98
|
+
provider_request_fn=self.make_request,
|
|
99
|
+
),
|
|
100
|
+
)
|
|
101
|
+
return self._request_func_cache[-1]
|
|
102
|
+
|
|
77
103
|
async def make_request(self, method: RPCEndpoint, params: Any) -> RPCResponse:
|
|
78
|
-
|
|
104
|
+
response = _make_request(
|
|
105
|
+
method,
|
|
106
|
+
params,
|
|
107
|
+
self.api_endpoints,
|
|
108
|
+
self.ethereum_tester,
|
|
109
|
+
repr(self._current_request_id),
|
|
110
|
+
)
|
|
111
|
+
self._current_request_id += 1
|
|
112
|
+
return response
|
|
79
113
|
|
|
80
114
|
async def is_connected(self, show_traceback: bool = False) -> Literal[True]:
|
|
81
115
|
return True
|
|
82
116
|
|
|
83
117
|
|
|
84
118
|
class EthereumTesterProvider(BaseProvider):
|
|
85
|
-
|
|
86
|
-
|
|
119
|
+
_current_request_id = 0
|
|
120
|
+
_middleware = (
|
|
87
121
|
default_transaction_fields_middleware,
|
|
88
122
|
ethereum_tester_middleware,
|
|
89
123
|
)
|
|
@@ -98,6 +132,7 @@ class EthereumTesterProvider(BaseProvider):
|
|
|
98
132
|
] = None,
|
|
99
133
|
) -> None:
|
|
100
134
|
# do not import eth_tester until runtime, it is not a default dependency
|
|
135
|
+
super().__init__()
|
|
101
136
|
from eth_tester import EthereumTester # noqa: F811
|
|
102
137
|
from eth_tester.backends.base import (
|
|
103
138
|
BaseChainBackend,
|
|
@@ -110,7 +145,7 @@ class EthereumTesterProvider(BaseProvider):
|
|
|
110
145
|
elif isinstance(ethereum_tester, BaseChainBackend):
|
|
111
146
|
self.ethereum_tester = EthereumTester(ethereum_tester)
|
|
112
147
|
else:
|
|
113
|
-
raise
|
|
148
|
+
raise Web3TypeError(
|
|
114
149
|
"Expected ethereum_tester to be of type `eth_tester.EthereumTester` or "
|
|
115
150
|
"a subclass of `eth_tester.backends.base.BaseChainBackend`, "
|
|
116
151
|
f"instead received {type(ethereum_tester)}. "
|
|
@@ -129,24 +164,52 @@ class EthereumTesterProvider(BaseProvider):
|
|
|
129
164
|
else:
|
|
130
165
|
self.api_endpoints = api_endpoints
|
|
131
166
|
|
|
167
|
+
def request_func(
|
|
168
|
+
self, w3: "Web3", middleware_onion: "MiddlewareOnion"
|
|
169
|
+
) -> Callable[..., RPCResponse]:
|
|
170
|
+
# override the request_func to add the ethereum_tester_middleware
|
|
171
|
+
|
|
172
|
+
middleware = middleware_onion.as_tuple_of_middleware() + tuple(self._middleware)
|
|
173
|
+
|
|
174
|
+
cache_key = self._request_func_cache[0]
|
|
175
|
+
if cache_key != middleware:
|
|
176
|
+
self._request_func_cache = (
|
|
177
|
+
middleware,
|
|
178
|
+
combine_middleware(
|
|
179
|
+
middleware=middleware,
|
|
180
|
+
w3=w3,
|
|
181
|
+
provider_request_fn=self.make_request,
|
|
182
|
+
),
|
|
183
|
+
)
|
|
184
|
+
return self._request_func_cache[-1]
|
|
185
|
+
|
|
132
186
|
def make_request(self, method: RPCEndpoint, params: Any) -> RPCResponse:
|
|
133
|
-
|
|
187
|
+
response = _make_request(
|
|
188
|
+
method,
|
|
189
|
+
params,
|
|
190
|
+
self.api_endpoints,
|
|
191
|
+
self.ethereum_tester,
|
|
192
|
+
repr(self._current_request_id),
|
|
193
|
+
)
|
|
194
|
+
self._current_request_id += 1
|
|
195
|
+
return response
|
|
134
196
|
|
|
135
197
|
def is_connected(self, show_traceback: bool = False) -> Literal[True]:
|
|
136
198
|
return True
|
|
137
199
|
|
|
138
200
|
|
|
139
|
-
def _make_response(result: Any, message: str = "") -> RPCResponse:
|
|
201
|
+
def _make_response(result: Any, response_id: str, message: str = "") -> RPCResponse:
|
|
140
202
|
if isinstance(result, Exception):
|
|
141
|
-
return
|
|
203
|
+
return cast(
|
|
204
|
+
RPCResponse,
|
|
142
205
|
{
|
|
143
|
-
"id":
|
|
206
|
+
"id": response_id,
|
|
144
207
|
"jsonrpc": "2.0",
|
|
145
|
-
"error": RPCError
|
|
146
|
-
}
|
|
208
|
+
"error": cast(RPCError, {"code": -32601, "message": message}),
|
|
209
|
+
},
|
|
147
210
|
)
|
|
148
211
|
|
|
149
|
-
return RPCResponse
|
|
212
|
+
return cast(RPCResponse, {"id": response_id, "jsonrpc": "2.0", "result": result})
|
|
150
213
|
|
|
151
214
|
|
|
152
215
|
def _make_request(
|
|
@@ -154,6 +217,7 @@ def _make_request(
|
|
|
154
217
|
params: Any,
|
|
155
218
|
api_endpoints: Dict[str, Dict[str, Any]],
|
|
156
219
|
ethereum_tester_instance: "EthereumTester",
|
|
220
|
+
request_id: str,
|
|
157
221
|
) -> RPCResponse:
|
|
158
222
|
# do not import eth_tester derivatives until runtime,
|
|
159
223
|
# it is not a default dependency
|
|
@@ -166,11 +230,15 @@ def _make_request(
|
|
|
166
230
|
try:
|
|
167
231
|
delegator = api_endpoints[namespace][endpoint]
|
|
168
232
|
except KeyError as e:
|
|
169
|
-
return _make_response(e, f"Unknown RPC Endpoint: {method}")
|
|
233
|
+
return _make_response(e, request_id, message=f"Unknown RPC Endpoint: {method}")
|
|
170
234
|
try:
|
|
171
235
|
response = delegator(ethereum_tester_instance, params)
|
|
172
236
|
except NotImplementedError as e:
|
|
173
|
-
return _make_response(
|
|
237
|
+
return _make_response(
|
|
238
|
+
e,
|
|
239
|
+
request_id,
|
|
240
|
+
message=f"RPC Endpoint has not been implemented: {method}",
|
|
241
|
+
)
|
|
174
242
|
except TransactionFailed as e:
|
|
175
243
|
first_arg = e.args[0]
|
|
176
244
|
try:
|
|
@@ -187,4 +255,4 @@ def _make_request(
|
|
|
187
255
|
reason = first_arg
|
|
188
256
|
raise TransactionFailed(f"execution reverted: {reason}")
|
|
189
257
|
else:
|
|
190
|
-
return _make_response(response)
|
|
258
|
+
return _make_response(response, request_id)
|
|
@@ -40,17 +40,14 @@ from web3._utils.formatters import (
|
|
|
40
40
|
from web3._utils.method_formatters import (
|
|
41
41
|
apply_list_to_array_formatter,
|
|
42
42
|
)
|
|
43
|
-
from web3.middleware import (
|
|
44
|
-
|
|
43
|
+
from web3.middleware.base import (
|
|
44
|
+
Web3Middleware,
|
|
45
45
|
)
|
|
46
46
|
from web3.middleware.formatting import (
|
|
47
|
-
|
|
47
|
+
FormattingMiddlewareBuilder,
|
|
48
48
|
)
|
|
49
49
|
from web3.types import (
|
|
50
|
-
AsyncMiddlewareCoroutine,
|
|
51
|
-
Middleware,
|
|
52
50
|
RPCEndpoint,
|
|
53
|
-
RPCResponse,
|
|
54
51
|
TxParams,
|
|
55
52
|
)
|
|
56
53
|
|
|
@@ -62,7 +59,7 @@ if TYPE_CHECKING:
|
|
|
62
59
|
|
|
63
60
|
|
|
64
61
|
def is_named_block(value: Any) -> bool:
|
|
65
|
-
return value in {"latest", "earliest", "
|
|
62
|
+
return value in {"latest", "earliest", "safe", "finalized"}
|
|
66
63
|
|
|
67
64
|
|
|
68
65
|
def is_hexstr(value: Any) -> bool:
|
|
@@ -95,7 +92,7 @@ TRANSACTION_REQUEST_FORMATTERS = {
|
|
|
95
92
|
"maxFeePerGas": to_integer_if_hex,
|
|
96
93
|
"maxPriorityFeePerGas": to_integer_if_hex,
|
|
97
94
|
"accessList": apply_list_to_array_formatter(
|
|
98
|
-
|
|
95
|
+
apply_key_map({"storageKeys": "storage_keys"})
|
|
99
96
|
),
|
|
100
97
|
}
|
|
101
98
|
transaction_request_formatter = apply_formatters_to_dict(TRANSACTION_REQUEST_FORMATTERS)
|
|
@@ -113,14 +110,14 @@ filter_request_remapper = apply_key_map(FILTER_REQUEST_KEY_MAPPING)
|
|
|
113
110
|
|
|
114
111
|
|
|
115
112
|
FILTER_REQUEST_FORMATTERS = {
|
|
116
|
-
"
|
|
117
|
-
"
|
|
113
|
+
"from_block": to_integer_if_hex,
|
|
114
|
+
"to_block": to_integer_if_hex,
|
|
118
115
|
}
|
|
119
116
|
filter_request_formatter = apply_formatters_to_dict(FILTER_REQUEST_FORMATTERS)
|
|
120
117
|
|
|
121
118
|
filter_request_transformer = compose(
|
|
122
|
-
filter_request_remapper,
|
|
123
119
|
filter_request_formatter,
|
|
120
|
+
filter_request_remapper,
|
|
124
121
|
)
|
|
125
122
|
|
|
126
123
|
|
|
@@ -138,6 +135,7 @@ TRANSACTION_RESULT_KEY_MAPPING = {
|
|
|
138
135
|
"max_priority_fee_per_gas": "maxPriorityFeePerGas",
|
|
139
136
|
"transaction_hash": "transactionHash",
|
|
140
137
|
"transaction_index": "transactionIndex",
|
|
138
|
+
"data": "input",
|
|
141
139
|
}
|
|
142
140
|
transaction_result_remapper = apply_key_map(TRANSACTION_RESULT_KEY_MAPPING)
|
|
143
141
|
|
|
@@ -201,7 +199,6 @@ BLOCK_RESULT_KEY_MAPPING = {
|
|
|
201
199
|
block_result_remapper = apply_key_map(BLOCK_RESULT_KEY_MAPPING)
|
|
202
200
|
|
|
203
201
|
BLOCK_RESULT_FORMATTERS = {
|
|
204
|
-
"logsBloom": integer_to_hex,
|
|
205
202
|
"withdrawals": apply_list_to_array_formatter(
|
|
206
203
|
apply_key_map({"validator_index": "validatorIndex"}),
|
|
207
204
|
),
|
|
@@ -288,21 +285,14 @@ request_formatters = {
|
|
|
288
285
|
),
|
|
289
286
|
# EVM
|
|
290
287
|
RPCEndpoint("evm_revert"): apply_formatters_to_args(hex_to_integer),
|
|
291
|
-
# Personal
|
|
292
|
-
RPCEndpoint("personal_sendTransaction"): apply_formatters_to_args(
|
|
293
|
-
transaction_request_transformer,
|
|
294
|
-
identity,
|
|
295
|
-
),
|
|
296
288
|
}
|
|
297
289
|
|
|
298
290
|
result_formatters: Optional[Dict[RPCEndpoint, Callable[..., Any]]] = {
|
|
299
291
|
RPCEndpoint("eth_getBlockByHash"): apply_formatter_if(
|
|
300
|
-
is_dict,
|
|
301
|
-
compose(block_result_remapper, block_result_formatter),
|
|
292
|
+
is_dict, compose(block_result_remapper, block_result_formatter)
|
|
302
293
|
),
|
|
303
294
|
RPCEndpoint("eth_getBlockByNumber"): apply_formatter_if(
|
|
304
|
-
is_dict,
|
|
305
|
-
compose(block_result_remapper, block_result_formatter),
|
|
295
|
+
is_dict, compose(block_result_remapper, block_result_formatter)
|
|
306
296
|
),
|
|
307
297
|
RPCEndpoint("eth_getBlockTransactionCountByHash"): apply_formatter_if(
|
|
308
298
|
is_dict,
|
|
@@ -343,15 +333,8 @@ result_formatters: Optional[Dict[RPCEndpoint, Callable[..., Any]]] = {
|
|
|
343
333
|
}
|
|
344
334
|
|
|
345
335
|
|
|
346
|
-
ethereum_tester_middleware = construct_formatting_middleware(
|
|
347
|
-
request_formatters=request_formatters, result_formatters=result_formatters
|
|
348
|
-
)
|
|
349
|
-
|
|
350
|
-
|
|
351
336
|
def guess_from(w3: "Web3", _: TxParams) -> ChecksumAddress:
|
|
352
|
-
if w3.eth.
|
|
353
|
-
return w3.eth.coinbase
|
|
354
|
-
elif w3.eth.accounts and len(w3.eth.accounts) > 0:
|
|
337
|
+
if w3.eth.accounts and len(w3.eth.accounts) > 0:
|
|
355
338
|
return w3.eth.accounts[0]
|
|
356
339
|
|
|
357
340
|
return None
|
|
@@ -369,48 +352,14 @@ def fill_default(
|
|
|
369
352
|
return assoc(transaction, field, guess_val)
|
|
370
353
|
|
|
371
354
|
|
|
372
|
-
def default_transaction_fields_middleware(
|
|
373
|
-
make_request: Callable[[RPCEndpoint, Any], Any], w3: "Web3"
|
|
374
|
-
) -> Callable[[RPCEndpoint, Any], RPCResponse]:
|
|
375
|
-
def middleware(method: RPCEndpoint, params: Any) -> RPCResponse:
|
|
376
|
-
if method in (
|
|
377
|
-
"eth_call",
|
|
378
|
-
"eth_estimateGas",
|
|
379
|
-
"eth_sendTransaction",
|
|
380
|
-
"eth_createAccessList",
|
|
381
|
-
):
|
|
382
|
-
fill_default_from = fill_default("from", guess_from, w3)
|
|
383
|
-
filled_transaction = pipe(
|
|
384
|
-
params[0],
|
|
385
|
-
fill_default_from,
|
|
386
|
-
)
|
|
387
|
-
return make_request(method, [filled_transaction] + list(params)[1:])
|
|
388
|
-
else:
|
|
389
|
-
return make_request(method, params)
|
|
390
|
-
|
|
391
|
-
return middleware
|
|
392
|
-
|
|
393
|
-
|
|
394
355
|
# --- async --- #
|
|
395
356
|
|
|
396
357
|
|
|
397
|
-
async def async_ethereum_tester_middleware( # type: ignore
|
|
398
|
-
make_request, web3: "AsyncWeb3"
|
|
399
|
-
) -> Middleware:
|
|
400
|
-
middleware = await async_construct_formatting_middleware(
|
|
401
|
-
request_formatters=request_formatters, result_formatters=result_formatters
|
|
402
|
-
)
|
|
403
|
-
return await middleware(make_request, web3)
|
|
404
|
-
|
|
405
|
-
|
|
406
358
|
async def async_guess_from(
|
|
407
359
|
async_w3: "AsyncWeb3", _: TxParams
|
|
408
360
|
) -> Optional[ChecksumAddress]:
|
|
409
|
-
coinbase = await async_w3.eth.coinbase
|
|
410
361
|
accounts = await async_w3.eth.accounts
|
|
411
|
-
if
|
|
412
|
-
return coinbase
|
|
413
|
-
elif accounts is not None and len(accounts) > 0:
|
|
362
|
+
if accounts is not None and len(accounts) > 0:
|
|
414
363
|
return accounts[0]
|
|
415
364
|
return None
|
|
416
365
|
|
|
@@ -430,20 +379,43 @@ async def async_fill_default(
|
|
|
430
379
|
return assoc(transaction, field, guess_val)
|
|
431
380
|
|
|
432
381
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
382
|
+
# --- define middleware --- #
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
class DefaultTransactionFieldsMiddleware(Web3Middleware):
|
|
386
|
+
def request_processor(self, method: "RPCEndpoint", params: Any) -> Any:
|
|
437
387
|
if method in (
|
|
438
388
|
"eth_call",
|
|
439
389
|
"eth_estimateGas",
|
|
440
390
|
"eth_sendTransaction",
|
|
391
|
+
"eth_createAccessList",
|
|
392
|
+
):
|
|
393
|
+
fill_default_from = fill_default("from", guess_from, self._w3)
|
|
394
|
+
filled_transaction = pipe(
|
|
395
|
+
params[0],
|
|
396
|
+
fill_default_from,
|
|
397
|
+
)
|
|
398
|
+
params = [filled_transaction] + list(params)[1:]
|
|
399
|
+
return method, params
|
|
400
|
+
|
|
401
|
+
# --- async --- #
|
|
402
|
+
|
|
403
|
+
async def async_request_processor(self, method: "RPCEndpoint", params: Any) -> Any:
|
|
404
|
+
if method in (
|
|
405
|
+
"eth_call",
|
|
406
|
+
"eth_estimateGas",
|
|
407
|
+
"eth_sendTransaction",
|
|
408
|
+
"eth_createAccessList",
|
|
441
409
|
):
|
|
442
410
|
filled_transaction = await async_fill_default(
|
|
443
|
-
"from", async_guess_from,
|
|
411
|
+
"from", async_guess_from, self._w3, params[0]
|
|
444
412
|
)
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
413
|
+
params = [filled_transaction] + list(params)[1:]
|
|
414
|
+
|
|
415
|
+
return method, params
|
|
416
|
+
|
|
448
417
|
|
|
449
|
-
|
|
418
|
+
ethereum_tester_middleware = FormattingMiddlewareBuilder.build(
|
|
419
|
+
request_formatters=request_formatters, result_formatters=result_formatters
|
|
420
|
+
)
|
|
421
|
+
default_transaction_fields_middleware = DefaultTransactionFieldsMiddleware
|
web3/providers/ipc.py
CHANGED
|
@@ -14,9 +14,11 @@ from types import (
|
|
|
14
14
|
)
|
|
15
15
|
from typing import (
|
|
16
16
|
Any,
|
|
17
|
-
|
|
17
|
+
List,
|
|
18
|
+
Tuple,
|
|
18
19
|
Type,
|
|
19
20
|
Union,
|
|
21
|
+
cast,
|
|
20
22
|
)
|
|
21
23
|
|
|
22
24
|
from web3._utils.threads import (
|
|
@@ -27,6 +29,13 @@ from web3.types import (
|
|
|
27
29
|
RPCResponse,
|
|
28
30
|
)
|
|
29
31
|
|
|
32
|
+
from .._utils.batching import (
|
|
33
|
+
sort_batch_response_by_response_ids,
|
|
34
|
+
)
|
|
35
|
+
from ..exceptions import (
|
|
36
|
+
Web3TypeError,
|
|
37
|
+
Web3ValueError,
|
|
38
|
+
)
|
|
30
39
|
from .base import (
|
|
31
40
|
JSONBaseProvider,
|
|
32
41
|
)
|
|
@@ -86,62 +95,40 @@ class PersistantSocket:
|
|
|
86
95
|
return self.sock
|
|
87
96
|
|
|
88
97
|
|
|
89
|
-
def get_default_ipc_path() ->
|
|
98
|
+
def get_default_ipc_path() -> str:
|
|
90
99
|
if sys.platform == "darwin":
|
|
91
|
-
|
|
92
|
-
os.path.join("~", "Library", "Ethereum", "geth.ipc")
|
|
93
|
-
)
|
|
94
|
-
if os.path.exists(ipc_path):
|
|
95
|
-
return ipc_path
|
|
96
|
-
return None
|
|
100
|
+
return os.path.expanduser(os.path.join("~", "Library", "Ethereum", "geth.ipc"))
|
|
97
101
|
|
|
98
102
|
elif sys.platform.startswith("linux") or sys.platform.startswith("freebsd"):
|
|
99
|
-
|
|
100
|
-
if os.path.exists(ipc_path):
|
|
101
|
-
return ipc_path
|
|
102
|
-
return None
|
|
103
|
+
return os.path.expanduser(os.path.join("~", ".ethereum", "geth.ipc"))
|
|
103
104
|
|
|
104
105
|
elif sys.platform == "win32":
|
|
105
|
-
|
|
106
|
-
if os.path.exists(ipc_path):
|
|
107
|
-
return ipc_path
|
|
108
|
-
return None
|
|
106
|
+
return r"\\.\pipe\geth.ipc"
|
|
109
107
|
|
|
110
108
|
else:
|
|
111
|
-
raise
|
|
112
|
-
f"Unsupported platform '{sys.platform}'.
|
|
109
|
+
raise Web3ValueError(
|
|
110
|
+
f"Unsupported platform '{sys.platform}'. Only darwin/linux/win32/"
|
|
113
111
|
"freebsd are supported. You must specify the ipc_path"
|
|
114
112
|
)
|
|
115
113
|
|
|
116
114
|
|
|
117
|
-
def get_dev_ipc_path() ->
|
|
115
|
+
def get_dev_ipc_path() -> str:
|
|
118
116
|
if os.environ.get("WEB3_PROVIDER_URI", ""):
|
|
119
|
-
|
|
120
|
-
if os.path.exists(ipc_path):
|
|
121
|
-
return ipc_path
|
|
122
|
-
return None
|
|
117
|
+
return os.environ.get("WEB3_PROVIDER_URI")
|
|
123
118
|
|
|
124
119
|
elif sys.platform == "darwin":
|
|
125
120
|
tmpdir = os.environ.get("TMPDIR", "")
|
|
126
|
-
|
|
127
|
-
if os.path.exists(ipc_path):
|
|
128
|
-
return ipc_path
|
|
129
|
-
return None
|
|
121
|
+
return os.path.expanduser(os.path.join(tmpdir, "geth.ipc"))
|
|
130
122
|
|
|
131
123
|
elif sys.platform.startswith("linux") or sys.platform.startswith("freebsd"):
|
|
132
|
-
|
|
133
|
-
if os.path.exists(ipc_path):
|
|
134
|
-
return ipc_path
|
|
135
|
-
return None
|
|
124
|
+
return os.path.expanduser(os.path.join("/tmp", "geth.ipc"))
|
|
136
125
|
|
|
137
126
|
elif sys.platform == "win32":
|
|
138
|
-
|
|
139
|
-
if os.path.exists(ipc_path):
|
|
140
|
-
return ipc_path
|
|
127
|
+
return r"\\.\pipe\geth.ipc"
|
|
141
128
|
|
|
142
129
|
else:
|
|
143
|
-
raise
|
|
144
|
-
f"Unsupported platform '{sys.platform}'.
|
|
130
|
+
raise Web3ValueError(
|
|
131
|
+
f"Unsupported platform '{sys.platform}'. Only darwin/linux/win32/"
|
|
145
132
|
"freebsd are supported. You must specify the ipc_path"
|
|
146
133
|
)
|
|
147
134
|
|
|
@@ -153,8 +140,7 @@ class IPCProvider(JSONBaseProvider):
|
|
|
153
140
|
def __init__(
|
|
154
141
|
self,
|
|
155
142
|
ipc_path: Union[str, Path] = None,
|
|
156
|
-
timeout: int =
|
|
157
|
-
*args: Any,
|
|
143
|
+
timeout: int = 30,
|
|
158
144
|
**kwargs: Any,
|
|
159
145
|
) -> None:
|
|
160
146
|
if ipc_path is None:
|
|
@@ -162,22 +148,17 @@ class IPCProvider(JSONBaseProvider):
|
|
|
162
148
|
elif isinstance(ipc_path, str) or isinstance(ipc_path, Path):
|
|
163
149
|
self.ipc_path = str(Path(ipc_path).expanduser().resolve())
|
|
164
150
|
else:
|
|
165
|
-
raise
|
|
151
|
+
raise Web3TypeError("ipc_path must be of type string or pathlib.Path")
|
|
166
152
|
|
|
167
153
|
self.timeout = timeout
|
|
168
154
|
self._lock = threading.Lock()
|
|
169
155
|
self._socket = PersistantSocket(self.ipc_path)
|
|
170
|
-
super().__init__()
|
|
156
|
+
super().__init__(**kwargs)
|
|
171
157
|
|
|
172
158
|
def __str__(self) -> str:
|
|
173
159
|
return f"<{self.__class__.__name__} {self.ipc_path}>"
|
|
174
160
|
|
|
175
|
-
def
|
|
176
|
-
self.logger.debug(
|
|
177
|
-
f"Making request IPC. Path: {self.ipc_path}, Method: {method}"
|
|
178
|
-
)
|
|
179
|
-
request = self.encode_rpc_request(method, params)
|
|
180
|
-
|
|
161
|
+
def _make_request(self, request: bytes) -> RPCResponse:
|
|
181
162
|
with self._lock, self._socket as sock:
|
|
182
163
|
try:
|
|
183
164
|
sock.sendall(request)
|
|
@@ -208,6 +189,21 @@ class IPCProvider(JSONBaseProvider):
|
|
|
208
189
|
timeout.sleep(0)
|
|
209
190
|
continue
|
|
210
191
|
|
|
192
|
+
def make_request(self, method: RPCEndpoint, params: Any) -> RPCResponse:
|
|
193
|
+
self.logger.debug(
|
|
194
|
+
f"Making request IPC. Path: {self.ipc_path}, Method: {method}"
|
|
195
|
+
)
|
|
196
|
+
request = self.encode_rpc_request(method, params)
|
|
197
|
+
return self._make_request(request)
|
|
198
|
+
|
|
199
|
+
def make_batch_request(
|
|
200
|
+
self, requests: List[Tuple[RPCEndpoint, Any]]
|
|
201
|
+
) -> List[RPCResponse]:
|
|
202
|
+
self.logger.debug(f"Making batch request IPC. Path: {self.ipc_path}")
|
|
203
|
+
request_data = self.encode_batch_rpc_request(requests)
|
|
204
|
+
response = cast(List[RPCResponse], self._make_request(request_data))
|
|
205
|
+
return sort_batch_response_by_response_ids(response)
|
|
206
|
+
|
|
211
207
|
|
|
212
208
|
# A valid JSON RPC response can only end in } or ] http://www.jsonrpc.org/specification
|
|
213
209
|
def has_valid_json_rpc_ending(raw_response: bytes) -> bool:
|