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
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
iscoroutinefunction,
|
|
3
|
-
)
|
|
4
|
-
import copy
|
|
1
|
+
import inspect
|
|
5
2
|
from typing import (
|
|
6
3
|
TYPE_CHECKING,
|
|
7
4
|
Any,
|
|
8
|
-
Dict,
|
|
9
5
|
Union,
|
|
10
6
|
cast,
|
|
11
7
|
)
|
|
@@ -98,9 +94,9 @@ class RequestMocker:
|
|
|
98
94
|
def __init__(
|
|
99
95
|
self,
|
|
100
96
|
w3: Union["AsyncWeb3[Any]", "Web3"],
|
|
101
|
-
mock_results:
|
|
102
|
-
mock_errors:
|
|
103
|
-
mock_responses:
|
|
97
|
+
mock_results: dict[Union["RPCEndpoint", str], Any] = None,
|
|
98
|
+
mock_errors: dict[Union["RPCEndpoint", str], Any] = None,
|
|
99
|
+
mock_responses: dict[Union["RPCEndpoint", str], Any] = None,
|
|
104
100
|
):
|
|
105
101
|
self.w3 = w3
|
|
106
102
|
self.mock_results = mock_results or {}
|
|
@@ -114,12 +110,11 @@ class RequestMocker:
|
|
|
114
110
|
"AsyncMakeRequestFn", "MakeRequestFn"
|
|
115
111
|
] = w3.provider.make_request
|
|
116
112
|
|
|
113
|
+
self._mock_request_counter = 1
|
|
114
|
+
|
|
117
115
|
def _build_request_id(self) -> int:
|
|
118
|
-
request_id =
|
|
119
|
-
|
|
120
|
-
if hasattr(self.w3.provider, "request_counter")
|
|
121
|
-
else 1
|
|
122
|
-
)
|
|
116
|
+
request_id = self._mock_request_counter
|
|
117
|
+
self._mock_request_counter += 1
|
|
123
118
|
return request_id
|
|
124
119
|
|
|
125
120
|
def __enter__(self) -> "Self":
|
|
@@ -145,7 +140,11 @@ class RequestMocker:
|
|
|
145
140
|
|
|
146
141
|
if all(
|
|
147
142
|
method not in mock_dict
|
|
148
|
-
for mock_dict in (
|
|
143
|
+
for mock_dict in (
|
|
144
|
+
self.mock_errors,
|
|
145
|
+
self.mock_results,
|
|
146
|
+
self.mock_responses,
|
|
147
|
+
)
|
|
149
148
|
):
|
|
150
149
|
return self._make_request(method, params)
|
|
151
150
|
|
|
@@ -225,7 +224,7 @@ class RequestMocker:
|
|
|
225
224
|
|
|
226
225
|
if callable(mock_return):
|
|
227
226
|
mock_return = mock_return(method, params)
|
|
228
|
-
elif iscoroutinefunction(mock_return):
|
|
227
|
+
elif inspect.iscoroutinefunction(mock_return):
|
|
229
228
|
# this is the "correct" way to mock the async make_request
|
|
230
229
|
mock_return = await mock_return(method, params)
|
|
231
230
|
|
|
@@ -240,7 +239,7 @@ class RequestMocker:
|
|
|
240
239
|
if callable(mock_return):
|
|
241
240
|
# handle callable to make things easier since we're mocking
|
|
242
241
|
mock_return = mock_return(method, params)
|
|
243
|
-
elif iscoroutinefunction(mock_return):
|
|
242
|
+
elif inspect.iscoroutinefunction(mock_return):
|
|
244
243
|
# this is the "correct" way to mock the async make_request
|
|
245
244
|
mock_return = await mock_return(method, params)
|
|
246
245
|
|
|
@@ -250,7 +249,7 @@ class RequestMocker:
|
|
|
250
249
|
error = self.mock_errors[method]
|
|
251
250
|
if callable(error):
|
|
252
251
|
error = error(method, params)
|
|
253
|
-
elif iscoroutinefunction(error):
|
|
252
|
+
elif inspect.iscoroutinefunction(error):
|
|
254
253
|
error = await error(method, params)
|
|
255
254
|
mocked_result = merge(response_dict, self._create_error_object(error))
|
|
256
255
|
|
|
@@ -266,7 +265,11 @@ class RequestMocker:
|
|
|
266
265
|
self._make_request = cast("AsyncMakeRequestFn", self._make_request)
|
|
267
266
|
if all(
|
|
268
267
|
method not in mock_dict
|
|
269
|
-
for mock_dict in (
|
|
268
|
+
for mock_dict in (
|
|
269
|
+
self.mock_errors,
|
|
270
|
+
self.mock_results,
|
|
271
|
+
self.mock_responses,
|
|
272
|
+
)
|
|
270
273
|
):
|
|
271
274
|
return await self._make_request(method, params)
|
|
272
275
|
mocked_result = await self._async_build_mock_result(method, params)
|
|
@@ -290,7 +293,11 @@ class RequestMocker:
|
|
|
290
293
|
) -> "RPCRequest":
|
|
291
294
|
if all(
|
|
292
295
|
method not in mock_dict
|
|
293
|
-
for mock_dict in (
|
|
296
|
+
for mock_dict in (
|
|
297
|
+
self.mock_errors,
|
|
298
|
+
self.mock_results,
|
|
299
|
+
self.mock_responses,
|
|
300
|
+
)
|
|
294
301
|
):
|
|
295
302
|
return await self._send_request(method, params)
|
|
296
303
|
else:
|
|
@@ -305,7 +312,11 @@ class RequestMocker:
|
|
|
305
312
|
request_id = rpc_request["id"]
|
|
306
313
|
if all(
|
|
307
314
|
method not in mock_dict
|
|
308
|
-
for mock_dict in (
|
|
315
|
+
for mock_dict in (
|
|
316
|
+
self.mock_errors,
|
|
317
|
+
self.mock_results,
|
|
318
|
+
self.mock_responses,
|
|
319
|
+
)
|
|
309
320
|
):
|
|
310
321
|
return await self._recv_for_request(request_id)
|
|
311
322
|
mocked_result = await self._async_build_mock_result(
|
|
@@ -327,7 +338,7 @@ class RequestMocker:
|
|
|
327
338
|
return mocked_result
|
|
328
339
|
|
|
329
340
|
@staticmethod
|
|
330
|
-
def _create_error_object(error:
|
|
341
|
+
def _create_error_object(error: dict[str, Any]) -> dict[str, Any]:
|
|
331
342
|
code = error.get("code", -32000)
|
|
332
343
|
message = error.get("message", "Mocked error")
|
|
333
344
|
return {"error": merge({"code": code, "message": message}, error)}
|
web3/_utils/normalizers.py
CHANGED
|
@@ -5,9 +5,6 @@ from typing import (
|
|
|
5
5
|
TYPE_CHECKING,
|
|
6
6
|
Any,
|
|
7
7
|
Callable,
|
|
8
|
-
Optional,
|
|
9
|
-
Tuple,
|
|
10
|
-
Union,
|
|
11
8
|
cast,
|
|
12
9
|
)
|
|
13
10
|
|
|
@@ -73,9 +70,9 @@ if TYPE_CHECKING:
|
|
|
73
70
|
|
|
74
71
|
def implicitly_identity(
|
|
75
72
|
to_wrap: Callable[[TypeStr, Any], Any],
|
|
76
|
-
) -> Callable[[TypeStr, Any],
|
|
73
|
+
) -> Callable[[TypeStr, Any], tuple[TypeStr, Any]]:
|
|
77
74
|
@functools.wraps(to_wrap)
|
|
78
|
-
def wrapper(type_str: TypeStr, data: Any) ->
|
|
75
|
+
def wrapper(type_str: TypeStr, data: Any) -> tuple[TypeStr, Any]:
|
|
79
76
|
modified = to_wrap(type_str, data)
|
|
80
77
|
if modified is None:
|
|
81
78
|
return type_str, data
|
|
@@ -93,14 +90,14 @@ def implicitly_identity(
|
|
|
93
90
|
@implicitly_identity
|
|
94
91
|
def addresses_checksummed(
|
|
95
92
|
type_str: TypeStr, data: Any
|
|
96
|
-
) ->
|
|
93
|
+
) -> tuple[TypeStr, ChecksumAddress]:
|
|
97
94
|
if type_str == "address":
|
|
98
95
|
return type_str, to_checksum_address(data)
|
|
99
96
|
return None
|
|
100
97
|
|
|
101
98
|
|
|
102
99
|
@implicitly_identity
|
|
103
|
-
def decode_abi_strings(type_str: TypeStr, data: Any) ->
|
|
100
|
+
def decode_abi_strings(type_str: TypeStr, data: Any) -> tuple[TypeStr, str]:
|
|
104
101
|
if type_str == "string":
|
|
105
102
|
return type_str, codecs.decode(data, "utf8", "backslashreplace")
|
|
106
103
|
return None
|
|
@@ -112,8 +109,8 @@ def decode_abi_strings(type_str: TypeStr, data: Any) -> Tuple[TypeStr, str]:
|
|
|
112
109
|
|
|
113
110
|
|
|
114
111
|
def parse_basic_type_str(
|
|
115
|
-
old_normalizer: Callable[[BasicType, TypeStr, Any],
|
|
116
|
-
) -> Callable[[TypeStr, Any],
|
|
112
|
+
old_normalizer: Callable[[BasicType, TypeStr, Any], tuple[TypeStr, Any]],
|
|
113
|
+
) -> Callable[[TypeStr, Any], tuple[TypeStr, Any]]:
|
|
117
114
|
"""
|
|
118
115
|
Modifies a normalizer to automatically parse the incoming type string. If
|
|
119
116
|
that type string does not represent a basic type (i.e. non-tuple type) or is
|
|
@@ -121,7 +118,7 @@ def parse_basic_type_str(
|
|
|
121
118
|
"""
|
|
122
119
|
|
|
123
120
|
@functools.wraps(old_normalizer)
|
|
124
|
-
def new_normalizer(type_str: TypeStr, data: Any) ->
|
|
121
|
+
def new_normalizer(type_str: TypeStr, data: Any) -> tuple[TypeStr, Any]:
|
|
125
122
|
try:
|
|
126
123
|
abi_type = parse(type_str)
|
|
127
124
|
except ParseError:
|
|
@@ -140,7 +137,7 @@ def parse_basic_type_str(
|
|
|
140
137
|
@parse_basic_type_str
|
|
141
138
|
def abi_bytes_to_hex(
|
|
142
139
|
abi_type: BasicType, type_str: TypeStr, data: Any
|
|
143
|
-
) ->
|
|
140
|
+
) -> tuple[TypeStr, HexStr] | None:
|
|
144
141
|
if abi_type.base != "bytes" or abi_type.is_array:
|
|
145
142
|
return None
|
|
146
143
|
|
|
@@ -163,7 +160,7 @@ def abi_bytes_to_hex(
|
|
|
163
160
|
@parse_basic_type_str
|
|
164
161
|
def abi_int_to_hex(
|
|
165
162
|
abi_type: BasicType, type_str: TypeStr, data: Any
|
|
166
|
-
) ->
|
|
163
|
+
) -> tuple[TypeStr, HexStr] | None:
|
|
167
164
|
if abi_type.base == "uint" and not abi_type.is_array:
|
|
168
165
|
# double check?
|
|
169
166
|
return type_str, hexstr_if_str(to_hex, data)
|
|
@@ -171,14 +168,14 @@ def abi_int_to_hex(
|
|
|
171
168
|
|
|
172
169
|
|
|
173
170
|
@implicitly_identity
|
|
174
|
-
def abi_string_to_hex(type_str: TypeStr, data: Any) ->
|
|
171
|
+
def abi_string_to_hex(type_str: TypeStr, data: Any) -> tuple[TypeStr, str] | None:
|
|
175
172
|
if type_str == "string":
|
|
176
173
|
return type_str, text_if_str(to_hex, data)
|
|
177
174
|
return None
|
|
178
175
|
|
|
179
176
|
|
|
180
177
|
@implicitly_identity
|
|
181
|
-
def abi_string_to_text(type_str: TypeStr, data: Any) ->
|
|
178
|
+
def abi_string_to_text(type_str: TypeStr, data: Any) -> tuple[TypeStr, str] | None:
|
|
182
179
|
if type_str == "string":
|
|
183
180
|
return type_str, text_if_str(to_text, data)
|
|
184
181
|
return None
|
|
@@ -188,7 +185,7 @@ def abi_string_to_text(type_str: TypeStr, data: Any) -> Optional[Tuple[TypeStr,
|
|
|
188
185
|
@parse_basic_type_str
|
|
189
186
|
def abi_bytes_to_bytes(
|
|
190
187
|
abi_type: BasicType, type_str: TypeStr, data: Any
|
|
191
|
-
) ->
|
|
188
|
+
) -> tuple[TypeStr, HexStr] | None:
|
|
192
189
|
if abi_type.base == "bytes" and not abi_type.is_array:
|
|
193
190
|
return type_str, hexstr_if_str(to_bytes, data)
|
|
194
191
|
return None
|
|
@@ -197,7 +194,7 @@ def abi_bytes_to_bytes(
|
|
|
197
194
|
@implicitly_identity
|
|
198
195
|
def abi_address_to_hex(
|
|
199
196
|
type_str: TypeStr, data: Any
|
|
200
|
-
) ->
|
|
197
|
+
) -> tuple[TypeStr, ChecksumAddress] | None:
|
|
201
198
|
if type_str == "address":
|
|
202
199
|
validate_address(data)
|
|
203
200
|
if is_binary_address(data):
|
|
@@ -210,7 +207,7 @@ def abi_ens_resolver(
|
|
|
210
207
|
w3: "Web3",
|
|
211
208
|
type_str: TypeStr,
|
|
212
209
|
val: Any,
|
|
213
|
-
) ->
|
|
210
|
+
) -> tuple[TypeStr, Any]:
|
|
214
211
|
if type_str == "address" and is_ens_name(val):
|
|
215
212
|
if w3 is None:
|
|
216
213
|
raise InvalidAddress(
|
|
@@ -247,7 +244,7 @@ BASE_RETURN_NORMALIZERS = [
|
|
|
247
244
|
#
|
|
248
245
|
|
|
249
246
|
|
|
250
|
-
def normalize_abi(abi:
|
|
247
|
+
def normalize_abi(abi: ABI | str) -> ABI:
|
|
251
248
|
if isinstance(abi, str):
|
|
252
249
|
abi = json.loads(abi)
|
|
253
250
|
validate_abi(cast(ABI, abi))
|
|
@@ -255,8 +252,8 @@ def normalize_abi(abi: Union[ABI, str]) -> ABI:
|
|
|
255
252
|
|
|
256
253
|
|
|
257
254
|
def normalize_address(
|
|
258
|
-
ens: ENS, address:
|
|
259
|
-
) ->
|
|
255
|
+
ens: ENS, address: ChecksumAddress | None
|
|
256
|
+
) -> ChecksumAddress | None:
|
|
260
257
|
if address:
|
|
261
258
|
if is_ens_name(address):
|
|
262
259
|
validate_name_has_address(ens, address)
|
|
@@ -266,14 +263,14 @@ def normalize_address(
|
|
|
266
263
|
|
|
267
264
|
|
|
268
265
|
def normalize_address_no_ens(
|
|
269
|
-
address:
|
|
270
|
-
) ->
|
|
266
|
+
address: ChecksumAddress | None,
|
|
267
|
+
) -> ChecksumAddress | None:
|
|
271
268
|
if address:
|
|
272
269
|
validate_address(address)
|
|
273
270
|
return address
|
|
274
271
|
|
|
275
272
|
|
|
276
|
-
def normalize_bytecode(bytecode:
|
|
273
|
+
def normalize_bytecode(bytecode: bytes | None) -> HexBytes | None:
|
|
277
274
|
if bytecode is not None:
|
|
278
275
|
return HexBytes(bytecode)
|
|
279
276
|
return bytecode
|
|
@@ -286,7 +283,7 @@ async def async_abi_ens_resolver(
|
|
|
286
283
|
async_w3: "AsyncWeb3[Any]",
|
|
287
284
|
type_str: TypeStr,
|
|
288
285
|
val: Any,
|
|
289
|
-
) ->
|
|
286
|
+
) -> tuple[TypeStr, Any]:
|
|
290
287
|
if type_str == "address" and is_ens_name(val):
|
|
291
288
|
if async_w3 is None:
|
|
292
289
|
raise InvalidAddress(
|
web3/_utils/rpc_abi.py
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
from typing import (
|
|
2
2
|
Any,
|
|
3
3
|
Callable,
|
|
4
|
-
Dict,
|
|
5
4
|
Iterable,
|
|
6
5
|
Sequence,
|
|
7
|
-
Tuple,
|
|
8
|
-
Union,
|
|
9
6
|
)
|
|
10
7
|
|
|
11
8
|
from eth_typing import (
|
|
@@ -174,7 +171,7 @@ TRACE_FILTER_PARAM_ABIS = {
|
|
|
174
171
|
"count": "int",
|
|
175
172
|
}
|
|
176
173
|
|
|
177
|
-
RPC_ABIS:
|
|
174
|
+
RPC_ABIS: dict[str, Sequence[Any] | dict[str, str]] = {
|
|
178
175
|
# eth
|
|
179
176
|
"eth_call": TRANSACTION_PARAMS_ABIS,
|
|
180
177
|
"eth_createAccessList": TRANSACTION_PARAMS_ABIS,
|
|
@@ -208,10 +205,10 @@ RPC_ABIS: Dict[str, Union[Sequence[Any], Dict[str, str]]] = {
|
|
|
208
205
|
|
|
209
206
|
@curry
|
|
210
207
|
def apply_abi_formatters_to_dict(
|
|
211
|
-
normalizers: Sequence[Callable[[TypeStr, Any],
|
|
212
|
-
abi_dict:
|
|
213
|
-
data:
|
|
214
|
-
) ->
|
|
208
|
+
normalizers: Sequence[Callable[[TypeStr, Any], tuple[TypeStr, Any]]],
|
|
209
|
+
abi_dict: dict[str, Any],
|
|
210
|
+
data: dict[Any, Any],
|
|
211
|
+
) -> dict[Any, Any]:
|
|
215
212
|
fields = list(abi_dict.keys() & data.keys())
|
|
216
213
|
formatted_values = map_abi_data(
|
|
217
214
|
normalizers,
|
|
@@ -225,9 +222,9 @@ def apply_abi_formatters_to_dict(
|
|
|
225
222
|
|
|
226
223
|
@to_dict
|
|
227
224
|
def abi_request_formatters(
|
|
228
|
-
normalizers: Sequence[Callable[[TypeStr, Any],
|
|
229
|
-
abis:
|
|
230
|
-
) -> Iterable[
|
|
225
|
+
normalizers: Sequence[Callable[[TypeStr, Any], tuple[TypeStr, Any]]],
|
|
226
|
+
abis: dict[RPCEndpoint, Any],
|
|
227
|
+
) -> Iterable[tuple[RPCEndpoint, Callable[..., Any]]]:
|
|
231
228
|
for method, abi_types in abis.items():
|
|
232
229
|
if isinstance(abi_types, list):
|
|
233
230
|
yield method, map_abi_data(normalizers, abi_types)
|
web3/_utils/threads.py
CHANGED
|
@@ -13,7 +13,6 @@ from typing import (
|
|
|
13
13
|
Callable,
|
|
14
14
|
Generic,
|
|
15
15
|
Literal,
|
|
16
|
-
Type,
|
|
17
16
|
)
|
|
18
17
|
|
|
19
18
|
from web3.exceptions import (
|
|
@@ -37,7 +36,7 @@ class Timeout(Exception):
|
|
|
37
36
|
def __init__(
|
|
38
37
|
self,
|
|
39
38
|
seconds: float = None,
|
|
40
|
-
exception:
|
|
39
|
+
exception: type[BaseException] = None,
|
|
41
40
|
*args: Any,
|
|
42
41
|
**kwargs: Any,
|
|
43
42
|
) -> None:
|
|
@@ -50,7 +49,7 @@ class Timeout(Exception):
|
|
|
50
49
|
|
|
51
50
|
def __exit__(
|
|
52
51
|
self,
|
|
53
|
-
exc_type:
|
|
52
|
+
exc_type: type[BaseException],
|
|
54
53
|
exc_val: BaseException,
|
|
55
54
|
exc_tb: TracebackType,
|
|
56
55
|
) -> Literal[False]:
|
|
@@ -152,7 +151,7 @@ class TimerClass(threading.Thread):
|
|
|
152
151
|
def spawn(
|
|
153
152
|
target: Callable[..., TReturn],
|
|
154
153
|
*args: Any,
|
|
155
|
-
thread_class:
|
|
154
|
+
thread_class: type[ThreadWithReturn[TReturn]] = ThreadWithReturn,
|
|
156
155
|
**kwargs: Any,
|
|
157
156
|
) -> ThreadWithReturn[TReturn]:
|
|
158
157
|
thread = thread_class(
|
web3/_utils/transactions.py
CHANGED
|
@@ -2,10 +2,7 @@ import math
|
|
|
2
2
|
from typing import (
|
|
3
3
|
TYPE_CHECKING,
|
|
4
4
|
Any,
|
|
5
|
-
Dict,
|
|
6
|
-
List,
|
|
7
5
|
Literal,
|
|
8
|
-
Optional,
|
|
9
6
|
Union,
|
|
10
7
|
cast,
|
|
11
8
|
)
|
|
@@ -57,7 +54,7 @@ TX_PARAM_LITERALS = Literal[
|
|
|
57
54
|
"blobVersionedHashes",
|
|
58
55
|
]
|
|
59
56
|
|
|
60
|
-
VALID_TRANSACTION_PARAMS:
|
|
57
|
+
VALID_TRANSACTION_PARAMS: list[TX_PARAM_LITERALS] = [
|
|
61
58
|
"type",
|
|
62
59
|
"from",
|
|
63
60
|
"to",
|
|
@@ -121,7 +118,7 @@ def fill_transaction_defaults(w3: "Web3", transaction: TxParams) -> TxParams:
|
|
|
121
118
|
or any_in_dict(DYNAMIC_FEE_TXN_PARAMS, transaction)
|
|
122
119
|
)
|
|
123
120
|
|
|
124
|
-
defaults:
|
|
121
|
+
defaults: dict[str, bytes | int] = {}
|
|
125
122
|
for key, default_getter in TRANSACTION_DEFAULTS.items():
|
|
126
123
|
if key not in transaction:
|
|
127
124
|
if (
|
|
@@ -148,7 +145,7 @@ def fill_transaction_defaults(w3: "Web3", transaction: TxParams) -> TxParams:
|
|
|
148
145
|
|
|
149
146
|
|
|
150
147
|
def get_block_gas_limit(
|
|
151
|
-
w3: "Web3", block_identifier:
|
|
148
|
+
w3: "Web3", block_identifier: BlockIdentifier | None = None
|
|
152
149
|
) -> int:
|
|
153
150
|
block = w3.eth.get_block(block_identifier or "latest")
|
|
154
151
|
return block["gasLimit"]
|
web3/_utils/type_conversion.py
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
from typing import (
|
|
2
|
-
Union,
|
|
3
|
-
)
|
|
4
|
-
|
|
5
1
|
from eth_typing import (
|
|
6
2
|
HexStr,
|
|
7
3
|
)
|
|
@@ -15,7 +11,7 @@ from web3.exceptions import (
|
|
|
15
11
|
)
|
|
16
12
|
|
|
17
13
|
|
|
18
|
-
def to_hex_if_bytes(val:
|
|
14
|
+
def to_hex_if_bytes(val: HexStr | str | bytes | bytearray) -> HexStr:
|
|
19
15
|
"""
|
|
20
16
|
Note: This method does not validate against all cases and is only
|
|
21
17
|
meant to work with bytes and hex strings.
|
|
@@ -26,7 +22,7 @@ def to_hex_if_bytes(val: Union[HexStr, str, bytes, bytearray]) -> HexStr:
|
|
|
26
22
|
return to_hex(val) if isinstance(val, (bytes, bytearray)) else to_hex(hexstr=val)
|
|
27
23
|
|
|
28
24
|
|
|
29
|
-
def to_bytes_if_hex(val:
|
|
25
|
+
def to_bytes_if_hex(val: HexStr | str | bytes | bytearray) -> bytes:
|
|
30
26
|
"""
|
|
31
27
|
Note: This method does not validate against all cases and is only
|
|
32
28
|
meant to work with bytes and hex strings.
|
web3/_utils/utility_methods.py
CHANGED
|
@@ -2,8 +2,6 @@ from typing import (
|
|
|
2
2
|
Any,
|
|
3
3
|
Iterable,
|
|
4
4
|
Mapping,
|
|
5
|
-
Set,
|
|
6
|
-
Union,
|
|
7
5
|
)
|
|
8
6
|
|
|
9
7
|
from web3.types import (
|
|
@@ -13,7 +11,7 @@ from web3.types import (
|
|
|
13
11
|
|
|
14
12
|
|
|
15
13
|
def all_in_dict(
|
|
16
|
-
values: Iterable[Any], d:
|
|
14
|
+
values: Iterable[Any], d: Mapping[Any, Any] | TxData | TxParams
|
|
17
15
|
) -> bool:
|
|
18
16
|
"""
|
|
19
17
|
Returns a bool based on whether ALL of the provided values exist
|
|
@@ -29,7 +27,7 @@ def all_in_dict(
|
|
|
29
27
|
|
|
30
28
|
|
|
31
29
|
def any_in_dict(
|
|
32
|
-
values: Iterable[Any], d:
|
|
30
|
+
values: Iterable[Any], d: Mapping[Any, Any] | TxData | TxParams
|
|
33
31
|
) -> bool:
|
|
34
32
|
"""
|
|
35
33
|
Returns a bool based on whether ANY of the provided values exist
|
|
@@ -45,7 +43,7 @@ def any_in_dict(
|
|
|
45
43
|
|
|
46
44
|
|
|
47
45
|
def none_in_dict(
|
|
48
|
-
values: Iterable[Any], d:
|
|
46
|
+
values: Iterable[Any], d: Mapping[Any, Any] | TxData | TxParams
|
|
49
47
|
) -> bool:
|
|
50
48
|
"""
|
|
51
49
|
Returns a bool based on whether NONE of the provided values exist
|
|
@@ -60,8 +58,8 @@ def none_in_dict(
|
|
|
60
58
|
|
|
61
59
|
|
|
62
60
|
def either_set_is_a_subset(
|
|
63
|
-
set1:
|
|
64
|
-
set2:
|
|
61
|
+
set1: set[Any],
|
|
62
|
+
set2: set[Any],
|
|
65
63
|
percentage: int = 100,
|
|
66
64
|
) -> bool:
|
|
67
65
|
"""
|
web3/_utils/validation.py
CHANGED
|
@@ -3,9 +3,7 @@ import logging
|
|
|
3
3
|
from typing import (
|
|
4
4
|
Any,
|
|
5
5
|
Callable,
|
|
6
|
-
Dict,
|
|
7
6
|
NoReturn,
|
|
8
|
-
Optional,
|
|
9
7
|
)
|
|
10
8
|
|
|
11
9
|
from eth_typing import (
|
|
@@ -75,7 +73,7 @@ from web3.types import (
|
|
|
75
73
|
)
|
|
76
74
|
|
|
77
75
|
|
|
78
|
-
def _prepare_selector_collision_msg(duplicates:
|
|
76
|
+
def _prepare_selector_collision_msg(duplicates: dict[HexStr, ABIFunction]) -> str:
|
|
79
77
|
dup_sel = valmap(apply_formatter_to_array(abi_to_signature), duplicates)
|
|
80
78
|
joined_funcs = valmap(lambda funcs: ", ".join(funcs), dup_sel)
|
|
81
79
|
func_sel_msg_list = [
|
|
@@ -264,7 +262,7 @@ def _raise_bad_response_format(response: RPCResponse, error: str = "") -> None:
|
|
|
264
262
|
|
|
265
263
|
def raise_error_for_batch_response(
|
|
266
264
|
response: RPCResponse,
|
|
267
|
-
logger:
|
|
265
|
+
logger: logging.Logger | None = None,
|
|
268
266
|
) -> NoReturn:
|
|
269
267
|
error = response.get("error")
|
|
270
268
|
if error is None:
|
|
@@ -288,10 +286,10 @@ def raise_error_for_batch_response(
|
|
|
288
286
|
|
|
289
287
|
def validate_rpc_response_and_raise_if_error(
|
|
290
288
|
response: RPCResponse,
|
|
291
|
-
error_formatters:
|
|
289
|
+
error_formatters: Callable[..., Any] | None,
|
|
292
290
|
is_subscription_response: bool = False,
|
|
293
|
-
logger:
|
|
294
|
-
params:
|
|
291
|
+
logger: logging.Logger | None = None,
|
|
292
|
+
params: Any | None = None,
|
|
295
293
|
) -> None:
|
|
296
294
|
if "jsonrpc" not in response or response["jsonrpc"] != "2.0":
|
|
297
295
|
_raise_bad_response_format(
|
|
@@ -335,7 +333,7 @@ def validate_rpc_response_and_raise_if_error(
|
|
|
335
333
|
response, 'Response must include either "error" or "result".'
|
|
336
334
|
)
|
|
337
335
|
elif "error" in response:
|
|
338
|
-
web3_rpc_error:
|
|
336
|
+
web3_rpc_error: Web3RPCError | None = None
|
|
339
337
|
error = response["error"]
|
|
340
338
|
|
|
341
339
|
# raise the error when the value is a string
|
web3/_utils/windows.py
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import sys
|
|
2
|
-
from typing import (
|
|
3
|
-
Tuple,
|
|
4
|
-
)
|
|
5
2
|
|
|
6
3
|
import pywintypes # noqa: E402
|
|
7
4
|
import win32file # noqa: E402
|
|
@@ -31,7 +28,7 @@ class NamedPipe:
|
|
|
31
28
|
raise OSError(err)
|
|
32
29
|
return data
|
|
33
30
|
|
|
34
|
-
def sendall(self, data: str) ->
|
|
31
|
+
def sendall(self, data: str) -> tuple[int, int]:
|
|
35
32
|
return win32file.WriteFile(self.handle, data)
|
|
36
33
|
|
|
37
34
|
def close(self) -> None:
|