web3 7.14.1__py3-none-any.whl → 8.0.0b1__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/_normalization.py +23 -29
- ens/async_ens.py +30 -24
- ens/base_ens.py +2 -3
- ens/ens.py +18 -20
- ens/utils.py +6 -10
- web3/__init__.py +0 -4
- web3/_utils/abi.py +38 -40
- web3/_utils/async_transactions.py +6 -9
- web3/_utils/batching.py +11 -15
- web3/_utils/blocks.py +1 -2
- web3/_utils/caching/caching_utils.py +12 -17
- web3/_utils/caching/request_caching_validation.py +7 -9
- web3/_utils/compat/__init__.py +2 -2
- web3/_utils/contract_sources/compile_contracts.py +4 -6
- web3/_utils/contracts.py +25 -29
- web3/_utils/datatypes.py +6 -10
- web3/_utils/decorators.py +1 -3
- web3/_utils/encoding.py +10 -14
- web3/_utils/ens.py +4 -5
- web3/_utils/events.py +19 -24
- web3/_utils/filters.py +23 -29
- web3/_utils/formatters.py +8 -13
- web3/_utils/http_session_manager.py +11 -22
- web3/_utils/math.py +1 -2
- web3/_utils/method_formatters.py +41 -43
- web3/_utils/module.py +3 -6
- web3/_utils/module_testing/eth_module.py +7 -9
- web3/_utils/module_testing/go_ethereum_admin_module.py +1 -2
- web3/_utils/module_testing/module_testing_utils.py +9 -5
- web3/_utils/module_testing/persistent_connection_provider.py +3 -7
- web3/_utils/module_testing/utils.py +32 -21
- web3/_utils/normalizers.py +21 -24
- web3/_utils/rpc_abi.py +8 -11
- web3/_utils/threads.py +3 -4
- web3/_utils/transactions.py +3 -6
- web3/_utils/type_conversion.py +2 -6
- web3/_utils/utility_methods.py +5 -7
- web3/_utils/validation.py +6 -8
- web3/_utils/windows.py +1 -4
- web3/beacon/async_beacon.py +50 -54
- web3/beacon/beacon.py +50 -54
- web3/contract/async_contract.py +38 -46
- web3/contract/base_contract.py +70 -75
- web3/contract/contract.py +39 -43
- web3/contract/utils.py +47 -51
- web3/datastructures.py +10 -15
- web3/eth/async_eth.py +64 -70
- web3/eth/base_eth.py +40 -44
- web3/eth/eth.py +50 -66
- web3/exceptions.py +8 -13
- web3/gas_strategies/rpc.py +1 -7
- web3/gas_strategies/time_based.py +2 -3
- web3/geth.py +17 -17
- web3/main.py +43 -52
- web3/manager.py +32 -35
- web3/method.py +22 -29
- web3/middleware/base.py +5 -8
- web3/middleware/filter.py +41 -46
- web3/middleware/formatting.py +5 -6
- web3/middleware/names.py +1 -3
- web3/middleware/signing.py +3 -4
- web3/middleware/stalecheck.py +1 -2
- web3/middleware/validation.py +1 -2
- web3/module.py +11 -14
- web3/providers/__init__.py +0 -4
- web3/providers/async_base.py +21 -27
- web3/providers/auto.py +9 -20
- web3/providers/base.py +12 -17
- web3/providers/eth_tester/defaults.py +4 -8
- web3/providers/eth_tester/main.py +4 -8
- web3/providers/eth_tester/middleware.py +2 -4
- web3/providers/ipc.py +6 -10
- web3/providers/persistent/async_ipc.py +4 -7
- web3/providers/persistent/persistent.py +22 -25
- web3/providers/persistent/persistent_connection.py +2 -4
- web3/providers/persistent/request_processor.py +11 -32
- web3/providers/persistent/subscription_container.py +5 -8
- web3/providers/persistent/subscription_manager.py +13 -19
- web3/providers/persistent/websocket.py +15 -12
- web3/providers/rpc/async_rpc.py +10 -16
- web3/providers/rpc/rpc.py +17 -20
- web3/providers/rpc/utils.py +2 -3
- web3/scripts/release/test_package.py +1 -4
- web3/testing.py +1 -5
- web3/tracing.py +9 -13
- web3/types.py +51 -58
- web3/utils/abi.py +28 -33
- web3/utils/async_exception_handling.py +1 -2
- web3/utils/caching.py +6 -10
- web3/utils/exception_handling.py +1 -2
- web3/utils/subscriptions.py +30 -34
- {web3-7.14.1.dist-info → web3-8.0.0b1.dist-info}/METADATA +10 -9
- web3-8.0.0b1.dist-info/RECORD +170 -0
- {web3-7.14.1.dist-info → web3-8.0.0b1.dist-info}/WHEEL +1 -1
- ens/specs/.DS_Store +0 -0
- web3/providers/legacy_websocket.py +0 -159
- web3-7.14.1.dist-info/RECORD +0 -172
- {web3-7.14.1.dist-info → web3-8.0.0b1.dist-info}/licenses/LICENSE +0 -0
- {web3-7.14.1.dist-info → web3-8.0.0b1.dist-info}/top_level.txt +0 -0
web3/main.py
CHANGED
|
@@ -30,18 +30,17 @@ from functools import (
|
|
|
30
30
|
from hexbytes import (
|
|
31
31
|
HexBytes,
|
|
32
32
|
)
|
|
33
|
+
from collections.abc import (
|
|
34
|
+
AsyncIterator,
|
|
35
|
+
)
|
|
33
36
|
from typing import (
|
|
34
|
-
TYPE_CHECKING,
|
|
35
37
|
Any,
|
|
36
|
-
AsyncIterator,
|
|
37
38
|
Callable,
|
|
38
|
-
Dict,
|
|
39
39
|
Generator,
|
|
40
40
|
Generic,
|
|
41
|
-
List,
|
|
42
41
|
Optional,
|
|
43
42
|
Sequence,
|
|
44
|
-
|
|
43
|
+
TYPE_CHECKING,
|
|
45
44
|
TypeVar,
|
|
46
45
|
Union,
|
|
47
46
|
cast,
|
|
@@ -135,7 +134,6 @@ from web3.providers.rpc import (
|
|
|
135
134
|
HTTPProvider,
|
|
136
135
|
)
|
|
137
136
|
from web3.providers import (
|
|
138
|
-
LegacyWebSocketProvider,
|
|
139
137
|
WebSocketProvider,
|
|
140
138
|
)
|
|
141
139
|
from web3.providers.persistent import (
|
|
@@ -160,7 +158,7 @@ if TYPE_CHECKING:
|
|
|
160
158
|
from web3.providers.persistent import PersistentConnectionProvider # noqa: F401
|
|
161
159
|
|
|
162
160
|
|
|
163
|
-
def get_async_default_modules() ->
|
|
161
|
+
def get_async_default_modules() -> dict[str, type[Module] | Sequence[Any]]:
|
|
164
162
|
return {
|
|
165
163
|
"eth": AsyncEth,
|
|
166
164
|
"net": AsyncNet,
|
|
@@ -175,7 +173,7 @@ def get_async_default_modules() -> Dict[str, Union[Type[Module], Sequence[Any]]]
|
|
|
175
173
|
}
|
|
176
174
|
|
|
177
175
|
|
|
178
|
-
def get_default_modules() ->
|
|
176
|
+
def get_default_modules() -> dict[str, type[Module] | Sequence[Any]]:
|
|
179
177
|
return {
|
|
180
178
|
"eth": Eth,
|
|
181
179
|
"net": Net,
|
|
@@ -200,9 +198,9 @@ class BaseWeb3:
|
|
|
200
198
|
manager: DefaultRequestManager
|
|
201
199
|
|
|
202
200
|
# mypy types
|
|
203
|
-
eth:
|
|
204
|
-
net:
|
|
205
|
-
geth:
|
|
201
|
+
eth: Eth | AsyncEth
|
|
202
|
+
net: Net | AsyncNet
|
|
203
|
+
geth: Geth | AsyncGeth
|
|
206
204
|
|
|
207
205
|
@property
|
|
208
206
|
def middleware_onion(self) -> MiddlewareOnion:
|
|
@@ -212,53 +210,53 @@ class BaseWeb3:
|
|
|
212
210
|
@staticmethod
|
|
213
211
|
@wraps(to_bytes)
|
|
214
212
|
def to_bytes(
|
|
215
|
-
primitive:
|
|
216
|
-
hexstr:
|
|
217
|
-
text:
|
|
213
|
+
primitive: Primitives | None = None,
|
|
214
|
+
hexstr: HexStr | None = None,
|
|
215
|
+
text: str | None = None,
|
|
218
216
|
) -> bytes:
|
|
219
217
|
return to_bytes(primitive, hexstr, text)
|
|
220
218
|
|
|
221
219
|
@staticmethod
|
|
222
220
|
@wraps(to_int)
|
|
223
221
|
def to_int(
|
|
224
|
-
primitive:
|
|
225
|
-
hexstr:
|
|
226
|
-
text:
|
|
222
|
+
primitive: Primitives | None = None,
|
|
223
|
+
hexstr: HexStr | None = None,
|
|
224
|
+
text: str | None = None,
|
|
227
225
|
) -> int:
|
|
228
226
|
return to_int(primitive, hexstr, text)
|
|
229
227
|
|
|
230
228
|
@staticmethod
|
|
231
229
|
@wraps(to_hex)
|
|
232
230
|
def to_hex(
|
|
233
|
-
primitive:
|
|
234
|
-
hexstr:
|
|
235
|
-
text:
|
|
231
|
+
primitive: Primitives | None = None,
|
|
232
|
+
hexstr: HexStr | None = None,
|
|
233
|
+
text: str | None = None,
|
|
236
234
|
) -> HexStr:
|
|
237
235
|
return to_hex(primitive, hexstr, text)
|
|
238
236
|
|
|
239
237
|
@staticmethod
|
|
240
238
|
@wraps(to_text)
|
|
241
239
|
def to_text(
|
|
242
|
-
primitive:
|
|
243
|
-
hexstr:
|
|
244
|
-
text:
|
|
240
|
+
primitive: Primitives | None = None,
|
|
241
|
+
hexstr: HexStr | None = None,
|
|
242
|
+
text: str | None = None,
|
|
245
243
|
) -> str:
|
|
246
244
|
return to_text(primitive, hexstr, text)
|
|
247
245
|
|
|
248
246
|
@staticmethod
|
|
249
247
|
@wraps(to_json)
|
|
250
|
-
def to_json(obj:
|
|
248
|
+
def to_json(obj: dict[Any, Any]) -> str:
|
|
251
249
|
return to_json(obj)
|
|
252
250
|
|
|
253
251
|
# Currency Utility
|
|
254
252
|
@staticmethod
|
|
255
253
|
@wraps(to_wei)
|
|
256
|
-
def to_wei(number:
|
|
254
|
+
def to_wei(number: int | float | str | decimal.Decimal, unit: str) -> Wei:
|
|
257
255
|
return cast(Wei, to_wei(number, unit))
|
|
258
256
|
|
|
259
257
|
@staticmethod
|
|
260
258
|
@wraps(from_wei)
|
|
261
|
-
def from_wei(number: int, unit: str) ->
|
|
259
|
+
def from_wei(number: int, unit: str) -> int | decimal.Decimal:
|
|
262
260
|
return from_wei(number, unit)
|
|
263
261
|
|
|
264
262
|
# Address Utility
|
|
@@ -274,7 +272,7 @@ class BaseWeb3:
|
|
|
274
272
|
|
|
275
273
|
@staticmethod
|
|
276
274
|
@wraps(to_checksum_address)
|
|
277
|
-
def to_checksum_address(value:
|
|
275
|
+
def to_checksum_address(value: AnyAddress | str | bytes) -> ChecksumAddress:
|
|
278
276
|
return to_checksum_address(value)
|
|
279
277
|
|
|
280
278
|
@property
|
|
@@ -299,9 +297,9 @@ class BaseWeb3:
|
|
|
299
297
|
@staticmethod
|
|
300
298
|
@apply_to_return_value(HexBytes)
|
|
301
299
|
def keccak(
|
|
302
|
-
primitive:
|
|
303
|
-
text:
|
|
304
|
-
hexstr:
|
|
300
|
+
primitive: Primitives | None = None,
|
|
301
|
+
text: str | None = None,
|
|
302
|
+
hexstr: HexStr | None = None,
|
|
305
303
|
) -> bytes:
|
|
306
304
|
if isinstance(primitive, (bytes, int, type(None))):
|
|
307
305
|
input_bytes = to_bytes(primitive, hexstr=hexstr, text=text)
|
|
@@ -316,12 +314,12 @@ class BaseWeb3:
|
|
|
316
314
|
|
|
317
315
|
@classmethod
|
|
318
316
|
def normalize_values(
|
|
319
|
-
cls, w3: "BaseWeb3", abi_types:
|
|
320
|
-
) ->
|
|
317
|
+
cls, w3: "BaseWeb3", abi_types: list[TypeStr], values: list[Any]
|
|
318
|
+
) -> list[Any]:
|
|
321
319
|
return map_abi_data([abi_ens_resolver(w3)], abi_types, values)
|
|
322
320
|
|
|
323
321
|
@combomethod
|
|
324
|
-
def solidity_keccak(cls, abi_types:
|
|
322
|
+
def solidity_keccak(cls, abi_types: list[TypeStr], values: list[Any]) -> bytes:
|
|
325
323
|
"""
|
|
326
324
|
Executes keccak256 exactly as Solidity does.
|
|
327
325
|
Takes list of abi_types as inputs -- `[uint24, int8[], bool]`
|
|
@@ -349,9 +347,7 @@ class BaseWeb3:
|
|
|
349
347
|
)
|
|
350
348
|
return cls.keccak(hexstr=hex_string)
|
|
351
349
|
|
|
352
|
-
def attach_modules(
|
|
353
|
-
self, modules: Dict[str, Union[Type[Module], Sequence[Any]]]
|
|
354
|
-
) -> None:
|
|
350
|
+
def attach_modules(self, modules: dict[str, type[Module] | Sequence[Any]]) -> None:
|
|
355
351
|
"""
|
|
356
352
|
Attach modules to the `Web3` instance.
|
|
357
353
|
"""
|
|
@@ -370,7 +366,7 @@ class BaseWeb3:
|
|
|
370
366
|
|
|
371
367
|
def _validate_provider(
|
|
372
368
|
w3: Union["Web3", "AsyncWeb3[Any]"],
|
|
373
|
-
provider:
|
|
369
|
+
provider: BaseProvider | AsyncBaseProvider | None,
|
|
374
370
|
) -> None:
|
|
375
371
|
if provider is not None:
|
|
376
372
|
if isinstance(w3, AsyncWeb3) and not isinstance(provider, AsyncBaseProvider):
|
|
@@ -396,16 +392,13 @@ class Web3(BaseWeb3):
|
|
|
396
392
|
HTTPProvider = HTTPProvider
|
|
397
393
|
IPCProvider = IPCProvider
|
|
398
394
|
EthereumTesterProvider = EthereumTesterProvider
|
|
399
|
-
LegacyWebSocketProvider = LegacyWebSocketProvider
|
|
400
395
|
|
|
401
396
|
def __init__(
|
|
402
397
|
self,
|
|
403
|
-
provider:
|
|
404
|
-
middleware:
|
|
405
|
-
modules:
|
|
406
|
-
external_modules:
|
|
407
|
-
Dict[str, Union[Type[Module], Sequence[Any]]]
|
|
408
|
-
] = None,
|
|
398
|
+
provider: BaseProvider | None = None,
|
|
399
|
+
middleware: Sequence[Any] | None = None,
|
|
400
|
+
modules: dict[str, type[Module] | Sequence[Any]] | None = None,
|
|
401
|
+
external_modules: None | (dict[str, type[Module] | Sequence[Any]]) = None,
|
|
409
402
|
ens: Union[ENS, "Empty"] = empty,
|
|
410
403
|
) -> None:
|
|
411
404
|
_validate_provider(self, provider)
|
|
@@ -473,12 +466,10 @@ class AsyncWeb3(BaseWeb3, Generic[AsyncProviderT]):
|
|
|
473
466
|
|
|
474
467
|
def __init__(
|
|
475
468
|
self,
|
|
476
|
-
provider:
|
|
477
|
-
middleware:
|
|
478
|
-
modules:
|
|
479
|
-
external_modules:
|
|
480
|
-
Dict[str, Union[Type[Module], Sequence[Any]]]
|
|
481
|
-
] = None,
|
|
469
|
+
provider: AsyncProviderT | None = None,
|
|
470
|
+
middleware: Sequence[Any] | None = None,
|
|
471
|
+
modules: dict[str, type[Module] | Sequence[Any]] | None = None,
|
|
472
|
+
external_modules: None | (dict[str, type[Module] | Sequence[Any]]) = None,
|
|
482
473
|
ens: Union[AsyncENS, "Empty"] = empty,
|
|
483
474
|
) -> None:
|
|
484
475
|
_validate_provider(self, provider)
|
|
@@ -526,7 +517,7 @@ class AsyncWeb3(BaseWeb3, Generic[AsyncProviderT]):
|
|
|
526
517
|
|
|
527
518
|
# -- persistent connection settings -- #
|
|
528
519
|
|
|
529
|
-
_subscription_manager:
|
|
520
|
+
_subscription_manager: SubscriptionManager | None = None
|
|
530
521
|
_persistent_connection: Optional["PersistentConnection"] = None
|
|
531
522
|
|
|
532
523
|
@property
|
|
@@ -573,7 +564,7 @@ class AsyncWeb3(BaseWeb3, Generic[AsyncProviderT]):
|
|
|
573
564
|
@persistent_connection_provider_method()
|
|
574
565
|
async def __aexit__(
|
|
575
566
|
self,
|
|
576
|
-
exc_type:
|
|
567
|
+
exc_type: type[BaseException],
|
|
577
568
|
exc_val: BaseException,
|
|
578
569
|
exc_tb: TracebackType,
|
|
579
570
|
) -> None:
|
web3/manager.py
CHANGED
|
@@ -6,11 +6,7 @@ from typing import (
|
|
|
6
6
|
AsyncGenerator,
|
|
7
7
|
Callable,
|
|
8
8
|
Coroutine,
|
|
9
|
-
Dict,
|
|
10
|
-
List,
|
|
11
|
-
Optional,
|
|
12
9
|
Sequence,
|
|
13
|
-
Tuple,
|
|
14
10
|
Union,
|
|
15
11
|
cast,
|
|
16
12
|
)
|
|
@@ -106,8 +102,8 @@ class RequestManager:
|
|
|
106
102
|
def __init__(
|
|
107
103
|
self,
|
|
108
104
|
w3: Union["AsyncWeb3[Any]", "Web3"],
|
|
109
|
-
provider:
|
|
110
|
-
middleware:
|
|
105
|
+
provider: Union["BaseProvider", "AsyncBaseProvider"] | None = None,
|
|
106
|
+
middleware: Sequence[tuple[Middleware, str]] | None = None,
|
|
111
107
|
) -> None:
|
|
112
108
|
self.w3 = w3
|
|
113
109
|
|
|
@@ -136,7 +132,7 @@ class RequestManager:
|
|
|
136
132
|
self._provider = provider
|
|
137
133
|
|
|
138
134
|
@staticmethod
|
|
139
|
-
def get_default_middleware() ->
|
|
135
|
+
def get_default_middleware() -> list[tuple[Middleware, str]]:
|
|
140
136
|
"""
|
|
141
137
|
List the default middleware for the request manager.
|
|
142
138
|
Documentation should remain in sync with these defaults.
|
|
@@ -153,7 +149,7 @@ class RequestManager:
|
|
|
153
149
|
# Provider requests and response
|
|
154
150
|
#
|
|
155
151
|
def _make_request(
|
|
156
|
-
self, method:
|
|
152
|
+
self, method: RPCEndpoint | Callable[..., RPCEndpoint], params: Any
|
|
157
153
|
) -> RPCResponse:
|
|
158
154
|
provider = cast("BaseProvider", self.provider)
|
|
159
155
|
request_func = provider.request_func(
|
|
@@ -163,7 +159,7 @@ class RequestManager:
|
|
|
163
159
|
return request_func(method, params)
|
|
164
160
|
|
|
165
161
|
async def _coro_make_request(
|
|
166
|
-
self, method:
|
|
162
|
+
self, method: RPCEndpoint | Callable[..., RPCEndpoint], params: Any
|
|
167
163
|
) -> RPCResponse:
|
|
168
164
|
provider = cast("AsyncBaseProvider", self.provider)
|
|
169
165
|
request_func = await provider.request_func(
|
|
@@ -186,8 +182,8 @@ class RequestManager:
|
|
|
186
182
|
self,
|
|
187
183
|
response: RPCResponse,
|
|
188
184
|
params: Any,
|
|
189
|
-
error_formatters:
|
|
190
|
-
null_result_formatters:
|
|
185
|
+
error_formatters: Callable[..., Any] | None = None,
|
|
186
|
+
null_result_formatters: Callable[..., Any] | None = None,
|
|
191
187
|
) -> Any:
|
|
192
188
|
is_subscription_response = (
|
|
193
189
|
response.get("method") == "eth_subscription"
|
|
@@ -221,10 +217,10 @@ class RequestManager:
|
|
|
221
217
|
|
|
222
218
|
def request_blocking(
|
|
223
219
|
self,
|
|
224
|
-
method:
|
|
220
|
+
method: RPCEndpoint | Callable[..., RPCEndpoint],
|
|
225
221
|
params: Any,
|
|
226
|
-
error_formatters:
|
|
227
|
-
null_result_formatters:
|
|
222
|
+
error_formatters: Callable[..., Any] | None = None,
|
|
223
|
+
null_result_formatters: Callable[..., Any] | None = None,
|
|
228
224
|
) -> Any:
|
|
229
225
|
"""
|
|
230
226
|
Make a synchronous request using the provider
|
|
@@ -236,10 +232,10 @@ class RequestManager:
|
|
|
236
232
|
|
|
237
233
|
async def coro_request(
|
|
238
234
|
self,
|
|
239
|
-
method:
|
|
235
|
+
method: RPCEndpoint | Callable[..., RPCEndpoint],
|
|
240
236
|
params: Any,
|
|
241
|
-
error_formatters:
|
|
242
|
-
null_result_formatters:
|
|
237
|
+
error_formatters: Callable[..., Any] | None = None,
|
|
238
|
+
null_result_formatters: Callable[..., Any] | None = None,
|
|
243
239
|
) -> Any:
|
|
244
240
|
"""
|
|
245
241
|
Coroutine for making a request using the provider
|
|
@@ -262,8 +258,8 @@ class RequestManager:
|
|
|
262
258
|
return RequestBatcher(self.w3)
|
|
263
259
|
|
|
264
260
|
def _make_batch_request(
|
|
265
|
-
self, requests_info:
|
|
266
|
-
) ->
|
|
261
|
+
self, requests_info: list[tuple[tuple["RPCEndpoint", Any], tuple[Any, ...]]]
|
|
262
|
+
) -> list[RPCResponse]:
|
|
267
263
|
"""
|
|
268
264
|
Make a batch request using the provider
|
|
269
265
|
"""
|
|
@@ -291,10 +287,10 @@ class RequestManager:
|
|
|
291
287
|
|
|
292
288
|
async def _async_make_batch_request(
|
|
293
289
|
self,
|
|
294
|
-
requests_info:
|
|
295
|
-
Coroutine[Any, Any,
|
|
290
|
+
requests_info: list[
|
|
291
|
+
Coroutine[Any, Any, tuple[tuple["RPCEndpoint", Any], tuple[Any]]]
|
|
296
292
|
],
|
|
297
|
-
) ->
|
|
293
|
+
) -> list[RPCResponse]:
|
|
298
294
|
"""
|
|
299
295
|
Make an asynchronous batch request using the provider
|
|
300
296
|
"""
|
|
@@ -315,7 +311,7 @@ class RequestManager:
|
|
|
315
311
|
|
|
316
312
|
if isinstance(response, list):
|
|
317
313
|
# expected format
|
|
318
|
-
response = cast(
|
|
314
|
+
response = cast(list[RPCResponse], response)
|
|
319
315
|
formatted_responses = [
|
|
320
316
|
self._format_batched_response(info, resp)
|
|
321
317
|
for info, resp in zip(unpacked_requests_info, response)
|
|
@@ -326,8 +322,8 @@ class RequestManager:
|
|
|
326
322
|
raise_error_for_batch_response(response, self.logger)
|
|
327
323
|
|
|
328
324
|
async def _async_send_batch(
|
|
329
|
-
self, requests:
|
|
330
|
-
) ->
|
|
325
|
+
self, requests: list[tuple["RPCEndpoint", Any]]
|
|
326
|
+
) -> list[RPCRequest]:
|
|
331
327
|
"""
|
|
332
328
|
Send a batch request via socket.
|
|
333
329
|
"""
|
|
@@ -346,7 +342,7 @@ class RequestManager:
|
|
|
346
342
|
)
|
|
347
343
|
return await send_func(requests)
|
|
348
344
|
|
|
349
|
-
async def _async_recv_batch(self, requests:
|
|
345
|
+
async def _async_recv_batch(self, requests: list[RPCRequest]) -> list[RPCResponse]:
|
|
350
346
|
"""
|
|
351
347
|
Receive a batch request via socket.
|
|
352
348
|
"""
|
|
@@ -367,10 +363,10 @@ class RequestManager:
|
|
|
367
363
|
|
|
368
364
|
async def _async_make_socket_batch_request(
|
|
369
365
|
self,
|
|
370
|
-
requests_info:
|
|
371
|
-
Coroutine[Any, Any,
|
|
366
|
+
requests_info: list[
|
|
367
|
+
Coroutine[Any, Any, tuple[tuple["RPCEndpoint", Any], tuple[Any, ...]]]
|
|
372
368
|
],
|
|
373
|
-
) ->
|
|
369
|
+
) -> list[RPCResponse]:
|
|
374
370
|
"""
|
|
375
371
|
Send and receive a batch request via a socket.
|
|
376
372
|
"""
|
|
@@ -407,7 +403,7 @@ class RequestManager:
|
|
|
407
403
|
|
|
408
404
|
def _format_batched_response(
|
|
409
405
|
self,
|
|
410
|
-
requests_info:
|
|
406
|
+
requests_info: tuple[tuple[RPCEndpoint, Any], Sequence[Any]],
|
|
411
407
|
response: RPCResponse,
|
|
412
408
|
) -> RPCResponse:
|
|
413
409
|
result_formatters, error_formatters, null_result_formatters = requests_info[1]
|
|
@@ -434,9 +430,10 @@ class RequestManager:
|
|
|
434
430
|
self,
|
|
435
431
|
method: RPCEndpoint,
|
|
436
432
|
params: Any,
|
|
437
|
-
response_formatters:
|
|
438
|
-
|
|
439
|
-
|
|
433
|
+
response_formatters: None
|
|
434
|
+
| (
|
|
435
|
+
tuple[dict[str, Callable[..., Any]], Callable[..., Any], Callable[..., Any]]
|
|
436
|
+
) = None,
|
|
440
437
|
) -> RPCResponse:
|
|
441
438
|
provider = cast(PersistentConnectionProvider, self._provider)
|
|
442
439
|
self.logger.debug(
|
|
@@ -495,7 +492,7 @@ class RequestManager:
|
|
|
495
492
|
provider._request_processor._request_information_cache.pop(response_id_key)
|
|
496
493
|
raise
|
|
497
494
|
|
|
498
|
-
async def recv(self) ->
|
|
495
|
+
async def recv(self) -> RPCResponse | FormattedEthSubscriptionResponse:
|
|
499
496
|
provider = cast(PersistentConnectionProvider, self._provider)
|
|
500
497
|
self.logger.debug(
|
|
501
498
|
"Getting next response from open socket connection: %s",
|
|
@@ -559,7 +556,7 @@ class RequestManager:
|
|
|
559
556
|
|
|
560
557
|
async def _process_response(
|
|
561
558
|
self, response: RPCResponse
|
|
562
|
-
) ->
|
|
559
|
+
) -> RPCResponse | FormattedEthSubscriptionResponse:
|
|
563
560
|
provider = cast(PersistentConnectionProvider, self._provider)
|
|
564
561
|
request_info = self._request_processor.get_request_information_for_response(
|
|
565
562
|
response
|
web3/method.py
CHANGED
|
@@ -3,14 +3,9 @@ from typing import (
|
|
|
3
3
|
TYPE_CHECKING,
|
|
4
4
|
Any,
|
|
5
5
|
Callable,
|
|
6
|
-
Dict,
|
|
7
6
|
Generic,
|
|
8
|
-
List,
|
|
9
7
|
Optional,
|
|
10
8
|
Sequence,
|
|
11
|
-
Tuple,
|
|
12
|
-
Type,
|
|
13
|
-
Union,
|
|
14
9
|
)
|
|
15
10
|
import warnings
|
|
16
11
|
|
|
@@ -58,17 +53,15 @@ Munger = Callable[..., Any]
|
|
|
58
53
|
|
|
59
54
|
@to_tuple
|
|
60
55
|
def _apply_request_formatters(
|
|
61
|
-
params: Any, request_formatters:
|
|
62
|
-
) ->
|
|
56
|
+
params: Any, request_formatters: dict[RPCEndpoint, Callable[..., TReturn]]
|
|
57
|
+
) -> tuple[Any, ...]:
|
|
63
58
|
if request_formatters:
|
|
64
59
|
formatted_params = pipe(params, request_formatters)
|
|
65
60
|
return formatted_params
|
|
66
61
|
return params
|
|
67
62
|
|
|
68
63
|
|
|
69
|
-
def _set_mungers(
|
|
70
|
-
mungers: Optional[Sequence[Munger]], is_property: bool
|
|
71
|
-
) -> Sequence[Any]:
|
|
64
|
+
def _set_mungers(mungers: Sequence[Munger] | None, is_property: bool) -> Sequence[Any]:
|
|
72
65
|
if is_property and mungers:
|
|
73
66
|
raise Web3ValidationError("Mungers cannot be used with a property.")
|
|
74
67
|
|
|
@@ -81,13 +74,13 @@ def _set_mungers(
|
|
|
81
74
|
)
|
|
82
75
|
|
|
83
76
|
|
|
84
|
-
def default_munger(_module: "Module", *args: Any, **kwargs: Any) ->
|
|
77
|
+
def default_munger(_module: "Module", *args: Any, **kwargs: Any) -> tuple[()]:
|
|
85
78
|
if args or kwargs:
|
|
86
79
|
raise Web3ValidationError("Parameters cannot be passed to a property.")
|
|
87
80
|
return ()
|
|
88
81
|
|
|
89
82
|
|
|
90
|
-
def default_root_munger(_module: "Module", *args: Any) ->
|
|
83
|
+
def default_root_munger(_module: "Module", *args: Any) -> list[Any]:
|
|
91
84
|
return [*args]
|
|
92
85
|
|
|
93
86
|
|
|
@@ -134,12 +127,12 @@ class Method(Generic[TFunc]):
|
|
|
134
127
|
|
|
135
128
|
def __init__(
|
|
136
129
|
self,
|
|
137
|
-
json_rpc_method:
|
|
138
|
-
mungers:
|
|
139
|
-
request_formatters:
|
|
140
|
-
result_formatters:
|
|
141
|
-
null_result_formatters:
|
|
142
|
-
method_choice_depends_on_args:
|
|
130
|
+
json_rpc_method: RPCEndpoint | None = None,
|
|
131
|
+
mungers: Sequence[Munger] | None = None,
|
|
132
|
+
request_formatters: Callable[..., TReturn] | None = None,
|
|
133
|
+
result_formatters: Callable[..., TReturn] | None = None,
|
|
134
|
+
null_result_formatters: Callable[..., TReturn] | None = None,
|
|
135
|
+
method_choice_depends_on_args: Callable[..., RPCEndpoint] | None = None,
|
|
143
136
|
is_property: bool = False,
|
|
144
137
|
):
|
|
145
138
|
self.json_rpc_method = json_rpc_method
|
|
@@ -155,7 +148,7 @@ class Method(Generic[TFunc]):
|
|
|
155
148
|
def __get__(
|
|
156
149
|
self,
|
|
157
150
|
module: Optional["Module"] = None,
|
|
158
|
-
_type:
|
|
151
|
+
_type: type["Module"] | None = None,
|
|
159
152
|
) -> TFunc:
|
|
160
153
|
self._module = module
|
|
161
154
|
if module is None:
|
|
@@ -192,7 +185,7 @@ class Method(Generic[TFunc]):
|
|
|
192
185
|
"``json_rpc_method`` config invalid. May be a string or function"
|
|
193
186
|
)
|
|
194
187
|
|
|
195
|
-
def input_munger(self, module: "Module", args: Any, kwargs: Any) ->
|
|
188
|
+
def input_munger(self, module: "Module", args: Any, kwargs: Any) -> list[Any]:
|
|
196
189
|
# This function takes the input parameters and munges them.
|
|
197
190
|
# See the test_process_params test in ``tests/core/method-class/test_method.py``
|
|
198
191
|
# for an example with multiple mungers.
|
|
@@ -202,12 +195,12 @@ class Method(Generic[TFunc]):
|
|
|
202
195
|
|
|
203
196
|
def process_params(
|
|
204
197
|
self, module: "Module", *args: Any, **kwargs: Any
|
|
205
|
-
) ->
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
198
|
+
) -> tuple[
|
|
199
|
+
tuple[RPCEndpoint | Callable[..., RPCEndpoint], tuple[RPCEndpoint, ...]],
|
|
200
|
+
tuple[
|
|
201
|
+
TReturn | dict[str, Callable[..., Any]],
|
|
209
202
|
Callable[..., Any],
|
|
210
|
-
|
|
203
|
+
TReturn | Callable[..., Any],
|
|
211
204
|
],
|
|
212
205
|
]:
|
|
213
206
|
params = self.input_munger(module, args, kwargs)
|
|
@@ -243,9 +236,9 @@ class DeprecatedMethod:
|
|
|
243
236
|
def __init__(
|
|
244
237
|
self,
|
|
245
238
|
method: Method[Callable[..., Any]],
|
|
246
|
-
old_name:
|
|
247
|
-
new_name:
|
|
248
|
-
msg:
|
|
239
|
+
old_name: str | None = None,
|
|
240
|
+
new_name: str | None = None,
|
|
241
|
+
msg: str | None = None,
|
|
249
242
|
) -> None:
|
|
250
243
|
self.method = method
|
|
251
244
|
self.old_name = old_name
|
|
@@ -253,7 +246,7 @@ class DeprecatedMethod:
|
|
|
253
246
|
self.msg = msg
|
|
254
247
|
|
|
255
248
|
def __get__(
|
|
256
|
-
self, obj: Optional["Module"] = None, obj_type:
|
|
249
|
+
self, obj: Optional["Module"] = None, obj_type: type["Module"] | None = None
|
|
257
250
|
) -> Any:
|
|
258
251
|
message = f"{self.old_name} is deprecated in favor of {self.new_name}"
|
|
259
252
|
if self.msg is not None:
|
web3/middleware/base.py
CHANGED
|
@@ -4,9 +4,6 @@ from abc import (
|
|
|
4
4
|
from typing import (
|
|
5
5
|
TYPE_CHECKING,
|
|
6
6
|
Any,
|
|
7
|
-
List,
|
|
8
|
-
Tuple,
|
|
9
|
-
Type,
|
|
10
7
|
Union,
|
|
11
8
|
)
|
|
12
9
|
|
|
@@ -61,8 +58,8 @@ class Web3Middleware:
|
|
|
61
58
|
self, make_batch_request: "MakeBatchRequestFn"
|
|
62
59
|
) -> "MakeBatchRequestFn":
|
|
63
60
|
def middleware(
|
|
64
|
-
requests_info:
|
|
65
|
-
) -> Union[
|
|
61
|
+
requests_info: list[tuple["RPCEndpoint", Any]],
|
|
62
|
+
) -> Union[list["RPCResponse"], "RPCResponse"]:
|
|
66
63
|
req_processed = [
|
|
67
64
|
self.request_processor(method, params)
|
|
68
65
|
for (method, params) in requests_info
|
|
@@ -106,8 +103,8 @@ class Web3Middleware:
|
|
|
106
103
|
self, make_batch_request: "AsyncMakeBatchRequestFn"
|
|
107
104
|
) -> "AsyncMakeBatchRequestFn":
|
|
108
105
|
async def middleware(
|
|
109
|
-
requests_info:
|
|
110
|
-
) -> Union[
|
|
106
|
+
requests_info: list[tuple["RPCEndpoint", Any]],
|
|
107
|
+
) -> Union[list["RPCResponse"], "RPCResponse"]:
|
|
111
108
|
req_processed = [
|
|
112
109
|
await self.async_request_processor(method, params)
|
|
113
110
|
for (method, params) in requests_info
|
|
@@ -186,5 +183,5 @@ class Web3MiddlewareBuilder(Web3Middleware):
|
|
|
186
183
|
|
|
187
184
|
# --- type definitions --- #
|
|
188
185
|
|
|
189
|
-
Middleware =
|
|
186
|
+
Middleware = type[Web3Middleware]
|
|
190
187
|
MiddlewareOnion = NamedElementOnion[str, Middleware]
|