faster-eth-abi 5.2.3__cp314-cp314-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.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.
- a1f8aa123fabc88e2b56__mypyc.cpython-314-i386-linux-gnu.so +0 -0
- faster_eth_abi/__init__.py +12 -0
- faster_eth_abi/abi.cpython-314-i386-linux-gnu.so +0 -0
- faster_eth_abi/abi.py +17 -0
- faster_eth_abi/base.py +41 -0
- faster_eth_abi/codec.py +167 -0
- faster_eth_abi/constants.cpython-314-i386-linux-gnu.so +0 -0
- faster_eth_abi/constants.py +7 -0
- faster_eth_abi/decoding.py +563 -0
- faster_eth_abi/encoding.py +699 -0
- faster_eth_abi/exceptions.py +115 -0
- faster_eth_abi/from_type_str.cpython-314-i386-linux-gnu.so +0 -0
- faster_eth_abi/from_type_str.py +135 -0
- faster_eth_abi/grammar.py +467 -0
- faster_eth_abi/io.py +103 -0
- faster_eth_abi/packed.cpython-314-i386-linux-gnu.so +0 -0
- faster_eth_abi/packed.py +15 -0
- faster_eth_abi/py.typed +0 -0
- faster_eth_abi/registry.py +640 -0
- faster_eth_abi/tools/__init__.cpython-314-i386-linux-gnu.so +0 -0
- faster_eth_abi/tools/__init__.py +3 -0
- faster_eth_abi/tools/_strategies.cpython-314-i386-linux-gnu.so +0 -0
- faster_eth_abi/tools/_strategies.py +237 -0
- faster_eth_abi/utils/__init__.cpython-314-i386-linux-gnu.so +0 -0
- faster_eth_abi/utils/__init__.py +0 -0
- faster_eth_abi/utils/numeric.cpython-314-i386-linux-gnu.so +0 -0
- faster_eth_abi/utils/numeric.py +86 -0
- faster_eth_abi/utils/padding.cpython-314-i386-linux-gnu.so +0 -0
- faster_eth_abi/utils/padding.py +22 -0
- faster_eth_abi/utils/string.cpython-314-i386-linux-gnu.so +0 -0
- faster_eth_abi/utils/string.py +19 -0
- faster_eth_abi/utils/validation.cpython-314-i386-linux-gnu.so +0 -0
- faster_eth_abi/utils/validation.py +22 -0
- faster_eth_abi-5.2.3.dist-info/METADATA +95 -0
- faster_eth_abi-5.2.3.dist-info/RECORD +38 -0
- faster_eth_abi-5.2.3.dist-info/WHEEL +7 -0
- faster_eth_abi-5.2.3.dist-info/licenses/LICENSE +21 -0
- faster_eth_abi-5.2.3.dist-info/top_level.txt +3 -0
Binary file
|
Binary file
|
faster_eth_abi/abi.py
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
from typing import (
|
2
|
+
Final,
|
3
|
+
)
|
4
|
+
|
5
|
+
from faster_eth_abi.codec import (
|
6
|
+
ABICodec,
|
7
|
+
)
|
8
|
+
from faster_eth_abi.registry import (
|
9
|
+
registry,
|
10
|
+
)
|
11
|
+
|
12
|
+
default_codec: Final = ABICodec(registry)
|
13
|
+
|
14
|
+
encode: Final = default_codec.encode
|
15
|
+
decode: Final = default_codec.decode
|
16
|
+
is_encodable: Final = default_codec.is_encodable
|
17
|
+
is_encodable_type: Final = default_codec.is_encodable_type
|
faster_eth_abi/base.py
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
from typing import (
|
2
|
+
Any,
|
3
|
+
)
|
4
|
+
|
5
|
+
|
6
|
+
class BaseCoder:
|
7
|
+
"""
|
8
|
+
Base class for all encoder and decoder classes.
|
9
|
+
"""
|
10
|
+
|
11
|
+
is_dynamic = False
|
12
|
+
|
13
|
+
def __init__(self, **kwargs: Any) -> None:
|
14
|
+
cls = type(self)
|
15
|
+
|
16
|
+
# Ensure no unrecognized kwargs were given
|
17
|
+
for key, value in kwargs.items():
|
18
|
+
if not hasattr(cls, key):
|
19
|
+
raise AttributeError(
|
20
|
+
"Property {key} not found on {cls_name} class. "
|
21
|
+
"`{cls_name}.__init__` only accepts keyword arguments which are "
|
22
|
+
"present on the {cls_name} class.".format(
|
23
|
+
key=key,
|
24
|
+
cls_name=cls.__name__,
|
25
|
+
)
|
26
|
+
)
|
27
|
+
setattr(self, key, value)
|
28
|
+
|
29
|
+
# Validate given combination of kwargs
|
30
|
+
self.validate()
|
31
|
+
|
32
|
+
def validate(self):
|
33
|
+
pass
|
34
|
+
|
35
|
+
@classmethod
|
36
|
+
def from_type_str(cls, type_str, registry): # pragma: no cover
|
37
|
+
"""
|
38
|
+
Used by :any:`ABIRegistry` to get an appropriate encoder or decoder
|
39
|
+
instance for the given type string and type registry.
|
40
|
+
"""
|
41
|
+
raise NotImplementedError("Must implement `from_type_str`")
|
faster_eth_abi/codec.py
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
from typing import (
|
2
|
+
Any,
|
3
|
+
Iterable,
|
4
|
+
Tuple,
|
5
|
+
cast,
|
6
|
+
)
|
7
|
+
|
8
|
+
from eth_typing.abi import (
|
9
|
+
Decodable,
|
10
|
+
TypeStr,
|
11
|
+
)
|
12
|
+
|
13
|
+
from faster_eth_abi.decoding import (
|
14
|
+
ContextFramesBytesIO,
|
15
|
+
TupleDecoder,
|
16
|
+
)
|
17
|
+
from faster_eth_abi.encoding import (
|
18
|
+
TupleEncoder,
|
19
|
+
)
|
20
|
+
from faster_eth_abi.exceptions import (
|
21
|
+
EncodingError,
|
22
|
+
)
|
23
|
+
from faster_eth_abi.registry import (
|
24
|
+
ABIRegistry,
|
25
|
+
)
|
26
|
+
from faster_eth_abi.utils.validation import (
|
27
|
+
validate_bytes_param,
|
28
|
+
validate_list_like_param,
|
29
|
+
)
|
30
|
+
|
31
|
+
|
32
|
+
class BaseABICoder:
|
33
|
+
"""
|
34
|
+
Base class for porcelain coding APIs. These are classes which wrap
|
35
|
+
instances of :class:`~faster_eth_abi.registry.ABIRegistry` to provide last-mile
|
36
|
+
coding functionality.
|
37
|
+
"""
|
38
|
+
|
39
|
+
def __init__(self, registry: ABIRegistry):
|
40
|
+
"""
|
41
|
+
Constructor.
|
42
|
+
|
43
|
+
:param registry: The registry providing the encoders to be used when
|
44
|
+
encoding values.
|
45
|
+
"""
|
46
|
+
self._registry = registry
|
47
|
+
|
48
|
+
|
49
|
+
class ABIEncoder(BaseABICoder):
|
50
|
+
"""
|
51
|
+
Wraps a registry to provide last-mile encoding functionality.
|
52
|
+
"""
|
53
|
+
|
54
|
+
def encode(self, types: Iterable[TypeStr], args: Iterable[Any]) -> bytes:
|
55
|
+
"""
|
56
|
+
Encodes the python values in ``args`` as a sequence of binary values of
|
57
|
+
the ABI types in ``types`` via the head-tail mechanism.
|
58
|
+
|
59
|
+
:param types: A list or tuple of string representations of the ABI types
|
60
|
+
that will be used for encoding e.g. ``('uint256', 'bytes[]',
|
61
|
+
'(int,int)')``
|
62
|
+
:param args: A list or tuple of python values to be encoded.
|
63
|
+
|
64
|
+
:returns: The head-tail encoded binary representation of the python
|
65
|
+
values in ``args`` as values of the ABI types in ``types``.
|
66
|
+
"""
|
67
|
+
# validate encode types and args
|
68
|
+
validate_list_like_param(types, "types")
|
69
|
+
validate_list_like_param(args, "args")
|
70
|
+
|
71
|
+
encoders = tuple(self._registry.get_encoder(type_str) for type_str in types)
|
72
|
+
|
73
|
+
encoder = TupleEncoder(encoders=encoders)
|
74
|
+
|
75
|
+
return encoder(args)
|
76
|
+
|
77
|
+
def is_encodable(self, typ: TypeStr, arg: Any) -> bool:
|
78
|
+
"""
|
79
|
+
Determines if the python value ``arg`` is encodable as a value of the
|
80
|
+
ABI type ``typ``.
|
81
|
+
|
82
|
+
:param typ: A string representation for the ABI type against which the
|
83
|
+
python value ``arg`` will be checked e.g. ``'uint256'``,
|
84
|
+
``'bytes[]'``, ``'(int,int)'``, etc.
|
85
|
+
:param arg: The python value whose encodability should be checked.
|
86
|
+
|
87
|
+
:returns: ``True`` if ``arg`` is encodable as a value of the ABI type
|
88
|
+
``typ``. Otherwise, ``False``.
|
89
|
+
"""
|
90
|
+
if not self.is_encodable_type(typ):
|
91
|
+
return False
|
92
|
+
|
93
|
+
encoder = self._registry.get_encoder(typ)
|
94
|
+
|
95
|
+
try:
|
96
|
+
encoder.validate_value(arg)
|
97
|
+
except EncodingError:
|
98
|
+
return False
|
99
|
+
except AttributeError:
|
100
|
+
try:
|
101
|
+
encoder(arg)
|
102
|
+
except EncodingError:
|
103
|
+
return False
|
104
|
+
|
105
|
+
return True
|
106
|
+
|
107
|
+
def is_encodable_type(self, typ: TypeStr) -> bool:
|
108
|
+
"""
|
109
|
+
Returns ``True`` if values for the ABI type ``typ`` can be encoded by
|
110
|
+
this codec.
|
111
|
+
|
112
|
+
:param typ: A string representation for the ABI type that will be
|
113
|
+
checked for encodability e.g. ``'uint256'``, ``'bytes[]'``,
|
114
|
+
``'(int,int)'``, etc.
|
115
|
+
|
116
|
+
:returns: ``True`` if values for ``typ`` can be encoded by this codec.
|
117
|
+
Otherwise, ``False``.
|
118
|
+
"""
|
119
|
+
return self._registry.has_encoder(typ)
|
120
|
+
|
121
|
+
|
122
|
+
class ABIDecoder(BaseABICoder):
|
123
|
+
"""
|
124
|
+
Wraps a registry to provide last-mile decoding functionality.
|
125
|
+
"""
|
126
|
+
|
127
|
+
stream_class = ContextFramesBytesIO
|
128
|
+
|
129
|
+
def decode(
|
130
|
+
self,
|
131
|
+
types: Iterable[TypeStr],
|
132
|
+
data: Decodable,
|
133
|
+
strict: bool = True,
|
134
|
+
) -> Tuple[Any, ...]:
|
135
|
+
"""
|
136
|
+
Decodes the binary value ``data`` as a sequence of values of the ABI types
|
137
|
+
in ``types`` via the head-tail mechanism into a tuple of equivalent python
|
138
|
+
values.
|
139
|
+
|
140
|
+
:param types: A list or tuple of string representations of the ABI types that
|
141
|
+
will be used for decoding e.g. ``('uint256', 'bytes[]', '(int,int)')``
|
142
|
+
:param data: The binary value to be decoded.
|
143
|
+
:param strict: If ``False``, dynamic-type decoders will ignore validations such
|
144
|
+
as making sure the data is padded to a multiple of 32 bytes or checking that
|
145
|
+
padding bytes are zero / empty. ``False`` is how the Solidity ABI decoder
|
146
|
+
currently works. However, ``True`` is the default for the faster-eth-abi
|
147
|
+
library.
|
148
|
+
|
149
|
+
:returns: A tuple of equivalent python values for the ABI values
|
150
|
+
represented in ``data``.
|
151
|
+
"""
|
152
|
+
# validate decode types and data
|
153
|
+
validate_list_like_param(types, "types")
|
154
|
+
validate_bytes_param(data, "data")
|
155
|
+
|
156
|
+
decoders = tuple(
|
157
|
+
self._registry.get_decoder(type_str, strict=strict) for type_str in types
|
158
|
+
)
|
159
|
+
|
160
|
+
decoder = TupleDecoder(decoders=decoders)
|
161
|
+
stream = self.stream_class(data)
|
162
|
+
|
163
|
+
return cast(Tuple[Any, ...], decoder(stream))
|
164
|
+
|
165
|
+
|
166
|
+
class ABICodec(ABIEncoder, ABIDecoder):
|
167
|
+
pass
|
Binary file
|