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/middleware/filter.py
CHANGED
|
@@ -5,13 +5,9 @@ from typing import (
|
|
|
5
5
|
Any,
|
|
6
6
|
AsyncIterable,
|
|
7
7
|
AsyncIterator,
|
|
8
|
-
Dict,
|
|
9
8
|
Generator,
|
|
10
9
|
Iterable,
|
|
11
10
|
Iterator,
|
|
12
|
-
List,
|
|
13
|
-
Optional,
|
|
14
|
-
Tuple,
|
|
15
11
|
Union,
|
|
16
12
|
cast,
|
|
17
13
|
)
|
|
@@ -73,7 +69,7 @@ else:
|
|
|
73
69
|
MAX_BLOCK_REQUEST = 50
|
|
74
70
|
|
|
75
71
|
|
|
76
|
-
def segment_count(start: int, stop: int, step: int = 5) -> Iterable[
|
|
72
|
+
def segment_count(start: int, stop: int, step: int = 5) -> Iterable[tuple[int, int]]:
|
|
77
73
|
"""
|
|
78
74
|
Creates a segment counting generator
|
|
79
75
|
|
|
@@ -104,7 +100,7 @@ def segment_count(start: int, stop: int, step: int = 5) -> Iterable[Tuple[int, i
|
|
|
104
100
|
return gen_bounded_segments(start, stop, step)
|
|
105
101
|
|
|
106
102
|
|
|
107
|
-
def gen_bounded_segments(start: int, stop: int, step: int) -> Iterable[
|
|
103
|
+
def gen_bounded_segments(start: int, stop: int, step: int) -> Iterable[tuple[int, int]]:
|
|
108
104
|
# If the initial range is less than the step
|
|
109
105
|
# just return (start, stop)
|
|
110
106
|
if start + step >= stop:
|
|
@@ -121,8 +117,8 @@ def gen_bounded_segments(start: int, stop: int, step: int) -> Iterable[Tuple[int
|
|
|
121
117
|
|
|
122
118
|
|
|
123
119
|
def block_ranges(
|
|
124
|
-
start_block: BlockNumber, last_block:
|
|
125
|
-
) -> Iterable[
|
|
120
|
+
start_block: BlockNumber, last_block: BlockNumber | None, step: int = 5
|
|
121
|
+
) -> Iterable[tuple[BlockNumber, BlockNumber]]:
|
|
126
122
|
"""
|
|
127
123
|
Returns 2-tuple ranges describing ranges of block from start_block to last_block
|
|
128
124
|
|
|
@@ -142,7 +138,7 @@ def block_ranges(
|
|
|
142
138
|
|
|
143
139
|
|
|
144
140
|
def iter_latest_block(
|
|
145
|
-
w3: "Web3", to_block:
|
|
141
|
+
w3: "Web3", to_block: BlockNumber | LatestBlockParam | None = None
|
|
146
142
|
) -> Iterable[BlockNumber]:
|
|
147
143
|
"""
|
|
148
144
|
Returns a generator that dispenses the latest block, if
|
|
@@ -180,8 +176,8 @@ def iter_latest_block(
|
|
|
180
176
|
def iter_latest_block_ranges(
|
|
181
177
|
w3: "Web3",
|
|
182
178
|
from_block: BlockNumber,
|
|
183
|
-
to_block:
|
|
184
|
-
) -> Iterable[
|
|
179
|
+
to_block: BlockNumber | LatestBlockParam | None = None,
|
|
180
|
+
) -> Iterable[tuple[BlockNumber | None, BlockNumber | None]]:
|
|
185
181
|
"""
|
|
186
182
|
Returns an iterator unloading ranges of available blocks
|
|
187
183
|
|
|
@@ -207,7 +203,7 @@ def iter_latest_block_ranges(
|
|
|
207
203
|
from_block = BlockNumber(latest_block + 1)
|
|
208
204
|
|
|
209
205
|
|
|
210
|
-
def drop_items_with_none_value(params:
|
|
206
|
+
def drop_items_with_none_value(params: dict[str, Any]) -> dict[str, Any]:
|
|
211
207
|
return valfilter(lambda x: x is not None, params)
|
|
212
208
|
|
|
213
209
|
|
|
@@ -215,10 +211,10 @@ def get_logs_multipart(
|
|
|
215
211
|
w3: "Web3",
|
|
216
212
|
start_block: BlockNumber,
|
|
217
213
|
stop_block: BlockNumber,
|
|
218
|
-
address:
|
|
219
|
-
topics:
|
|
214
|
+
address: Address | ChecksumAddress | list[Address | ChecksumAddress],
|
|
215
|
+
topics: list[_Hash32 | list[_Hash32] | None],
|
|
220
216
|
max_blocks: int,
|
|
221
|
-
) -> Iterable[
|
|
217
|
+
) -> Iterable[list[LogReceipt]]:
|
|
222
218
|
"""
|
|
223
219
|
Used to break up requests to ``eth_getLogs``
|
|
224
220
|
|
|
@@ -242,12 +238,11 @@ class RequestLogs:
|
|
|
242
238
|
def __init__(
|
|
243
239
|
self,
|
|
244
240
|
w3: "Web3",
|
|
245
|
-
from_block:
|
|
246
|
-
to_block:
|
|
247
|
-
address:
|
|
248
|
-
|
|
249
|
-
] = None,
|
|
250
|
-
topics: Optional[List[Optional[Union[_Hash32, List[_Hash32]]]]] = None,
|
|
241
|
+
from_block: BlockNumber | LatestBlockParam | None = None,
|
|
242
|
+
to_block: BlockNumber | LatestBlockParam | None = None,
|
|
243
|
+
address: None
|
|
244
|
+
| (Address | ChecksumAddress | list[Address | ChecksumAddress]) = None,
|
|
245
|
+
topics: list[_Hash32 | list[_Hash32] | None] | None = None,
|
|
251
246
|
) -> None:
|
|
252
247
|
self.address = address
|
|
253
248
|
self.topics = topics
|
|
@@ -278,7 +273,7 @@ class RequestLogs:
|
|
|
278
273
|
|
|
279
274
|
return to_block
|
|
280
275
|
|
|
281
|
-
def _get_filter_changes(self) -> Iterator[
|
|
276
|
+
def _get_filter_changes(self) -> Iterator[list[LogReceipt]]:
|
|
282
277
|
for start, stop in iter_latest_block_ranges(
|
|
283
278
|
self.w3, self.from_block, self.to_block
|
|
284
279
|
):
|
|
@@ -298,7 +293,7 @@ class RequestLogs:
|
|
|
298
293
|
)
|
|
299
294
|
)
|
|
300
295
|
|
|
301
|
-
def get_logs(self) ->
|
|
296
|
+
def get_logs(self) -> list[LogReceipt]:
|
|
302
297
|
return list(
|
|
303
298
|
concat(
|
|
304
299
|
get_logs_multipart(
|
|
@@ -332,10 +327,10 @@ class RequestBlocks:
|
|
|
332
327
|
self.start_block = BlockNumber(w3.eth.block_number + 1)
|
|
333
328
|
|
|
334
329
|
@property
|
|
335
|
-
def filter_changes(self) -> Iterator[
|
|
330
|
+
def filter_changes(self) -> Iterator[list[Hash32]]:
|
|
336
331
|
return self.get_filter_changes()
|
|
337
332
|
|
|
338
|
-
def get_filter_changes(self) -> Iterator[
|
|
333
|
+
def get_filter_changes(self) -> Iterator[list[Hash32]]:
|
|
339
334
|
block_range_iter = iter_latest_block_ranges(self.w3, self.start_block, None)
|
|
340
335
|
|
|
341
336
|
for block_range in block_range_iter:
|
|
@@ -344,7 +339,7 @@ class RequestBlocks:
|
|
|
344
339
|
|
|
345
340
|
@to_list
|
|
346
341
|
def block_hashes_in_range(
|
|
347
|
-
w3: "Web3", block_range:
|
|
342
|
+
w3: "Web3", block_range: tuple[BlockNumber, BlockNumber]
|
|
348
343
|
) -> Iterable[Hash32]:
|
|
349
344
|
from_block, to_block = block_range
|
|
350
345
|
if from_block is None or to_block is None:
|
|
@@ -358,7 +353,7 @@ def block_hashes_in_range(
|
|
|
358
353
|
|
|
359
354
|
async def async_iter_latest_block(
|
|
360
355
|
w3: "AsyncWeb3[Any]",
|
|
361
|
-
to_block:
|
|
356
|
+
to_block: BlockNumber | LatestBlockParam | None = None,
|
|
362
357
|
) -> AsyncIterable[BlockNumber]:
|
|
363
358
|
"""
|
|
364
359
|
Returns a generator that dispenses the latest block, if
|
|
@@ -397,8 +392,8 @@ async def async_iter_latest_block(
|
|
|
397
392
|
async def async_iter_latest_block_ranges(
|
|
398
393
|
w3: "AsyncWeb3[Any]",
|
|
399
394
|
from_block: BlockNumber,
|
|
400
|
-
to_block:
|
|
401
|
-
) -> AsyncIterable[
|
|
395
|
+
to_block: BlockNumber | LatestBlockParam | None = None,
|
|
396
|
+
) -> AsyncIterable[tuple[BlockNumber | None, BlockNumber | None]]:
|
|
402
397
|
"""
|
|
403
398
|
Returns an iterator unloading ranges of available blocks
|
|
404
399
|
|
|
@@ -429,10 +424,10 @@ async def async_get_logs_multipart(
|
|
|
429
424
|
w3: "AsyncWeb3[Any]",
|
|
430
425
|
start_block: BlockNumber,
|
|
431
426
|
stop_block: BlockNumber,
|
|
432
|
-
address:
|
|
433
|
-
topics:
|
|
427
|
+
address: Address | ChecksumAddress | list[Address | ChecksumAddress],
|
|
428
|
+
topics: list[_Hash32 | list[_Hash32] | None],
|
|
434
429
|
max_blocks: int,
|
|
435
|
-
) -> AsyncIterable[
|
|
430
|
+
) -> AsyncIterable[list[LogReceipt]]:
|
|
436
431
|
"""
|
|
437
432
|
Used to break up requests to ``eth_getLogs``
|
|
438
433
|
|
|
@@ -460,12 +455,12 @@ class AsyncRequestLogs:
|
|
|
460
455
|
def __init__(
|
|
461
456
|
self,
|
|
462
457
|
w3: "AsyncWeb3[Any]",
|
|
463
|
-
from_block:
|
|
464
|
-
to_block:
|
|
465
|
-
address:
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
topics:
|
|
458
|
+
from_block: BlockNumber | LatestBlockParam | None = None,
|
|
459
|
+
to_block: BlockNumber | LatestBlockParam | None = None,
|
|
460
|
+
address: (
|
|
461
|
+
Address | ChecksumAddress | list[Address | ChecksumAddress] | None
|
|
462
|
+
) = None,
|
|
463
|
+
topics: list[_Hash32 | list[_Hash32] | None] | None = None,
|
|
469
464
|
) -> None:
|
|
470
465
|
self.address = address
|
|
471
466
|
self.topics = topics
|
|
@@ -505,7 +500,7 @@ class AsyncRequestLogs:
|
|
|
505
500
|
|
|
506
501
|
return to_block
|
|
507
502
|
|
|
508
|
-
async def _get_filter_changes(self) -> AsyncIterator[
|
|
503
|
+
async def _get_filter_changes(self) -> AsyncIterator[list[LogReceipt]]:
|
|
509
504
|
self_from_block = await self.from_block
|
|
510
505
|
self_to_block = await self.to_block
|
|
511
506
|
async for start, stop in async_iter_latest_block_ranges(
|
|
@@ -527,7 +522,7 @@ class AsyncRequestLogs:
|
|
|
527
522
|
for item in sublist
|
|
528
523
|
]
|
|
529
524
|
|
|
530
|
-
async def get_logs(self) ->
|
|
525
|
+
async def get_logs(self) -> list[LogReceipt]:
|
|
531
526
|
self_from_block = await self.from_block
|
|
532
527
|
self_to_block = await self.to_block
|
|
533
528
|
return [
|
|
@@ -557,10 +552,10 @@ class AsyncRequestBlocks:
|
|
|
557
552
|
return closure().__await__()
|
|
558
553
|
|
|
559
554
|
@property
|
|
560
|
-
def filter_changes(self) -> AsyncIterator[
|
|
555
|
+
def filter_changes(self) -> AsyncIterator[list[Hash32]]:
|
|
561
556
|
return self.get_filter_changes()
|
|
562
557
|
|
|
563
|
-
async def get_filter_changes(self) -> AsyncIterator[
|
|
558
|
+
async def get_filter_changes(self) -> AsyncIterator[list[Hash32]]:
|
|
564
559
|
block_range_iter = async_iter_latest_block_ranges(
|
|
565
560
|
self.w3, self.start_block, None
|
|
566
561
|
)
|
|
@@ -570,8 +565,8 @@ class AsyncRequestBlocks:
|
|
|
570
565
|
|
|
571
566
|
|
|
572
567
|
async def async_block_hashes_in_range(
|
|
573
|
-
w3: "AsyncWeb3[Any]", block_range:
|
|
574
|
-
) ->
|
|
568
|
+
w3: "AsyncWeb3[Any]", block_range: tuple[BlockNumber, BlockNumber]
|
|
569
|
+
) -> list[None | Hash32]:
|
|
575
570
|
from_block, to_block = block_range
|
|
576
571
|
if from_block is None or to_block is None:
|
|
577
572
|
return []
|
|
@@ -596,8 +591,8 @@ def _simulate_rpc_response_with_result(filter_id: str) -> "RPCResponse":
|
|
|
596
591
|
|
|
597
592
|
class LocalFilterMiddleware(Web3Middleware):
|
|
598
593
|
def __init__(self, w3: Union["Web3", "AsyncWeb3[Any]"]):
|
|
599
|
-
self.filters:
|
|
600
|
-
self.async_filters:
|
|
594
|
+
self.filters: dict[str, SyncFilter] = {}
|
|
595
|
+
self.async_filters: dict[str, AsyncFilter] = {}
|
|
601
596
|
self.filter_id_counter = itertools.count()
|
|
602
597
|
super().__init__(w3)
|
|
603
598
|
|
web3/middleware/formatting.py
CHANGED
|
@@ -4,7 +4,6 @@ from typing import (
|
|
|
4
4
|
Callable,
|
|
5
5
|
Coroutine,
|
|
6
6
|
Literal,
|
|
7
|
-
Optional,
|
|
8
7
|
Union,
|
|
9
8
|
cast,
|
|
10
9
|
)
|
|
@@ -116,12 +115,12 @@ class FormattingMiddlewareBuilder(Web3MiddlewareBuilder):
|
|
|
116
115
|
def build(
|
|
117
116
|
w3: Union["Web3", "AsyncWeb3[Any]"],
|
|
118
117
|
# formatters option:
|
|
119
|
-
request_formatters:
|
|
120
|
-
result_formatters:
|
|
121
|
-
error_formatters:
|
|
118
|
+
request_formatters: Formatters | None = None,
|
|
119
|
+
result_formatters: Formatters | None = None,
|
|
120
|
+
error_formatters: Formatters | None = None,
|
|
122
121
|
# formatters builder option:
|
|
123
|
-
sync_formatters_builder:
|
|
124
|
-
async_formatters_builder:
|
|
122
|
+
sync_formatters_builder: SYNC_FORMATTERS_BUILDER | None = None,
|
|
123
|
+
async_formatters_builder: ASYNC_FORMATTERS_BUILDER | None = None,
|
|
125
124
|
) -> "FormattingMiddlewareBuilder":
|
|
126
125
|
# if not both sync and async formatters are specified, raise error
|
|
127
126
|
if (
|
web3/middleware/names.py
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
from typing import (
|
|
2
2
|
TYPE_CHECKING,
|
|
3
3
|
Any,
|
|
4
|
-
Dict,
|
|
5
4
|
Sequence,
|
|
6
|
-
Union,
|
|
7
5
|
cast,
|
|
8
6
|
)
|
|
9
7
|
|
|
@@ -71,7 +69,7 @@ async def async_format_all_ens_names_to_address(
|
|
|
71
69
|
async def async_apply_ens_to_address_conversion(
|
|
72
70
|
async_web3: "AsyncWeb3[Any]",
|
|
73
71
|
params: Any,
|
|
74
|
-
abi_types_for_method:
|
|
72
|
+
abi_types_for_method: Sequence[str] | dict[str, str],
|
|
75
73
|
) -> Any:
|
|
76
74
|
if isinstance(abi_types_for_method, Sequence):
|
|
77
75
|
formatted_params = await async_format_all_ens_names_to_address(
|
web3/middleware/signing.py
CHANGED
|
@@ -7,7 +7,6 @@ from typing import (
|
|
|
7
7
|
Any,
|
|
8
8
|
Collection,
|
|
9
9
|
Iterable,
|
|
10
|
-
Tuple,
|
|
11
10
|
TypeVar,
|
|
12
11
|
Union,
|
|
13
12
|
cast,
|
|
@@ -93,8 +92,8 @@ _PrivateKey = Union[LocalAccount, PrivateKey, HexStr, bytes]
|
|
|
93
92
|
|
|
94
93
|
@to_dict
|
|
95
94
|
def gen_normalized_accounts(
|
|
96
|
-
val:
|
|
97
|
-
) -> Iterable[
|
|
95
|
+
val: _PrivateKey | Collection[_PrivateKey],
|
|
96
|
+
) -> Iterable[tuple[ChecksumAddress, LocalAccount]]:
|
|
98
97
|
if isinstance(
|
|
99
98
|
val,
|
|
100
99
|
(
|
|
@@ -157,7 +156,7 @@ class SignAndSendRawMiddlewareBuilder(Web3MiddlewareBuilder):
|
|
|
157
156
|
@staticmethod
|
|
158
157
|
@curry
|
|
159
158
|
def build(
|
|
160
|
-
private_key_or_account:
|
|
159
|
+
private_key_or_account: _PrivateKey | Collection[_PrivateKey],
|
|
161
160
|
w3: Union["Web3", "AsyncWeb3[Any]"],
|
|
162
161
|
) -> "SignAndSendRawMiddlewareBuilder":
|
|
163
162
|
middleware = SignAndSendRawMiddlewareBuilder(w3)
|
web3/middleware/stalecheck.py
CHANGED
|
@@ -2,7 +2,6 @@ import time
|
|
|
2
2
|
from typing import ( # noqa: F401
|
|
3
3
|
TYPE_CHECKING,
|
|
4
4
|
Any,
|
|
5
|
-
Callable,
|
|
6
5
|
Collection,
|
|
7
6
|
Dict,
|
|
8
7
|
Optional,
|
|
@@ -45,7 +44,7 @@ def _is_fresh(block: BlockData, allowable_delay: int) -> bool:
|
|
|
45
44
|
class StalecheckMiddlewareBuilder(Web3MiddlewareBuilder):
|
|
46
45
|
allowable_delay: int
|
|
47
46
|
skip_stalecheck_for_methods: Collection[str]
|
|
48
|
-
cache:
|
|
47
|
+
cache: dict[str, BlockData | None]
|
|
49
48
|
|
|
50
49
|
@staticmethod
|
|
51
50
|
@curry
|
web3/middleware/validation.py
CHANGED
|
@@ -2,7 +2,6 @@ from typing import (
|
|
|
2
2
|
TYPE_CHECKING,
|
|
3
3
|
Any,
|
|
4
4
|
Callable,
|
|
5
|
-
Dict,
|
|
6
5
|
)
|
|
7
6
|
|
|
8
7
|
from eth_utils.curried import (
|
|
@@ -121,7 +120,7 @@ def _chain_id_validator(web3_chain_id: int) -> Callable[..., Any]:
|
|
|
121
120
|
|
|
122
121
|
|
|
123
122
|
def _build_formatters_dict(
|
|
124
|
-
request_formatters:
|
|
123
|
+
request_formatters: dict[RPCEndpoint, Any],
|
|
125
124
|
) -> FormattersDict:
|
|
126
125
|
return dict(
|
|
127
126
|
request_formatters=request_formatters,
|
web3/module.py
CHANGED
|
@@ -3,10 +3,7 @@ from typing import (
|
|
|
3
3
|
Any,
|
|
4
4
|
Callable,
|
|
5
5
|
Coroutine,
|
|
6
|
-
Dict,
|
|
7
|
-
Optional,
|
|
8
6
|
Sequence,
|
|
9
|
-
Tuple,
|
|
10
7
|
TypeVar,
|
|
11
8
|
Union,
|
|
12
9
|
cast,
|
|
@@ -63,13 +60,13 @@ def retrieve_request_information_for_batching(
|
|
|
63
60
|
w3: Union["AsyncWeb3[Any]", "Web3"],
|
|
64
61
|
module: "Module",
|
|
65
62
|
method: Method[Callable[..., Any]],
|
|
66
|
-
) ->
|
|
67
|
-
Callable[...,
|
|
68
|
-
Callable[..., Coroutine[Any, Any,
|
|
69
|
-
|
|
63
|
+
) -> (
|
|
64
|
+
Callable[..., tuple[tuple[RPCEndpoint, Any], Sequence[Any]]]
|
|
65
|
+
| Callable[..., Coroutine[Any, Any, tuple[tuple[RPCEndpoint, Any], Sequence[Any]]]]
|
|
66
|
+
):
|
|
70
67
|
async def async_inner(
|
|
71
68
|
*args: Any, **kwargs: Any
|
|
72
|
-
) ->
|
|
69
|
+
) -> tuple[tuple[RPCEndpoint, Any], Sequence[Any]]:
|
|
73
70
|
(method_str, params), response_formatters = method.process_params(
|
|
74
71
|
module, *args, **kwargs
|
|
75
72
|
)
|
|
@@ -81,7 +78,7 @@ def retrieve_request_information_for_batching(
|
|
|
81
78
|
|
|
82
79
|
def inner(
|
|
83
80
|
*args: Any, **kwargs: Any
|
|
84
|
-
) ->
|
|
81
|
+
) -> tuple[tuple[RPCEndpoint, Any], Sequence[Any]]:
|
|
85
82
|
(method_str, params), response_formatters = method.process_params(
|
|
86
83
|
module, *args, **kwargs
|
|
87
84
|
)
|
|
@@ -95,8 +92,8 @@ def retrieve_blocking_method_call_fn(
|
|
|
95
92
|
w3: "Web3",
|
|
96
93
|
module: "Module",
|
|
97
94
|
method: Method[Callable[..., TReturn]],
|
|
98
|
-
) -> Callable[...,
|
|
99
|
-
def caller(*args: Any, **kwargs: Any) ->
|
|
95
|
+
) -> Callable[..., TReturn | LogFilter]:
|
|
96
|
+
def caller(*args: Any, **kwargs: Any) -> TReturn | LogFilter:
|
|
100
97
|
try:
|
|
101
98
|
(method_str, params), response_formatters = method.process_params(
|
|
102
99
|
module, *args, **kwargs
|
|
@@ -127,12 +124,12 @@ def retrieve_async_method_call_fn(
|
|
|
127
124
|
Coroutine[
|
|
128
125
|
Any,
|
|
129
126
|
Any,
|
|
130
|
-
|
|
127
|
+
RPCResponse | FormattedEthSubscriptionResponse | AsyncLogFilter | None,
|
|
131
128
|
],
|
|
132
129
|
]:
|
|
133
130
|
async def caller(
|
|
134
131
|
*args: Any, **kwargs: Any
|
|
135
|
-
) ->
|
|
132
|
+
) -> RPCResponse | FormattedEthSubscriptionResponse | AsyncLogFilter:
|
|
136
133
|
try:
|
|
137
134
|
(method_str, params), response_formatters = method.process_params(
|
|
138
135
|
module, *args, **kwargs
|
|
@@ -184,7 +181,7 @@ class Module:
|
|
|
184
181
|
|
|
185
182
|
def attach_methods(
|
|
186
183
|
self,
|
|
187
|
-
methods:
|
|
184
|
+
methods: dict[str, Method[Callable[..., Any]]],
|
|
188
185
|
) -> None:
|
|
189
186
|
for method_name, method_class in methods.items():
|
|
190
187
|
klass = (
|
web3/providers/__init__.py
CHANGED
|
@@ -18,9 +18,6 @@ from .ipc import (
|
|
|
18
18
|
from .rpc import (
|
|
19
19
|
HTTPProvider,
|
|
20
20
|
)
|
|
21
|
-
from .legacy_websocket import (
|
|
22
|
-
LegacyWebSocketProvider,
|
|
23
|
-
)
|
|
24
21
|
from .persistent import (
|
|
25
22
|
AsyncIPCProvider,
|
|
26
23
|
PersistentConnection,
|
|
@@ -42,7 +39,6 @@ __all__ = [
|
|
|
42
39
|
"HTTPProvider",
|
|
43
40
|
"IPCProvider",
|
|
44
41
|
"JSONBaseProvider",
|
|
45
|
-
"LegacyWebSocketProvider",
|
|
46
42
|
"PersistentConnection",
|
|
47
43
|
"PersistentConnectionProvider",
|
|
48
44
|
"WebSocketProvider",
|
web3/providers/async_base.py
CHANGED
|
@@ -7,12 +7,7 @@ from typing import (
|
|
|
7
7
|
Any,
|
|
8
8
|
Callable,
|
|
9
9
|
Coroutine,
|
|
10
|
-
Dict,
|
|
11
|
-
List,
|
|
12
10
|
Optional,
|
|
13
|
-
Set,
|
|
14
|
-
Tuple,
|
|
15
|
-
Union,
|
|
16
11
|
cast,
|
|
17
12
|
)
|
|
18
13
|
|
|
@@ -54,8 +49,8 @@ from web3.utils import (
|
|
|
54
49
|
)
|
|
55
50
|
|
|
56
51
|
if TYPE_CHECKING:
|
|
57
|
-
from websockets.
|
|
58
|
-
|
|
52
|
+
from websockets.asyncio.client import (
|
|
53
|
+
ClientConnection,
|
|
59
54
|
)
|
|
60
55
|
|
|
61
56
|
from web3 import ( # noqa: F401
|
|
@@ -75,8 +70,8 @@ class AsyncBaseProvider:
|
|
|
75
70
|
logger: logging.Logger = logging.getLogger(
|
|
76
71
|
"web3.providers.async_base.AsyncBaseProvider"
|
|
77
72
|
)
|
|
78
|
-
_request_func_cache:
|
|
79
|
-
|
|
73
|
+
_request_func_cache: tuple[
|
|
74
|
+
tuple[Middleware, ...], Callable[..., Coroutine[Any, Any, RPCResponse]]
|
|
80
75
|
] = (None, None)
|
|
81
76
|
|
|
82
77
|
is_async = True
|
|
@@ -87,10 +82,9 @@ class AsyncBaseProvider:
|
|
|
87
82
|
def __init__(
|
|
88
83
|
self,
|
|
89
84
|
cache_allowed_requests: bool = False,
|
|
90
|
-
cacheable_requests:
|
|
91
|
-
request_cache_validation_threshold:
|
|
92
|
-
|
|
93
|
-
] = empty,
|
|
85
|
+
cacheable_requests: set[RPCEndpoint] = None,
|
|
86
|
+
request_cache_validation_threshold: None
|
|
87
|
+
| (RequestCacheValidationThreshold | int | Empty) = empty,
|
|
94
88
|
) -> None:
|
|
95
89
|
self._request_cache = SimpleCache(1000)
|
|
96
90
|
self._request_cache_lock: asyncio.Lock = asyncio.Lock()
|
|
@@ -102,9 +96,9 @@ class AsyncBaseProvider:
|
|
|
102
96
|
self._batching_context: contextvars.ContextVar[
|
|
103
97
|
Optional["RequestBatcher[Any]"]
|
|
104
98
|
] = contextvars.ContextVar("batching_context", default=None)
|
|
105
|
-
self._batch_request_func_cache:
|
|
106
|
-
|
|
107
|
-
Callable[..., Coroutine[Any, Any,
|
|
99
|
+
self._batch_request_func_cache: tuple[
|
|
100
|
+
tuple[Middleware, ...],
|
|
101
|
+
Callable[..., Coroutine[Any, Any, list[RPCResponse] | RPCResponse]],
|
|
108
102
|
] = (None, None)
|
|
109
103
|
|
|
110
104
|
@property
|
|
@@ -114,7 +108,7 @@ class AsyncBaseProvider:
|
|
|
114
108
|
async def request_func(
|
|
115
109
|
self, async_w3: "AsyncWeb3[Any]", middleware_onion: MiddlewareOnion
|
|
116
110
|
) -> Callable[..., Coroutine[Any, Any, RPCResponse]]:
|
|
117
|
-
middleware:
|
|
111
|
+
middleware: tuple[Middleware, ...] = middleware_onion.as_tuple_of_middleware()
|
|
118
112
|
|
|
119
113
|
cache_key = self._request_func_cache[0]
|
|
120
114
|
if cache_key != middleware:
|
|
@@ -130,8 +124,8 @@ class AsyncBaseProvider:
|
|
|
130
124
|
|
|
131
125
|
async def batch_request_func(
|
|
132
126
|
self, async_w3: "AsyncWeb3[Any]", middleware_onion: MiddlewareOnion
|
|
133
|
-
) -> Callable[..., Coroutine[Any, Any,
|
|
134
|
-
middleware:
|
|
127
|
+
) -> Callable[..., Coroutine[Any, Any, list[RPCResponse] | RPCResponse]]:
|
|
128
|
+
middleware: tuple[Middleware, ...] = middleware_onion.as_tuple_of_middleware()
|
|
135
129
|
|
|
136
130
|
cache_key = self._batch_request_func_cache[0]
|
|
137
131
|
if cache_key != middleware:
|
|
@@ -151,8 +145,8 @@ class AsyncBaseProvider:
|
|
|
151
145
|
raise NotImplementedError("Providers must implement this method")
|
|
152
146
|
|
|
153
147
|
async def make_batch_request(
|
|
154
|
-
self, requests:
|
|
155
|
-
) ->
|
|
148
|
+
self, requests: list[tuple[RPCEndpoint, Any]]
|
|
149
|
+
) -> list[RPCResponse] | RPCResponse:
|
|
156
150
|
raise NotImplementedError("Providers must implement this method")
|
|
157
151
|
|
|
158
152
|
async def is_connected(self, show_traceback: bool = False) -> bool:
|
|
@@ -175,11 +169,11 @@ class AsyncBaseProvider:
|
|
|
175
169
|
)
|
|
176
170
|
|
|
177
171
|
# WebSocket typing
|
|
178
|
-
_ws: "
|
|
172
|
+
_ws: "ClientConnection"
|
|
179
173
|
|
|
180
174
|
# IPC typing
|
|
181
|
-
_reader:
|
|
182
|
-
_writer:
|
|
175
|
+
_reader: asyncio.StreamReader | None
|
|
176
|
+
_writer: asyncio.StreamWriter | None
|
|
183
177
|
|
|
184
178
|
|
|
185
179
|
class AsyncJSONBaseProvider(AsyncBaseProvider):
|
|
@@ -200,7 +194,7 @@ class AsyncJSONBaseProvider(AsyncBaseProvider):
|
|
|
200
194
|
@staticmethod
|
|
201
195
|
def encode_rpc_dict(rpc_dict: RPCRequest) -> bytes:
|
|
202
196
|
encoded = FriendlyJsonSerde().json_encode(
|
|
203
|
-
cast(
|
|
197
|
+
cast(dict[str, Any], rpc_dict), cls=Web3JsonEncoder
|
|
204
198
|
)
|
|
205
199
|
return to_bytes(text=encoded)
|
|
206
200
|
|
|
@@ -242,7 +236,7 @@ class AsyncJSONBaseProvider(AsyncBaseProvider):
|
|
|
242
236
|
# -- batch requests -- #
|
|
243
237
|
|
|
244
238
|
def encode_batch_rpc_request(
|
|
245
|
-
self, requests:
|
|
239
|
+
self, requests: list[tuple[RPCEndpoint, Any]]
|
|
246
240
|
) -> bytes:
|
|
247
241
|
return (
|
|
248
242
|
b"["
|
|
@@ -252,5 +246,5 @@ class AsyncJSONBaseProvider(AsyncBaseProvider):
|
|
|
252
246
|
+ b"]"
|
|
253
247
|
)
|
|
254
248
|
|
|
255
|
-
def encode_batch_request_dicts(self, request_dicts:
|
|
249
|
+
def encode_batch_request_dicts(self, request_dicts: list[RPCRequest]) -> bytes:
|
|
256
250
|
return b"[" + b",".join(self.encode_rpc_dict(d) for d in request_dicts) + b"]"
|
web3/providers/auto.py
CHANGED
|
@@ -2,13 +2,7 @@ import os
|
|
|
2
2
|
from typing import (
|
|
3
3
|
Any,
|
|
4
4
|
Callable,
|
|
5
|
-
Dict,
|
|
6
|
-
List,
|
|
7
|
-
Optional,
|
|
8
5
|
Sequence,
|
|
9
|
-
Tuple,
|
|
10
|
-
Type,
|
|
11
|
-
Union,
|
|
12
6
|
)
|
|
13
7
|
from urllib.parse import (
|
|
14
8
|
urlparse,
|
|
@@ -25,7 +19,6 @@ from web3.providers import (
|
|
|
25
19
|
HTTPProvider,
|
|
26
20
|
IPCProvider,
|
|
27
21
|
JSONBaseProvider,
|
|
28
|
-
LegacyWebSocketProvider,
|
|
29
22
|
)
|
|
30
23
|
from web3.types import (
|
|
31
24
|
RPCEndpoint,
|
|
@@ -36,7 +29,7 @@ HTTP_SCHEMES = {"http", "https"}
|
|
|
36
29
|
WS_SCHEMES = {"ws", "wss"}
|
|
37
30
|
|
|
38
31
|
|
|
39
|
-
def load_provider_from_environment() ->
|
|
32
|
+
def load_provider_from_environment() -> JSONBaseProvider | None:
|
|
40
33
|
uri_string = URI(os.environ.get("WEB3_PROVIDER_URI", ""))
|
|
41
34
|
if not uri_string:
|
|
42
35
|
return None
|
|
@@ -45,15 +38,13 @@ def load_provider_from_environment() -> Optional[JSONBaseProvider]:
|
|
|
45
38
|
|
|
46
39
|
|
|
47
40
|
def load_provider_from_uri(
|
|
48
|
-
uri_string: URI, headers:
|
|
41
|
+
uri_string: URI, headers: dict[str, tuple[str, str]] | None = None
|
|
49
42
|
) -> JSONBaseProvider:
|
|
50
43
|
uri = urlparse(uri_string)
|
|
51
44
|
if uri.scheme == "file":
|
|
52
45
|
return IPCProvider(uri.path)
|
|
53
46
|
elif uri.scheme in HTTP_SCHEMES:
|
|
54
47
|
return HTTPProvider(uri_string, headers)
|
|
55
|
-
elif uri.scheme in WS_SCHEMES:
|
|
56
|
-
return LegacyWebSocketProvider(uri_string)
|
|
57
48
|
else:
|
|
58
49
|
raise NotImplementedError(
|
|
59
50
|
"Web3 does not know how to connect to scheme "
|
|
@@ -66,15 +57,13 @@ class AutoProvider(JSONBaseProvider):
|
|
|
66
57
|
load_provider_from_environment,
|
|
67
58
|
IPCProvider,
|
|
68
59
|
HTTPProvider,
|
|
69
|
-
LegacyWebSocketProvider,
|
|
70
60
|
)
|
|
71
61
|
_active_provider = None
|
|
72
62
|
|
|
73
63
|
def __init__(
|
|
74
64
|
self,
|
|
75
|
-
potential_providers:
|
|
76
|
-
|
|
77
|
-
] = None,
|
|
65
|
+
potential_providers: None
|
|
66
|
+
| (Sequence[Callable[..., JSONBaseProvider] | type[JSONBaseProvider]]) = None,
|
|
78
67
|
) -> None:
|
|
79
68
|
"""
|
|
80
69
|
:param iterable potential_providers: ordered series of provider classes
|
|
@@ -97,8 +86,8 @@ class AutoProvider(JSONBaseProvider):
|
|
|
97
86
|
return self._proxy_request(method, params, use_cache=False)
|
|
98
87
|
|
|
99
88
|
def make_batch_request(
|
|
100
|
-
self, requests:
|
|
101
|
-
) ->
|
|
89
|
+
self, requests: list[tuple[RPCEndpoint, Any]]
|
|
90
|
+
) -> list[RPCResponse] | RPCResponse:
|
|
102
91
|
try:
|
|
103
92
|
return self._proxy_batch_request(requests)
|
|
104
93
|
except OSError:
|
|
@@ -121,8 +110,8 @@ class AutoProvider(JSONBaseProvider):
|
|
|
121
110
|
return provider.make_request(method, params)
|
|
122
111
|
|
|
123
112
|
def _proxy_batch_request(
|
|
124
|
-
self, requests:
|
|
125
|
-
) ->
|
|
113
|
+
self, requests: list[tuple[RPCEndpoint, Any]], use_cache: bool = True
|
|
114
|
+
) -> list[RPCResponse] | RPCResponse:
|
|
126
115
|
provider = self._get_active_provider(use_cache)
|
|
127
116
|
if provider is None:
|
|
128
117
|
raise CannotHandleRequest(
|
|
@@ -132,7 +121,7 @@ class AutoProvider(JSONBaseProvider):
|
|
|
132
121
|
|
|
133
122
|
return provider.make_batch_request(requests)
|
|
134
123
|
|
|
135
|
-
def _get_active_provider(self, use_cache: bool) ->
|
|
124
|
+
def _get_active_provider(self, use_cache: bool) -> JSONBaseProvider | None:
|
|
136
125
|
if use_cache and self._active_provider is not None:
|
|
137
126
|
return self._active_provider
|
|
138
127
|
|