faster-eth-utils 5.3.19__cp311-cp311-win32.whl → 5.3.23__cp311-cp311-win32.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.
Potentially problematic release.
This version of faster-eth-utils might be problematic. Click here for more details.
- faster_eth_utils/abi.cp311-win32.pyd +0 -0
- faster_eth_utils/abi.py +76 -55
- faster_eth_utils/address.cp311-win32.pyd +0 -0
- faster_eth_utils/address.py +7 -14
- faster_eth_utils/applicators.cp311-win32.pyd +0 -0
- faster_eth_utils/applicators.py +20 -33
- faster_eth_utils/conversions.cp311-win32.pyd +0 -0
- faster_eth_utils/conversions.py +18 -20
- faster_eth_utils/crypto.cp311-win32.pyd +0 -0
- faster_eth_utils/crypto.py +3 -8
- faster_eth_utils/currency.cp311-win32.pyd +0 -0
- faster_eth_utils/currency.py +11 -8
- faster_eth_utils/curried/__init__.py +35 -44
- faster_eth_utils/debug.cp311-win32.pyd +0 -0
- faster_eth_utils/decorators.cp311-win32.pyd +0 -0
- faster_eth_utils/decorators.py +16 -20
- faster_eth_utils/encoding.cp311-win32.pyd +0 -0
- faster_eth_utils/encoding.py +1 -1
- faster_eth_utils/exceptions.cp311-win32.pyd +0 -0
- faster_eth_utils/exceptions.py +1 -1
- faster_eth_utils/functional.cp311-win32.pyd +0 -0
- faster_eth_utils/functional.py +10 -12
- faster_eth_utils/hexadecimal.cp311-win32.pyd +0 -0
- faster_eth_utils/hexadecimal.py +8 -12
- faster_eth_utils/humanize.cp311-win32.pyd +0 -0
- faster_eth_utils/humanize.py +16 -16
- faster_eth_utils/logging.py +33 -27
- faster_eth_utils/module_loading.cp311-win32.pyd +0 -0
- faster_eth_utils/network.cp311-win32.pyd +0 -0
- faster_eth_utils/network.py +2 -3
- faster_eth_utils/numeric.cp311-win32.pyd +0 -0
- faster_eth_utils/pydantic.py +4 -6
- faster_eth_utils/toolz.cp311-win32.pyd +0 -0
- faster_eth_utils/types.cp311-win32.pyd +0 -0
- faster_eth_utils/types.py +5 -8
- faster_eth_utils/units.cp311-win32.pyd +0 -0
- {faster_eth_utils-5.3.19.dist-info → faster_eth_utils-5.3.23.dist-info}/METADATA +8 -9
- faster_eth_utils-5.3.23.dist-info/RECORD +53 -0
- faster_eth_utils__mypyc.cp311-win32.pyd +0 -0
- faster_eth_utils-5.3.19.dist-info/RECORD +0 -53
- {faster_eth_utils-5.3.19.dist-info → faster_eth_utils-5.3.23.dist-info}/WHEEL +0 -0
- {faster_eth_utils-5.3.19.dist-info → faster_eth_utils-5.3.23.dist-info}/licenses/LICENSE +0 -0
- {faster_eth_utils-5.3.19.dist-info → faster_eth_utils-5.3.23.dist-info}/top_level.txt +0 -0
|
Binary file
|
faster_eth_utils/abi.py
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
from collections import (
|
|
2
|
-
abc,
|
|
3
|
-
)
|
|
4
1
|
import copy
|
|
5
2
|
import itertools
|
|
6
3
|
import re
|
|
4
|
+
from collections.abc import (
|
|
5
|
+
Iterable,
|
|
6
|
+
Mapping,
|
|
7
|
+
Sequence,
|
|
8
|
+
)
|
|
7
9
|
from typing import (
|
|
8
10
|
Any,
|
|
9
|
-
Dict,
|
|
10
11
|
Final,
|
|
11
|
-
|
|
12
|
-
List,
|
|
12
|
+
Generic,
|
|
13
13
|
Literal,
|
|
14
|
-
|
|
15
|
-
Optional,
|
|
16
|
-
Sequence,
|
|
17
|
-
Tuple,
|
|
18
|
-
Union,
|
|
14
|
+
TypeVar,
|
|
19
15
|
cast,
|
|
20
16
|
overload,
|
|
21
17
|
)
|
|
@@ -31,6 +27,9 @@ from eth_typing import (
|
|
|
31
27
|
ABIFunction,
|
|
32
28
|
ABIReceive,
|
|
33
29
|
)
|
|
30
|
+
from typing_extensions import (
|
|
31
|
+
Self,
|
|
32
|
+
)
|
|
34
33
|
|
|
35
34
|
from faster_eth_utils.types import (
|
|
36
35
|
is_list_like,
|
|
@@ -41,12 +40,37 @@ from .crypto import (
|
|
|
41
40
|
)
|
|
42
41
|
|
|
43
42
|
|
|
43
|
+
T = TypeVar("T")
|
|
44
|
+
|
|
44
45
|
ABIType = Literal["function", "constructor", "fallback", "receive", "event", "error"]
|
|
45
46
|
|
|
47
|
+
_TUPLE_TYPE_STR_RE: Final = re.compile("^(tuple)((\\[([1-9]\\d*\\b)?])*)??$")
|
|
48
|
+
|
|
49
|
+
_chain: Final = itertools.chain
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class _repeat(Generic[T]):
|
|
53
|
+
|
|
54
|
+
def __init__(self, value: T, times: int | None = None) -> None:
|
|
55
|
+
self._value: Final[T] = value
|
|
56
|
+
self._times: Final[int | None] = times
|
|
57
|
+
self._index = 0
|
|
58
|
+
|
|
59
|
+
def __iter__(self) -> Self:
|
|
60
|
+
return self
|
|
61
|
+
|
|
62
|
+
def __next__(self) -> T:
|
|
63
|
+
if self._times is None:
|
|
64
|
+
return self._value
|
|
65
|
+
if self._index >= self._times:
|
|
66
|
+
raise StopIteration
|
|
67
|
+
self._index += 1
|
|
68
|
+
return self._value
|
|
69
|
+
|
|
46
70
|
|
|
47
71
|
def _align_abi_input(
|
|
48
72
|
arg_abi: ABIComponent, normalized_arg: Any
|
|
49
|
-
) ->
|
|
73
|
+
) -> Any | tuple[Any, ...]:
|
|
50
74
|
"""
|
|
51
75
|
Aligns the values of any mapping at any level of nesting in ``normalized_arg``
|
|
52
76
|
according to the layout of the corresponding abi spec.
|
|
@@ -70,37 +94,38 @@ def _align_abi_input(
|
|
|
70
94
|
new_abi = copy.copy(arg_abi)
|
|
71
95
|
new_abi["type"] = tuple_prefix + "[]" * (num_dims - 1)
|
|
72
96
|
|
|
73
|
-
sub_abis =
|
|
97
|
+
sub_abis = _repeat(new_abi)
|
|
74
98
|
|
|
75
99
|
aligned_arg: Any
|
|
76
|
-
if isinstance(normalized_arg,
|
|
100
|
+
if isinstance(normalized_arg, Mapping):
|
|
77
101
|
# normalized_arg is mapping. Align values according to abi order.
|
|
78
102
|
aligned_arg = tuple(normalized_arg[abi["name"]] for abi in sub_abis)
|
|
79
103
|
else:
|
|
80
104
|
aligned_arg = normalized_arg
|
|
81
105
|
|
|
82
|
-
if
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
106
|
+
# We can generate more optimized C code if we branch by arg type
|
|
107
|
+
if isinstance(aligned_arg, tuple):
|
|
108
|
+
# convert NamedTuple to regular tuple
|
|
109
|
+
return tuple(map(_align_abi_input, sub_abis, aligned_arg))
|
|
110
|
+
|
|
111
|
+
elif type(aligned_arg) is list:
|
|
112
|
+
return list(map(_align_abi_input, sub_abis, aligned_arg))
|
|
87
113
|
|
|
88
|
-
|
|
89
|
-
|
|
114
|
+
elif is_list_like(aligned_arg):
|
|
115
|
+
return type(aligned_arg)(map(_align_abi_input, sub_abis, aligned_arg)) # type: ignore [call-arg]
|
|
90
116
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
117
|
+
raise TypeError(
|
|
118
|
+
f'Expected non-string sequence for "{arg_abi.get("type")}" '
|
|
119
|
+
f"component type: got {aligned_arg}"
|
|
94
120
|
)
|
|
95
121
|
|
|
96
122
|
|
|
97
|
-
def _get_tuple_type_str_and_dims(s: str) ->
|
|
123
|
+
def _get_tuple_type_str_and_dims(s: str) -> tuple[str, str | None] | None:
|
|
98
124
|
"""
|
|
99
125
|
Takes a JSON ABI type string. For tuple type strings, returns the separated
|
|
100
126
|
prefix and array dimension parts. For all other strings, returns ``None``.
|
|
101
127
|
"""
|
|
102
|
-
|
|
103
|
-
match = re.compile(tuple_type_str_re).match(s)
|
|
128
|
+
match = _TUPLE_TYPE_STR_RE.match(s)
|
|
104
129
|
|
|
105
130
|
return None if match is None else (match[1], match[2])
|
|
106
131
|
|
|
@@ -123,7 +148,7 @@ def _raise_if_fallback_or_receive_abi(abi_element: ABIElement) -> None:
|
|
|
123
148
|
)
|
|
124
149
|
|
|
125
150
|
|
|
126
|
-
def collapse_if_tuple(abi:
|
|
151
|
+
def collapse_if_tuple(abi: ABIComponent | dict[str, Any] | str) -> str:
|
|
127
152
|
"""
|
|
128
153
|
Extract argument types from a function or event ABI parameter.
|
|
129
154
|
|
|
@@ -296,7 +321,7 @@ __ABI_TYPE_LITERALS: Final = {
|
|
|
296
321
|
def filter_abi_by_type(
|
|
297
322
|
abi_type: Literal["function"],
|
|
298
323
|
contract_abi: ABI,
|
|
299
|
-
) ->
|
|
324
|
+
) -> list[ABIFunction]:
|
|
300
325
|
pass
|
|
301
326
|
|
|
302
327
|
|
|
@@ -304,7 +329,7 @@ def filter_abi_by_type(
|
|
|
304
329
|
def filter_abi_by_type(
|
|
305
330
|
abi_type: Literal["constructor"],
|
|
306
331
|
contract_abi: ABI,
|
|
307
|
-
) ->
|
|
332
|
+
) -> list[ABIConstructor]:
|
|
308
333
|
pass
|
|
309
334
|
|
|
310
335
|
|
|
@@ -312,7 +337,7 @@ def filter_abi_by_type(
|
|
|
312
337
|
def filter_abi_by_type(
|
|
313
338
|
abi_type: Literal["fallback"],
|
|
314
339
|
contract_abi: ABI,
|
|
315
|
-
) ->
|
|
340
|
+
) -> list[ABIFallback]:
|
|
316
341
|
pass
|
|
317
342
|
|
|
318
343
|
|
|
@@ -320,7 +345,7 @@ def filter_abi_by_type(
|
|
|
320
345
|
def filter_abi_by_type(
|
|
321
346
|
abi_type: Literal["receive"],
|
|
322
347
|
contract_abi: ABI,
|
|
323
|
-
) ->
|
|
348
|
+
) -> list[ABIReceive]:
|
|
324
349
|
pass
|
|
325
350
|
|
|
326
351
|
|
|
@@ -328,7 +353,7 @@ def filter_abi_by_type(
|
|
|
328
353
|
def filter_abi_by_type(
|
|
329
354
|
abi_type: Literal["event"],
|
|
330
355
|
contract_abi: ABI,
|
|
331
|
-
) ->
|
|
356
|
+
) -> list[ABIEvent]:
|
|
332
357
|
pass
|
|
333
358
|
|
|
334
359
|
|
|
@@ -336,16 +361,16 @@ def filter_abi_by_type(
|
|
|
336
361
|
def filter_abi_by_type(
|
|
337
362
|
abi_type: Literal["error"],
|
|
338
363
|
contract_abi: ABI,
|
|
339
|
-
) ->
|
|
364
|
+
) -> list[ABIError]:
|
|
340
365
|
pass
|
|
341
366
|
|
|
342
367
|
|
|
343
368
|
def filter_abi_by_type(
|
|
344
369
|
abi_type: ABIType,
|
|
345
370
|
contract_abi: ABI,
|
|
346
|
-
) ->
|
|
347
|
-
|
|
348
|
-
|
|
371
|
+
) -> (
|
|
372
|
+
list[ABIFunction] | list[ABIConstructor] | list[ABIFallback] | list[ABIReceive] | list[ABIEvent] | list[ABIError]
|
|
373
|
+
):
|
|
349
374
|
"""
|
|
350
375
|
Return a list of each ``ABIElement`` that is of type ``abi_type``.
|
|
351
376
|
|
|
@@ -375,7 +400,7 @@ ABIEvent, ABIError]]`
|
|
|
375
400
|
"""
|
|
376
401
|
if abi_type in ("function", "constructor", "fallback", "receive", "event", "error"):
|
|
377
402
|
return [abi for abi in contract_abi if abi["type"] == abi_type] # type: ignore [return-value]
|
|
378
|
-
abi_type_string:
|
|
403
|
+
abi_type_string: ABIType | None = __ABI_TYPE_LITERALS.get(abi_type) # type: ignore [call-overload]
|
|
379
404
|
if abi_type_string is None:
|
|
380
405
|
raise ValueError(f"Unsupported ABI type: {abi_type}")
|
|
381
406
|
return [abi for abi in contract_abi if abi["type"] == abi_type_string] # type: ignore [return-value]
|
|
@@ -432,7 +457,7 @@ def get_normalized_abi_inputs(
|
|
|
432
457
|
abi_element: ABIElement,
|
|
433
458
|
*args: Any,
|
|
434
459
|
**kwargs: Any,
|
|
435
|
-
) ->
|
|
460
|
+
) -> tuple[Any, ...]:
|
|
436
461
|
r"""
|
|
437
462
|
Flattens positional args (``args``) and keyword args (``kwargs``) into a Tuple and
|
|
438
463
|
uses the ``abi_element`` for validation.
|
|
@@ -500,6 +525,7 @@ def get_normalized_abi_inputs(
|
|
|
500
525
|
|
|
501
526
|
kwarg_names = set(kwargs.keys())
|
|
502
527
|
sorted_arg_names = tuple(arg_abi["name"] for arg_abi in function_inputs)
|
|
528
|
+
arg_positions = {name: index for index, name in enumerate(sorted_arg_names)}
|
|
503
529
|
args_as_kwargs = dict(zip(sorted_arg_names, args))
|
|
504
530
|
|
|
505
531
|
# Check for duplicate args
|
|
@@ -525,22 +551,17 @@ def get_normalized_abi_inputs(
|
|
|
525
551
|
|
|
526
552
|
# Sort args according to their position in the ABI and unzip them from their
|
|
527
553
|
# names
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
itertools.chain(kwargs.items(), args_as_kwargs.items()),
|
|
532
|
-
key=lambda kv: sorted_arg_names.index(kv[0]),
|
|
533
|
-
)
|
|
534
|
-
)
|
|
554
|
+
sorted_items = sorted(
|
|
555
|
+
_chain(kwargs.items(), args_as_kwargs.items()),
|
|
556
|
+
key=lambda kv: arg_positions[kv[0]],
|
|
535
557
|
)
|
|
536
|
-
|
|
537
|
-
return tuple(sorted_args[1]) if sorted_args else ()
|
|
558
|
+
return tuple(val for _, val in sorted_items)
|
|
538
559
|
|
|
539
560
|
|
|
540
561
|
def get_aligned_abi_inputs(
|
|
541
562
|
abi_element: ABIElement,
|
|
542
|
-
normalized_args:
|
|
543
|
-
) ->
|
|
563
|
+
normalized_args: tuple[Any, ...] | Mapping[Any, Any],
|
|
564
|
+
) -> tuple[tuple[str, ...], tuple[Any, ...]]:
|
|
544
565
|
"""
|
|
545
566
|
Returns a pair of nested Tuples containing a list of types and a list of input
|
|
546
567
|
values sorted by the order specified by the ``abi``.
|
|
@@ -583,7 +604,7 @@ def get_aligned_abi_inputs(
|
|
|
583
604
|
_raise_if_fallback_or_receive_abi(abi_element)
|
|
584
605
|
|
|
585
606
|
abi_element_inputs = cast(Sequence[ABIComponent], abi_element.get("inputs", []))
|
|
586
|
-
if isinstance(normalized_args,
|
|
607
|
+
if isinstance(normalized_args, Mapping):
|
|
587
608
|
# `args` is mapping. Align values according to abi order.
|
|
588
609
|
normalized_args = tuple(
|
|
589
610
|
normalized_args[abi["name"]] for abi in abi_element_inputs
|
|
@@ -598,7 +619,7 @@ def get_aligned_abi_inputs(
|
|
|
598
619
|
)
|
|
599
620
|
|
|
600
621
|
|
|
601
|
-
def get_abi_input_names(abi_element: ABIElement) ->
|
|
622
|
+
def get_abi_input_names(abi_element: ABIElement) -> list[str | None]:
|
|
602
623
|
"""
|
|
603
624
|
Return names for each input from the function or event ABI.
|
|
604
625
|
|
|
@@ -634,7 +655,7 @@ def get_abi_input_names(abi_element: ABIElement) -> List[Optional[str]]:
|
|
|
634
655
|
]
|
|
635
656
|
|
|
636
657
|
|
|
637
|
-
def get_abi_input_types(abi_element: ABIElement) ->
|
|
658
|
+
def get_abi_input_types(abi_element: ABIElement) -> list[str]:
|
|
638
659
|
"""
|
|
639
660
|
Return types for each input from the function or event ABI.
|
|
640
661
|
|
|
@@ -670,7 +691,7 @@ def get_abi_input_types(abi_element: ABIElement) -> List[str]:
|
|
|
670
691
|
]
|
|
671
692
|
|
|
672
693
|
|
|
673
|
-
def get_abi_output_names(abi_element: ABIElement) ->
|
|
694
|
+
def get_abi_output_names(abi_element: ABIElement) -> list[str | None]:
|
|
674
695
|
"""
|
|
675
696
|
Return names for each output from the ABI element.
|
|
676
697
|
|
|
@@ -715,7 +736,7 @@ def get_abi_output_names(abi_element: ABIElement) -> List[Optional[str]]:
|
|
|
715
736
|
]
|
|
716
737
|
|
|
717
738
|
|
|
718
|
-
def get_abi_output_types(abi_element: ABIElement) ->
|
|
739
|
+
def get_abi_output_types(abi_element: ABIElement) -> list[str]:
|
|
719
740
|
"""
|
|
720
741
|
Return types for each output from the function ABI.
|
|
721
742
|
|
|
Binary file
|
faster_eth_utils/address.py
CHANGED
|
@@ -2,7 +2,7 @@ import re
|
|
|
2
2
|
from typing import (
|
|
3
3
|
Any,
|
|
4
4
|
Final,
|
|
5
|
-
|
|
5
|
+
TypeGuard,
|
|
6
6
|
)
|
|
7
7
|
|
|
8
8
|
import cchecksum
|
|
@@ -13,21 +13,13 @@ from eth_typing import (
|
|
|
13
13
|
HexAddress,
|
|
14
14
|
HexStr,
|
|
15
15
|
)
|
|
16
|
-
from typing_extensions import (
|
|
17
|
-
TypeGuard,
|
|
18
|
-
)
|
|
19
16
|
|
|
20
17
|
from .conversions import (
|
|
21
18
|
hexstr_if_str,
|
|
22
19
|
to_hex,
|
|
23
20
|
)
|
|
24
|
-
from .crypto import (
|
|
25
|
-
keccak,
|
|
26
|
-
)
|
|
27
21
|
from .hexadecimal import (
|
|
28
|
-
add_0x_prefix,
|
|
29
22
|
decode_hex,
|
|
30
|
-
encode_hex,
|
|
31
23
|
remove_0x_prefix,
|
|
32
24
|
)
|
|
33
25
|
from .types import (
|
|
@@ -76,7 +68,7 @@ def is_address(value: Any) -> bool:
|
|
|
76
68
|
return False
|
|
77
69
|
|
|
78
70
|
|
|
79
|
-
def to_normalized_address(value:
|
|
71
|
+
def to_normalized_address(value: AnyAddress | str | bytes) -> HexAddress:
|
|
80
72
|
"""
|
|
81
73
|
Converts an address to its normalized hexadecimal representation.
|
|
82
74
|
"""
|
|
@@ -100,7 +92,7 @@ def is_normalized_address(value: Any) -> TypeGuard[HexAddress]:
|
|
|
100
92
|
return is_address(value) and value == to_normalized_address(value)
|
|
101
93
|
|
|
102
94
|
|
|
103
|
-
def to_canonical_address(address:
|
|
95
|
+
def to_canonical_address(address: AnyAddress | str | bytes) -> Address:
|
|
104
96
|
"""
|
|
105
97
|
Convert a valid address to its canonical form (20-length bytes).
|
|
106
98
|
"""
|
|
@@ -115,15 +107,16 @@ def is_canonical_address(address: Any) -> TypeGuard[Address]:
|
|
|
115
107
|
8
|
|
116
108
|
|
|
117
109
|
def is_same_address(
|
|
118
|
-
left:
|
|
110
|
+
left: AnyAddress | str | bytes, right: AnyAddress | str | bytes
|
|
119
111
|
) -> bool:
|
|
120
112
|
"""
|
|
121
113
|
Checks if both addresses are same or not.
|
|
122
114
|
"""
|
|
123
115
|
if not is_address(left) or not is_address(right):
|
|
124
116
|
raise ValueError("Both values must be valid addresses")
|
|
125
|
-
|
|
126
|
-
return
|
|
117
|
+
if left == right:
|
|
118
|
+
return True
|
|
119
|
+
return to_normalized_address(left) == to_normalized_address(right)
|
|
127
120
|
|
|
128
121
|
|
|
129
122
|
def is_checksum_address(value: Any) -> TypeGuard[ChecksumAddress]:
|
|
Binary file
|
faster_eth_utils/applicators.py
CHANGED
|
@@ -1,24 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
from collections.abc import Callable, Generator, Mapping, Sequence
|
|
2
2
|
from typing import (
|
|
3
3
|
TYPE_CHECKING,
|
|
4
4
|
Any,
|
|
5
|
-
|
|
6
|
-
Dict,
|
|
7
|
-
Generator,
|
|
8
|
-
List,
|
|
9
|
-
Mapping,
|
|
10
|
-
Sequence,
|
|
11
|
-
Tuple,
|
|
5
|
+
TypeGuard,
|
|
12
6
|
TypeVar,
|
|
13
|
-
Union,
|
|
14
7
|
cast,
|
|
15
8
|
overload,
|
|
16
9
|
)
|
|
17
|
-
import warnings
|
|
18
10
|
|
|
19
|
-
|
|
20
|
-
TypeGuard,
|
|
21
|
-
)
|
|
11
|
+
import warnings
|
|
22
12
|
|
|
23
13
|
from .decorators import (
|
|
24
14
|
return_arg_type,
|
|
@@ -32,25 +22,22 @@ from .toolz import (
|
|
|
32
22
|
)
|
|
33
23
|
|
|
34
24
|
if TYPE_CHECKING:
|
|
35
|
-
|
|
36
|
-
from _typeshed import SupportsBool
|
|
25
|
+
from _typeshed import SupportsBool
|
|
37
26
|
# We have to sacrifice a little bit of specificity on dinosaur Python3.8
|
|
38
|
-
else:
|
|
39
|
-
SupportsBool = Any
|
|
40
27
|
|
|
41
28
|
TArg = TypeVar("TArg")
|
|
42
29
|
TReturn = TypeVar("TReturn")
|
|
43
30
|
TOther = TypeVar("TOther")
|
|
44
31
|
|
|
45
|
-
Formatters = Callable[[
|
|
32
|
+
Formatters = Callable[[list[Any]], list[Any]]
|
|
46
33
|
|
|
47
34
|
|
|
48
35
|
@return_arg_type(2)
|
|
49
36
|
def apply_formatter_at_index(
|
|
50
37
|
formatter: Callable[[TArg], TReturn],
|
|
51
38
|
at_index: int,
|
|
52
|
-
value: Sequence[
|
|
53
|
-
) -> Generator[
|
|
39
|
+
value: Sequence[TArg | TOther],
|
|
40
|
+
) -> Generator[TOther | TReturn, None, None]:
|
|
54
41
|
try:
|
|
55
42
|
item = value[at_index]
|
|
56
43
|
except IndexError:
|
|
@@ -87,7 +74,7 @@ def combine_argument_formatters(*formatters: Callable[..., Any]) -> Formatters:
|
|
|
87
74
|
|
|
88
75
|
@return_arg_type(1)
|
|
89
76
|
def apply_formatters_to_sequence(
|
|
90
|
-
formatters:
|
|
77
|
+
formatters: list[Callable[[Any], TReturn]], sequence: Sequence[Any]
|
|
91
78
|
) -> Generator[TReturn, None, None]:
|
|
92
79
|
num_formatters = len(formatters)
|
|
93
80
|
num_items = len(sequence)
|
|
@@ -111,20 +98,20 @@ def apply_formatter_if(
|
|
|
111
98
|
condition: Callable[[TArg], TypeGuard[TOther]],
|
|
112
99
|
formatter: Callable[[TOther], TReturn],
|
|
113
100
|
value: TArg,
|
|
114
|
-
) ->
|
|
101
|
+
) -> TArg | TReturn: ...
|
|
115
102
|
|
|
116
103
|
|
|
117
104
|
@overload
|
|
118
105
|
def apply_formatter_if(
|
|
119
106
|
condition: Callable[[TArg], bool], formatter: Callable[[TArg], TReturn], value: TArg
|
|
120
|
-
) ->
|
|
107
|
+
) -> TArg | TReturn: ...
|
|
121
108
|
|
|
122
109
|
|
|
123
110
|
def apply_formatter_if( # type: ignore [misc]
|
|
124
|
-
condition:
|
|
125
|
-
formatter:
|
|
111
|
+
condition: Callable[[TArg], TypeGuard[TOther]] | Callable[[TArg], bool],
|
|
112
|
+
formatter: Callable[[TOther], TReturn] | Callable[[TArg], TReturn],
|
|
126
113
|
value: TArg,
|
|
127
|
-
) ->
|
|
114
|
+
) -> TArg | TReturn:
|
|
128
115
|
if condition(value):
|
|
129
116
|
return formatter(value) # type: ignore [arg-type]
|
|
130
117
|
else:
|
|
@@ -132,10 +119,10 @@ def apply_formatter_if( # type: ignore [misc]
|
|
|
132
119
|
|
|
133
120
|
|
|
134
121
|
def apply_formatters_to_dict(
|
|
135
|
-
formatters:
|
|
136
|
-
value:
|
|
122
|
+
formatters: dict[Any, Any],
|
|
123
|
+
value: dict[Any, Any] | CamelModel,
|
|
137
124
|
unaliased: bool = False,
|
|
138
|
-
) ->
|
|
125
|
+
) -> dict[Any, Any]:
|
|
139
126
|
"""
|
|
140
127
|
Apply formatters to a dictionary of values. If the value is a pydantic model,
|
|
141
128
|
it will be serialized to a dictionary first, taking into account the
|
|
@@ -176,8 +163,8 @@ def apply_formatter_to_array(
|
|
|
176
163
|
|
|
177
164
|
|
|
178
165
|
def apply_one_of_formatters(
|
|
179
|
-
formatter_condition_pairs:
|
|
180
|
-
|
|
166
|
+
formatter_condition_pairs: tuple[
|
|
167
|
+
tuple[Callable[[TArg], "SupportsBool"], Callable[[TArg], TReturn]], ...
|
|
181
168
|
],
|
|
182
169
|
value: TArg,
|
|
183
170
|
) -> TReturn:
|
|
@@ -191,8 +178,8 @@ def apply_one_of_formatters(
|
|
|
191
178
|
|
|
192
179
|
|
|
193
180
|
def apply_key_map(
|
|
194
|
-
key_mappings:
|
|
195
|
-
) ->
|
|
181
|
+
key_mappings: dict[Any, Any], value: Mapping[Any, Any]
|
|
182
|
+
) -> dict[Any, Any]:
|
|
196
183
|
key_conflicts = (
|
|
197
184
|
set(value.keys())
|
|
198
185
|
.difference(key_mappings.keys())
|
|
Binary file
|
faster_eth_utils/conversions.py
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
from typing import (
|
|
2
|
-
Callable,
|
|
3
|
-
Optional,
|
|
4
2
|
TypeVar,
|
|
5
3
|
Union,
|
|
6
4
|
)
|
|
5
|
+
from collections.abc import Callable
|
|
7
6
|
|
|
8
7
|
from eth_typing import (
|
|
9
8
|
HexStr,
|
|
@@ -31,9 +30,9 @@ BytesLike = Union[Primitives, bytearray, memoryview]
|
|
|
31
30
|
|
|
32
31
|
|
|
33
32
|
def to_hex(
|
|
34
|
-
primitive:
|
|
35
|
-
hexstr:
|
|
36
|
-
text:
|
|
33
|
+
primitive: BytesLike | None = None,
|
|
34
|
+
hexstr: HexStr | None = None,
|
|
35
|
+
text: str | None = None,
|
|
37
36
|
) -> HexStr:
|
|
38
37
|
"""
|
|
39
38
|
Auto converts any supported value into its hex representation.
|
|
@@ -71,9 +70,9 @@ def to_hex(
|
|
|
71
70
|
|
|
72
71
|
|
|
73
72
|
def to_int(
|
|
74
|
-
primitive:
|
|
75
|
-
hexstr:
|
|
76
|
-
text:
|
|
73
|
+
primitive: BytesLike | None = None,
|
|
74
|
+
hexstr: HexStr | None = None,
|
|
75
|
+
text: str | None = None,
|
|
77
76
|
) -> int:
|
|
78
77
|
"""
|
|
79
78
|
Converts value to its integer representation.
|
|
@@ -107,9 +106,9 @@ def to_int(
|
|
|
107
106
|
|
|
108
107
|
|
|
109
108
|
def to_bytes(
|
|
110
|
-
primitive:
|
|
111
|
-
hexstr:
|
|
112
|
-
text:
|
|
109
|
+
primitive: BytesLike | None = None,
|
|
110
|
+
hexstr: HexStr | None = None,
|
|
111
|
+
text: str | None = None,
|
|
113
112
|
) -> bytes:
|
|
114
113
|
if isinstance(primitive, bool):
|
|
115
114
|
return b"\x01" if primitive else b"\x00"
|
|
@@ -118,10 +117,10 @@ def to_bytes(
|
|
|
118
117
|
elif isinstance(primitive, bytes):
|
|
119
118
|
return primitive
|
|
120
119
|
elif isinstance(primitive, int):
|
|
121
|
-
return
|
|
120
|
+
return int_to_big_endian(primitive)
|
|
122
121
|
elif hexstr is not None:
|
|
123
122
|
if len(hexstr) % 2:
|
|
124
|
-
hexstr = "0x0
|
|
123
|
+
hexstr = HexStr(f"0x0{remove_0x_prefix(hexstr)}")
|
|
125
124
|
return decode_hex(hexstr)
|
|
126
125
|
elif text is not None:
|
|
127
126
|
return text.encode("utf-8")
|
|
@@ -132,9 +131,9 @@ def to_bytes(
|
|
|
132
131
|
|
|
133
132
|
|
|
134
133
|
def to_text(
|
|
135
|
-
primitive:
|
|
136
|
-
hexstr:
|
|
137
|
-
text:
|
|
134
|
+
primitive: BytesLike | None = None,
|
|
135
|
+
hexstr: HexStr | None = None,
|
|
136
|
+
text: str | None = None,
|
|
138
137
|
) -> str:
|
|
139
138
|
if hexstr is not None:
|
|
140
139
|
return to_bytes(hexstr=hexstr).decode("utf-8")
|
|
@@ -147,13 +146,12 @@ def to_text(
|
|
|
147
146
|
elif isinstance(primitive, memoryview):
|
|
148
147
|
return bytes(primitive).decode("utf-8")
|
|
149
148
|
elif isinstance(primitive, int):
|
|
150
|
-
|
|
151
|
-
return to_text(byte_encoding)
|
|
149
|
+
return int_to_big_endian(primitive).decode("utf-8")
|
|
152
150
|
raise TypeError("Expected an int, bytes, bytearray or hexstr.")
|
|
153
151
|
|
|
154
152
|
|
|
155
153
|
def text_if_str(
|
|
156
|
-
to_type: Callable[..., T], text_or_primitive:
|
|
154
|
+
to_type: Callable[..., T], text_or_primitive: bytes | int | str
|
|
157
155
|
) -> T:
|
|
158
156
|
"""
|
|
159
157
|
Convert to a type, assuming that strings can be only unicode text (not a hexstr).
|
|
@@ -169,7 +167,7 @@ def text_if_str(
|
|
|
169
167
|
|
|
170
168
|
|
|
171
169
|
def hexstr_if_str(
|
|
172
|
-
to_type: Callable[..., T], hexstr_or_primitive:
|
|
170
|
+
to_type: Callable[..., T], hexstr_or_primitive: bytes | int | str
|
|
173
171
|
) -> T:
|
|
174
172
|
"""
|
|
175
173
|
Convert to a type, assuming that strings can be only hexstr (not unicode text).
|
|
Binary file
|
faster_eth_utils/crypto.py
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
from typing import (
|
|
2
|
-
Optional,
|
|
3
|
-
Union,
|
|
4
|
-
)
|
|
5
|
-
|
|
6
1
|
from eth_hash.auto import (
|
|
7
2
|
keccak as keccak_256,
|
|
8
3
|
)
|
|
@@ -14,8 +9,8 @@ from .conversions import (
|
|
|
14
9
|
|
|
15
10
|
|
|
16
11
|
def keccak(
|
|
17
|
-
primitive:
|
|
18
|
-
hexstr:
|
|
19
|
-
text:
|
|
12
|
+
primitive: bytes | int | bool | None = None,
|
|
13
|
+
hexstr: HexStr | None = None,
|
|
14
|
+
text: str | None = None,
|
|
20
15
|
) -> bytes:
|
|
21
16
|
return bytes(keccak_256(to_bytes(primitive, hexstr, text)))
|
|
Binary file
|