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/middleware/formatting.py
CHANGED
|
@@ -3,7 +3,9 @@ from typing import (
|
|
|
3
3
|
Any,
|
|
4
4
|
Callable,
|
|
5
5
|
Coroutine,
|
|
6
|
+
Literal,
|
|
6
7
|
Optional,
|
|
8
|
+
Union,
|
|
7
9
|
cast,
|
|
8
10
|
)
|
|
9
11
|
|
|
@@ -13,14 +15,16 @@ from eth_utils.toolz import (
|
|
|
13
15
|
merge,
|
|
14
16
|
)
|
|
15
17
|
|
|
18
|
+
from web3.exceptions import (
|
|
19
|
+
Web3ValueError,
|
|
20
|
+
)
|
|
21
|
+
from web3.middleware.base import (
|
|
22
|
+
Web3MiddlewareBuilder,
|
|
23
|
+
)
|
|
16
24
|
from web3.types import (
|
|
17
|
-
AsyncMiddleware,
|
|
18
|
-
AsyncMiddlewareCoroutine,
|
|
19
25
|
EthSubscriptionParams,
|
|
20
26
|
Formatters,
|
|
21
27
|
FormattersDict,
|
|
22
|
-
Literal,
|
|
23
|
-
Middleware,
|
|
24
28
|
RPCEndpoint,
|
|
25
29
|
RPCResponse,
|
|
26
30
|
)
|
|
@@ -30,6 +34,9 @@ if TYPE_CHECKING:
|
|
|
30
34
|
AsyncWeb3,
|
|
31
35
|
Web3,
|
|
32
36
|
)
|
|
37
|
+
from web3.middleware.base import ( # noqa: F401
|
|
38
|
+
Web3Middleware,
|
|
39
|
+
)
|
|
33
40
|
from web3.providers import ( # noqa: F401
|
|
34
41
|
PersistentConnectionProvider,
|
|
35
42
|
)
|
|
@@ -85,125 +92,134 @@ def _apply_response_formatters(
|
|
|
85
92
|
return response
|
|
86
93
|
|
|
87
94
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
95
|
+
SYNC_FORMATTERS_BUILDER = Callable[["Web3", RPCEndpoint], FormattersDict]
|
|
96
|
+
ASYNC_FORMATTERS_BUILDER = Callable[
|
|
97
|
+
["AsyncWeb3", RPCEndpoint], Coroutine[Any, Any, FormattersDict]
|
|
98
|
+
]
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
class FormattingMiddlewareBuilder(Web3MiddlewareBuilder):
|
|
102
|
+
request_formatters: Formatters = None
|
|
103
|
+
result_formatters: Formatters = None
|
|
104
|
+
error_formatters: Formatters = None
|
|
105
|
+
sync_formatters_builder: SYNC_FORMATTERS_BUILDER = None
|
|
106
|
+
async_formatters_builder: ASYNC_FORMATTERS_BUILDER = None
|
|
107
|
+
|
|
108
|
+
@staticmethod
|
|
109
|
+
@curry
|
|
110
|
+
def build(
|
|
111
|
+
w3: Union["AsyncWeb3", "Web3"],
|
|
112
|
+
# formatters option:
|
|
113
|
+
request_formatters: Optional[Formatters] = None,
|
|
114
|
+
result_formatters: Optional[Formatters] = None,
|
|
115
|
+
error_formatters: Optional[Formatters] = None,
|
|
116
|
+
# formatters builder option:
|
|
117
|
+
sync_formatters_builder: Optional[SYNC_FORMATTERS_BUILDER] = None,
|
|
118
|
+
async_formatters_builder: Optional[ASYNC_FORMATTERS_BUILDER] = None,
|
|
119
|
+
) -> "FormattingMiddlewareBuilder":
|
|
120
|
+
# if not both sync and async formatters are specified, raise error
|
|
121
|
+
if (
|
|
122
|
+
sync_formatters_builder is None and async_formatters_builder is not None
|
|
123
|
+
) or (sync_formatters_builder is not None and async_formatters_builder is None):
|
|
124
|
+
raise Web3ValueError(
|
|
125
|
+
"Must specify both sync_formatters_builder and async_formatters_builder"
|
|
126
|
+
)
|
|
105
127
|
|
|
106
|
-
|
|
128
|
+
if sync_formatters_builder is not None and async_formatters_builder is not None:
|
|
129
|
+
if (
|
|
130
|
+
request_formatters is not None
|
|
131
|
+
or result_formatters is not None
|
|
132
|
+
or error_formatters is not None
|
|
133
|
+
):
|
|
134
|
+
raise Web3ValueError(
|
|
135
|
+
"Cannot specify formatters_builder and formatters at the same time"
|
|
136
|
+
)
|
|
107
137
|
|
|
138
|
+
middleware = FormattingMiddlewareBuilder(w3)
|
|
139
|
+
middleware.request_formatters = request_formatters or {}
|
|
140
|
+
middleware.result_formatters = result_formatters or {}
|
|
141
|
+
middleware.error_formatters = error_formatters or {}
|
|
142
|
+
middleware.sync_formatters_builder = sync_formatters_builder
|
|
143
|
+
middleware.async_formatters_builder = async_formatters_builder
|
|
144
|
+
return middleware
|
|
108
145
|
|
|
109
|
-
def
|
|
110
|
-
|
|
111
|
-
) -> Middleware:
|
|
112
|
-
def formatter_middleware(
|
|
113
|
-
make_request: Callable[[RPCEndpoint, Any], Any],
|
|
114
|
-
w3: "Web3",
|
|
115
|
-
) -> Callable[[RPCEndpoint, Any], RPCResponse]:
|
|
116
|
-
def middleware(method: RPCEndpoint, params: Any) -> RPCResponse:
|
|
146
|
+
def request_processor(self, method: "RPCEndpoint", params: Any) -> Any:
|
|
147
|
+
if self.sync_formatters_builder is not None:
|
|
117
148
|
formatters = merge(
|
|
118
149
|
FORMATTER_DEFAULTS,
|
|
119
|
-
|
|
150
|
+
self.sync_formatters_builder(cast("Web3", self._w3), method),
|
|
120
151
|
)
|
|
121
|
-
request_formatters = formatters.pop("request_formatters")
|
|
152
|
+
self.request_formatters = formatters.pop("request_formatters")
|
|
122
153
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
response = make_request(method, params)
|
|
154
|
+
if method in self.request_formatters:
|
|
155
|
+
formatter = self.request_formatters[method]
|
|
156
|
+
params = formatter(params)
|
|
127
157
|
|
|
128
|
-
|
|
129
|
-
method,
|
|
130
|
-
formatters["result_formatters"],
|
|
131
|
-
formatters["error_formatters"],
|
|
132
|
-
response,
|
|
133
|
-
)
|
|
134
|
-
|
|
135
|
-
return middleware
|
|
158
|
+
return method, params
|
|
136
159
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
160
|
+
def response_processor(self, method: RPCEndpoint, response: "RPCResponse") -> Any:
|
|
161
|
+
if self.sync_formatters_builder is not None:
|
|
162
|
+
formatters = merge(
|
|
163
|
+
FORMATTER_DEFAULTS,
|
|
164
|
+
self.sync_formatters_builder(cast("Web3", self._w3), method),
|
|
165
|
+
)
|
|
166
|
+
self.result_formatters = formatters["result_formatters"]
|
|
167
|
+
self.error_formatters = formatters["error_formatters"]
|
|
168
|
+
|
|
169
|
+
return _apply_response_formatters(
|
|
170
|
+
method,
|
|
171
|
+
self.result_formatters,
|
|
172
|
+
self.error_formatters,
|
|
173
|
+
response,
|
|
174
|
+
)
|
|
141
175
|
|
|
176
|
+
# -- async -- #
|
|
142
177
|
|
|
143
|
-
async def
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
return dict(
|
|
153
|
-
request_formatters=request_formatters or {},
|
|
154
|
-
result_formatters=result_formatters or {},
|
|
155
|
-
error_formatters=error_formatters or {},
|
|
156
|
-
)
|
|
178
|
+
async def async_request_processor(self, method: "RPCEndpoint", params: Any) -> Any:
|
|
179
|
+
if self.async_formatters_builder is not None:
|
|
180
|
+
formatters = merge(
|
|
181
|
+
FORMATTER_DEFAULTS,
|
|
182
|
+
await self.async_formatters_builder(
|
|
183
|
+
cast("AsyncWeb3", self._w3), method
|
|
184
|
+
),
|
|
185
|
+
)
|
|
186
|
+
self.request_formatters = formatters.pop("request_formatters")
|
|
157
187
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
188
|
+
if method in self.request_formatters:
|
|
189
|
+
formatter = self.request_formatters[method]
|
|
190
|
+
params = formatter(params)
|
|
161
191
|
|
|
192
|
+
return method, params
|
|
162
193
|
|
|
163
|
-
async def
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
) -> Callable[
|
|
168
|
-
[Callable[[RPCEndpoint, Any], Any], "AsyncWeb3"],
|
|
169
|
-
Coroutine[Any, Any, AsyncMiddlewareCoroutine],
|
|
170
|
-
]:
|
|
171
|
-
async def formatter_middleware(
|
|
172
|
-
make_request: Callable[[RPCEndpoint, Any], Any],
|
|
173
|
-
async_w3: "AsyncWeb3",
|
|
174
|
-
) -> AsyncMiddlewareCoroutine:
|
|
175
|
-
async def middleware(method: RPCEndpoint, params: Any) -> Optional[RPCResponse]:
|
|
194
|
+
async def async_response_processor(
|
|
195
|
+
self, method: RPCEndpoint, response: "RPCResponse"
|
|
196
|
+
) -> Any:
|
|
197
|
+
if self.async_formatters_builder is not None:
|
|
176
198
|
formatters = merge(
|
|
177
199
|
FORMATTER_DEFAULTS,
|
|
178
|
-
await
|
|
200
|
+
await self.async_formatters_builder(
|
|
201
|
+
cast("AsyncWeb3", self._w3), method
|
|
202
|
+
),
|
|
179
203
|
)
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
if method in request_formatters:
|
|
183
|
-
formatter = request_formatters[method]
|
|
184
|
-
params = formatter(params)
|
|
185
|
-
response = await make_request(method, params)
|
|
186
|
-
|
|
187
|
-
if async_w3.provider.has_persistent_connection:
|
|
188
|
-
# asynchronous response processing
|
|
189
|
-
provider = cast("PersistentConnectionProvider", async_w3.provider)
|
|
190
|
-
provider._request_processor.append_middleware_response_processor(
|
|
191
|
-
response,
|
|
192
|
-
_apply_response_formatters(
|
|
193
|
-
method,
|
|
194
|
-
formatters["result_formatters"],
|
|
195
|
-
formatters["error_formatters"],
|
|
196
|
-
),
|
|
197
|
-
)
|
|
198
|
-
return response
|
|
199
|
-
else:
|
|
200
|
-
return _apply_response_formatters(
|
|
201
|
-
method,
|
|
202
|
-
formatters["result_formatters"],
|
|
203
|
-
formatters["error_formatters"],
|
|
204
|
-
response,
|
|
205
|
-
)
|
|
204
|
+
self.result_formatters = formatters["result_formatters"]
|
|
205
|
+
self.error_formatters = formatters["error_formatters"]
|
|
206
206
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
207
|
+
if self._w3.provider.has_persistent_connection:
|
|
208
|
+
# asynchronous response processing
|
|
209
|
+
provider = cast("PersistentConnectionProvider", self._w3.provider)
|
|
210
|
+
provider._request_processor.append_middleware_response_processor(
|
|
211
|
+
response,
|
|
212
|
+
_apply_response_formatters(
|
|
213
|
+
method,
|
|
214
|
+
self.result_formatters,
|
|
215
|
+
self.error_formatters,
|
|
216
|
+
),
|
|
217
|
+
)
|
|
218
|
+
return response
|
|
219
|
+
else:
|
|
220
|
+
return _apply_response_formatters(
|
|
221
|
+
method,
|
|
222
|
+
self.result_formatters,
|
|
223
|
+
self.error_formatters,
|
|
224
|
+
response,
|
|
225
|
+
)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from typing import (
|
|
2
2
|
TYPE_CHECKING,
|
|
3
3
|
Any,
|
|
4
|
-
|
|
4
|
+
cast,
|
|
5
5
|
)
|
|
6
6
|
|
|
7
7
|
from eth_utils.toolz import (
|
|
@@ -23,11 +23,12 @@ from web3.exceptions import (
|
|
|
23
23
|
InvalidTransaction,
|
|
24
24
|
TransactionTypeMismatch,
|
|
25
25
|
)
|
|
26
|
+
from web3.middleware.base import (
|
|
27
|
+
Web3Middleware,
|
|
28
|
+
)
|
|
26
29
|
from web3.types import (
|
|
27
|
-
AsyncMiddlewareCoroutine,
|
|
28
30
|
BlockData,
|
|
29
31
|
RPCEndpoint,
|
|
30
|
-
RPCResponse,
|
|
31
32
|
TxParams,
|
|
32
33
|
Wei,
|
|
33
34
|
)
|
|
@@ -78,51 +79,38 @@ def validate_transaction_params(
|
|
|
78
79
|
return transaction
|
|
79
80
|
|
|
80
81
|
|
|
81
|
-
|
|
82
|
-
make_request: Callable[[RPCEndpoint, Any], Any], w3: "Web3"
|
|
83
|
-
) -> Callable[[RPCEndpoint, Any], RPCResponse]:
|
|
82
|
+
class GasPriceStrategyMiddleware(Web3Middleware):
|
|
84
83
|
"""
|
|
85
|
-
- Uses a gas price strategy if one is set. This is only supported
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
- Uses a gas price strategy if one is set. This is only supported for
|
|
85
|
+
legacy transactions. It is recommended to send dynamic fee transactions
|
|
86
|
+
(EIP-1559) whenever possible.
|
|
88
87
|
|
|
89
88
|
- Validates transaction params against legacy and dynamic fee txn values.
|
|
90
89
|
"""
|
|
91
90
|
|
|
92
|
-
def
|
|
91
|
+
def request_processor(self, method: RPCEndpoint, params: Any) -> Any:
|
|
93
92
|
if method == "eth_sendTransaction":
|
|
94
93
|
transaction = params[0]
|
|
95
|
-
generated_gas_price =
|
|
94
|
+
generated_gas_price = self._w3.eth.generate_gas_price(transaction)
|
|
95
|
+
w3 = cast("Web3", self._w3)
|
|
96
96
|
latest_block = w3.eth.get_block("latest")
|
|
97
97
|
transaction = validate_transaction_params(
|
|
98
98
|
transaction, latest_block, generated_gas_price
|
|
99
99
|
)
|
|
100
|
-
|
|
101
|
-
return make_request(method, params)
|
|
100
|
+
params = (transaction,)
|
|
102
101
|
|
|
103
|
-
|
|
102
|
+
return method, params
|
|
104
103
|
|
|
104
|
+
# -- async -- #
|
|
105
105
|
|
|
106
|
-
async def
|
|
107
|
-
make_request: Callable[[RPCEndpoint, Any], Any], async_w3: "AsyncWeb3"
|
|
108
|
-
) -> AsyncMiddlewareCoroutine:
|
|
109
|
-
"""
|
|
110
|
-
- Uses a gas price strategy if one is set. This is only supported for
|
|
111
|
-
legacy transactions. It is recommended to send dynamic fee transactions
|
|
112
|
-
(EIP-1559) whenever possible.
|
|
113
|
-
|
|
114
|
-
- Validates transaction params against legacy and dynamic fee txn values.
|
|
115
|
-
"""
|
|
116
|
-
|
|
117
|
-
async def middleware(method: RPCEndpoint, params: Any) -> RPCResponse:
|
|
106
|
+
async def async_request_processor(self, method: RPCEndpoint, params: Any) -> Any:
|
|
118
107
|
if method == "eth_sendTransaction":
|
|
119
108
|
transaction = params[0]
|
|
120
|
-
|
|
121
|
-
|
|
109
|
+
w3 = cast("AsyncWeb3", self._w3)
|
|
110
|
+
generated_gas_price = w3.eth.generate_gas_price(transaction)
|
|
111
|
+
latest_block = await w3.eth.get_block("latest")
|
|
122
112
|
transaction = validate_transaction_params(
|
|
123
113
|
transaction, latest_block, generated_gas_price
|
|
124
114
|
)
|
|
125
|
-
|
|
126
|
-
return
|
|
127
|
-
|
|
128
|
-
return middleware
|
|
115
|
+
params = (transaction,)
|
|
116
|
+
return method, params
|
web3/middleware/names.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
from typing import (
|
|
2
2
|
TYPE_CHECKING,
|
|
3
3
|
Any,
|
|
4
|
-
Callable,
|
|
5
4
|
Dict,
|
|
6
5
|
Sequence,
|
|
7
6
|
Union,
|
|
7
|
+
cast,
|
|
8
8
|
)
|
|
9
9
|
|
|
10
10
|
from toolz import (
|
|
@@ -20,8 +20,6 @@ from web3._utils.rpc_abi import (
|
|
|
20
20
|
abi_request_formatters,
|
|
21
21
|
)
|
|
22
22
|
from web3.types import (
|
|
23
|
-
AsyncMiddlewareCoroutine,
|
|
24
|
-
Middleware,
|
|
25
23
|
RPCEndpoint,
|
|
26
24
|
)
|
|
27
25
|
|
|
@@ -33,8 +31,14 @@ from .._utils.abi import (
|
|
|
33
31
|
from .._utils.formatters import (
|
|
34
32
|
recursive_map,
|
|
35
33
|
)
|
|
34
|
+
from ..exceptions import (
|
|
35
|
+
Web3TypeError,
|
|
36
|
+
)
|
|
37
|
+
from .base import (
|
|
38
|
+
Web3Middleware,
|
|
39
|
+
)
|
|
36
40
|
from .formatting import (
|
|
37
|
-
|
|
41
|
+
FormattingMiddlewareBuilder,
|
|
38
42
|
)
|
|
39
43
|
|
|
40
44
|
if TYPE_CHECKING:
|
|
@@ -44,18 +48,6 @@ if TYPE_CHECKING:
|
|
|
44
48
|
)
|
|
45
49
|
|
|
46
50
|
|
|
47
|
-
def name_to_address_middleware(w3: "Web3") -> Middleware:
|
|
48
|
-
normalizers = [
|
|
49
|
-
abi_ens_resolver(w3),
|
|
50
|
-
]
|
|
51
|
-
return construct_formatting_middleware(
|
|
52
|
-
request_formatters=abi_request_formatters(normalizers, RPC_ABIS)
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
# -- async -- #
|
|
57
|
-
|
|
58
|
-
|
|
59
51
|
def _is_logs_subscription_with_optional_args(method: RPCEndpoint, params: Any) -> bool:
|
|
60
52
|
return method == "eth_subscribe" and len(params) == 2 and params[0] == "logs"
|
|
61
53
|
|
|
@@ -103,17 +95,29 @@ async def async_apply_ens_to_address_conversion(
|
|
|
103
95
|
return (formatted_params_dict, *params[1:])
|
|
104
96
|
|
|
105
97
|
else:
|
|
106
|
-
raise
|
|
98
|
+
raise Web3TypeError(
|
|
107
99
|
f"ABI definitions must be a list or dictionary, "
|
|
108
100
|
f"got {abi_types_for_method!r}"
|
|
109
101
|
)
|
|
110
102
|
|
|
111
103
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
) ->
|
|
116
|
-
|
|
104
|
+
class ENSNameToAddressMiddleware(Web3Middleware):
|
|
105
|
+
_formatting_middleware = None
|
|
106
|
+
|
|
107
|
+
def request_processor(self, method: "RPCEndpoint", params: Any) -> Any:
|
|
108
|
+
if self._formatting_middleware is None:
|
|
109
|
+
normalizers = [
|
|
110
|
+
abi_ens_resolver(self._w3),
|
|
111
|
+
]
|
|
112
|
+
self._formatting_middleware = FormattingMiddlewareBuilder.build(
|
|
113
|
+
request_formatters=abi_request_formatters(normalizers, RPC_ABIS)
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
return self._formatting_middleware(self._w3).request_processor(method, params)
|
|
117
|
+
|
|
118
|
+
# -- async -- #
|
|
119
|
+
|
|
120
|
+
async def async_request_processor(self, method: "RPCEndpoint", params: Any) -> Any:
|
|
117
121
|
abi_types_for_method = RPC_ABIS.get(method, None)
|
|
118
122
|
|
|
119
123
|
if abi_types_for_method is not None:
|
|
@@ -121,7 +125,7 @@ async def async_name_to_address_middleware(
|
|
|
121
125
|
# eth_subscribe optional logs params are unique.
|
|
122
126
|
# Handle them separately here.
|
|
123
127
|
(formatted_dict,) = await async_apply_ens_to_address_conversion(
|
|
124
|
-
|
|
128
|
+
cast("AsyncWeb3", self._w3),
|
|
125
129
|
(params[1],),
|
|
126
130
|
{
|
|
127
131
|
"address": "address",
|
|
@@ -132,10 +136,9 @@ async def async_name_to_address_middleware(
|
|
|
132
136
|
|
|
133
137
|
else:
|
|
134
138
|
params = await async_apply_ens_to_address_conversion(
|
|
135
|
-
|
|
139
|
+
cast("AsyncWeb3", self._w3),
|
|
136
140
|
params,
|
|
137
141
|
abi_types_for_method,
|
|
138
142
|
)
|
|
139
|
-
return await make_request(method, params)
|
|
140
143
|
|
|
141
|
-
|
|
144
|
+
return method, params
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
from typing import (
|
|
2
|
+
TYPE_CHECKING,
|
|
3
|
+
)
|
|
4
|
+
|
|
5
|
+
from eth_utils import (
|
|
6
|
+
is_dict,
|
|
7
|
+
)
|
|
8
|
+
from eth_utils.curried import (
|
|
9
|
+
apply_formatter_if,
|
|
10
|
+
apply_formatters_to_dict,
|
|
11
|
+
apply_key_map,
|
|
12
|
+
is_null,
|
|
13
|
+
)
|
|
14
|
+
from eth_utils.toolz import (
|
|
15
|
+
complement,
|
|
16
|
+
compose,
|
|
17
|
+
)
|
|
18
|
+
from hexbytes import (
|
|
19
|
+
HexBytes,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
from web3._utils.rpc_abi import (
|
|
23
|
+
RPC,
|
|
24
|
+
)
|
|
25
|
+
from web3.middleware.formatting import (
|
|
26
|
+
FormattingMiddlewareBuilder,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
if TYPE_CHECKING:
|
|
30
|
+
from web3 import ( # noqa: F401
|
|
31
|
+
AsyncWeb3,
|
|
32
|
+
Web3,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
is_not_null = complement(is_null)
|
|
36
|
+
|
|
37
|
+
remap_extradata_to_poa_fields = apply_key_map(
|
|
38
|
+
{
|
|
39
|
+
"extraData": "proofOfAuthorityData",
|
|
40
|
+
}
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
pythonic_extradata_to_poa = apply_formatters_to_dict(
|
|
44
|
+
{
|
|
45
|
+
"proofOfAuthorityData": HexBytes,
|
|
46
|
+
}
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
extradata_to_poa_cleanup = compose(
|
|
50
|
+
pythonic_extradata_to_poa, remap_extradata_to_poa_fields
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
ExtraDataToPOAMiddleware = FormattingMiddlewareBuilder.build(
|
|
55
|
+
result_formatters={
|
|
56
|
+
RPC.eth_getBlockByHash: apply_formatter_if(
|
|
57
|
+
is_not_null, extradata_to_poa_cleanup
|
|
58
|
+
),
|
|
59
|
+
RPC.eth_getBlockByNumber: apply_formatter_if(
|
|
60
|
+
is_not_null, extradata_to_poa_cleanup
|
|
61
|
+
),
|
|
62
|
+
RPC.eth_subscribe: apply_formatter_if(
|
|
63
|
+
is_not_null,
|
|
64
|
+
# original call to eth_subscribe returns a string, needs a dict check
|
|
65
|
+
apply_formatter_if(is_dict, extradata_to_poa_cleanup),
|
|
66
|
+
),
|
|
67
|
+
},
|
|
68
|
+
)
|
web3/middleware/pythonic.py
CHANGED
|
@@ -3,10 +3,10 @@ from web3._utils.method_formatters import (
|
|
|
3
3
|
PYTHONIC_RESULT_FORMATTERS,
|
|
4
4
|
)
|
|
5
5
|
from web3.middleware.formatting import (
|
|
6
|
-
|
|
6
|
+
FormattingMiddlewareBuilder,
|
|
7
7
|
)
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
PythonicMiddleware = FormattingMiddlewareBuilder.build(
|
|
10
10
|
request_formatters=PYTHONIC_REQUEST_FORMATTERS,
|
|
11
11
|
result_formatters=PYTHONIC_RESULT_FORMATTERS,
|
|
12
12
|
)
|