faster-eth-abi 5.2.25__cp311-cp311-musllinux_1_2_x86_64.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.
- faster_eth_abi/__init__.py +17 -0
- faster_eth_abi/_codec.cpython-311-x86_64-linux-musl.so +0 -0
- faster_eth_abi/_codec.py +83 -0
- faster_eth_abi/_decoding.cpython-311-x86_64-linux-musl.so +0 -0
- faster_eth_abi/_decoding.py +371 -0
- faster_eth_abi/_encoding.cpython-311-x86_64-linux-musl.so +0 -0
- faster_eth_abi/_encoding.py +514 -0
- faster_eth_abi/_grammar.cpython-311-x86_64-linux-musl.so +0 -0
- faster_eth_abi/_grammar.py +389 -0
- faster_eth_abi/abi.cpython-311-x86_64-linux-musl.so +0 -0
- faster_eth_abi/abi.py +17 -0
- faster_eth_abi/base.py +45 -0
- faster_eth_abi/codec.py +2809 -0
- faster_eth_abi/constants.cpython-311-x86_64-linux-musl.so +0 -0
- faster_eth_abi/constants.py +7 -0
- faster_eth_abi/decoding.py +555 -0
- faster_eth_abi/encoding.py +738 -0
- faster_eth_abi/exceptions.cpython-311-x86_64-linux-musl.so +0 -0
- faster_eth_abi/exceptions.py +127 -0
- faster_eth_abi/from_type_str.cpython-311-x86_64-linux-musl.so +0 -0
- faster_eth_abi/from_type_str.py +141 -0
- faster_eth_abi/grammar.py +179 -0
- faster_eth_abi/io.cpython-311-x86_64-linux-musl.so +0 -0
- faster_eth_abi/io.py +137 -0
- faster_eth_abi/packed.cpython-311-x86_64-linux-musl.so +0 -0
- faster_eth_abi/packed.py +19 -0
- faster_eth_abi/py.typed +0 -0
- faster_eth_abi/registry.py +758 -0
- faster_eth_abi/tools/__init__.cpython-311-x86_64-linux-musl.so +0 -0
- faster_eth_abi/tools/__init__.py +3 -0
- faster_eth_abi/tools/_strategies.cpython-311-x86_64-linux-musl.so +0 -0
- faster_eth_abi/tools/_strategies.py +247 -0
- faster_eth_abi/typing.py +4627 -0
- faster_eth_abi/utils/__init__.cpython-311-x86_64-linux-musl.so +0 -0
- faster_eth_abi/utils/__init__.py +0 -0
- faster_eth_abi/utils/localcontext.cpython-311-x86_64-linux-musl.so +0 -0
- faster_eth_abi/utils/localcontext.py +49 -0
- faster_eth_abi/utils/numeric.cpython-311-x86_64-linux-musl.so +0 -0
- faster_eth_abi/utils/numeric.py +117 -0
- faster_eth_abi/utils/padding.cpython-311-x86_64-linux-musl.so +0 -0
- faster_eth_abi/utils/padding.py +22 -0
- faster_eth_abi/utils/string.cpython-311-x86_64-linux-musl.so +0 -0
- faster_eth_abi/utils/string.py +19 -0
- faster_eth_abi/utils/validation.cpython-311-x86_64-linux-musl.so +0 -0
- faster_eth_abi/utils/validation.py +18 -0
- faster_eth_abi-5.2.25.dist-info/METADATA +134 -0
- faster_eth_abi-5.2.25.dist-info/RECORD +50 -0
- faster_eth_abi-5.2.25.dist-info/WHEEL +5 -0
- faster_eth_abi-5.2.25.dist-info/top_level.txt +2 -0
- faster_eth_abi__mypyc.cpython-311-x86_64-linux-musl.so +0 -0
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
from typing import (
|
|
2
|
+
Any,
|
|
3
|
+
Callable,
|
|
4
|
+
Final,
|
|
5
|
+
Optional,
|
|
6
|
+
Tuple,
|
|
7
|
+
TypeAlias,
|
|
8
|
+
Union,
|
|
9
|
+
cast,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
from cchecksum import (
|
|
13
|
+
to_checksum_address,
|
|
14
|
+
)
|
|
15
|
+
from eth_typing.abi import (
|
|
16
|
+
TypeStr,
|
|
17
|
+
)
|
|
18
|
+
from hypothesis import (
|
|
19
|
+
strategies as st,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
from faster_eth_abi._grammar import (
|
|
23
|
+
ABIType,
|
|
24
|
+
Arrlist,
|
|
25
|
+
BasicType,
|
|
26
|
+
TupleType,
|
|
27
|
+
normalize,
|
|
28
|
+
)
|
|
29
|
+
from faster_eth_abi.grammar import (
|
|
30
|
+
parse,
|
|
31
|
+
)
|
|
32
|
+
from faster_eth_abi.registry import (
|
|
33
|
+
BaseEquals,
|
|
34
|
+
BaseRegistry,
|
|
35
|
+
Lookup,
|
|
36
|
+
PredicateMapping,
|
|
37
|
+
has_arrlist,
|
|
38
|
+
is_base_tuple,
|
|
39
|
+
)
|
|
40
|
+
from faster_eth_abi.utils.numeric import (
|
|
41
|
+
scale_places,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
StrategyFactory: TypeAlias = Callable[[ABIType, "StrategyRegistry"], st.SearchStrategy]
|
|
45
|
+
StrategyRegistration: TypeAlias = Union[st.SearchStrategy, StrategyFactory]
|
|
46
|
+
StrategyMapping: TypeAlias = PredicateMapping[StrategyRegistration]
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class StrategyRegistry(BaseRegistry):
|
|
50
|
+
def __init__(self) -> None:
|
|
51
|
+
strategies: StrategyMapping = PredicateMapping("strategy registry")
|
|
52
|
+
self._strategies: Final = strategies
|
|
53
|
+
|
|
54
|
+
def register_strategy(
|
|
55
|
+
self,
|
|
56
|
+
lookup: Lookup,
|
|
57
|
+
registration: StrategyRegistration,
|
|
58
|
+
label: Optional[str] = None,
|
|
59
|
+
) -> None:
|
|
60
|
+
self._register(self._strategies, lookup, registration, label=label)
|
|
61
|
+
|
|
62
|
+
def unregister_strategy(self, lookup_or_label: Lookup) -> None:
|
|
63
|
+
self._unregister(self._strategies, lookup_or_label)
|
|
64
|
+
|
|
65
|
+
def get_strategy(self, type_str: TypeStr) -> st.SearchStrategy:
|
|
66
|
+
"""
|
|
67
|
+
Returns a hypothesis strategy for the given ABI type.
|
|
68
|
+
|
|
69
|
+
:param type_str: The canonical string representation of the ABI type
|
|
70
|
+
for which a hypothesis strategy should be returned.
|
|
71
|
+
|
|
72
|
+
:returns: A hypothesis strategy for generating Python values that are
|
|
73
|
+
encodable as values of the given ABI type.
|
|
74
|
+
"""
|
|
75
|
+
registration = self._get_registration(self._strategies, type_str)
|
|
76
|
+
|
|
77
|
+
if isinstance(registration, st.SearchStrategy):
|
|
78
|
+
# If a hypothesis strategy was registered, just return it
|
|
79
|
+
return registration
|
|
80
|
+
else:
|
|
81
|
+
# Otherwise, assume the factory is a callable. Call it with the abi
|
|
82
|
+
# type to get an appropriate hypothesis strategy.
|
|
83
|
+
normalized_type_str = normalize(type_str)
|
|
84
|
+
abi_type = parse(normalized_type_str)
|
|
85
|
+
strategy = registration(abi_type, self)
|
|
86
|
+
|
|
87
|
+
return strategy
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def get_uint_strategy(
|
|
91
|
+
abi_type: BasicType[Any], registry: StrategyRegistry
|
|
92
|
+
) -> st.SearchStrategy:
|
|
93
|
+
bits = cast(int, abi_type.sub)
|
|
94
|
+
|
|
95
|
+
return st.integers(
|
|
96
|
+
min_value=0,
|
|
97
|
+
max_value=2**bits - 1,
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def get_int_strategy(
|
|
102
|
+
abi_type: BasicType[Any], registry: StrategyRegistry
|
|
103
|
+
) -> st.SearchStrategy:
|
|
104
|
+
bits = cast(int, abi_type.sub)
|
|
105
|
+
|
|
106
|
+
return st.integers(
|
|
107
|
+
min_value=-(2 ** (bits - 1)),
|
|
108
|
+
max_value=2 ** (bits - 1) - 1,
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
address_strategy: Final = st.binary(min_size=20, max_size=20).map(to_checksum_address)
|
|
113
|
+
bool_strategy: Final = st.booleans()
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def get_ufixed_strategy(
|
|
117
|
+
abi_type: BasicType[Any], registry: StrategyRegistry
|
|
118
|
+
) -> st.SearchStrategy:
|
|
119
|
+
bits, places = cast(Tuple[int, int], abi_type.sub)
|
|
120
|
+
|
|
121
|
+
return st.decimals(
|
|
122
|
+
min_value=0,
|
|
123
|
+
max_value=2**bits - 1,
|
|
124
|
+
places=0,
|
|
125
|
+
).map(scale_places(places))
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def get_fixed_strategy(
|
|
129
|
+
abi_type: BasicType[Any], registry: StrategyRegistry
|
|
130
|
+
) -> st.SearchStrategy:
|
|
131
|
+
bits, places = cast(Tuple[int, int], abi_type.sub)
|
|
132
|
+
|
|
133
|
+
return st.decimals(
|
|
134
|
+
min_value=-(2 ** (bits - 1)),
|
|
135
|
+
max_value=2 ** (bits - 1) - 1,
|
|
136
|
+
places=0,
|
|
137
|
+
).map(scale_places(places))
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def get_bytes_strategy(
|
|
141
|
+
abi_type: BasicType[Any], registry: StrategyRegistry
|
|
142
|
+
) -> st.SearchStrategy:
|
|
143
|
+
num_bytes = abi_type.sub
|
|
144
|
+
|
|
145
|
+
return st.binary(
|
|
146
|
+
min_size=num_bytes,
|
|
147
|
+
max_size=num_bytes,
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
bytes_strategy: Final = st.binary(min_size=0, max_size=4096)
|
|
152
|
+
string_strategy: Final = st.text()
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def get_array_strategy(
|
|
156
|
+
abi_type: ABIType, registry: StrategyRegistry
|
|
157
|
+
) -> st.SearchStrategy:
|
|
158
|
+
item_type = abi_type.item_type
|
|
159
|
+
item_type_str = item_type.to_type_str()
|
|
160
|
+
item_strategy = registry.get_strategy(item_type_str)
|
|
161
|
+
|
|
162
|
+
arrlist = cast(Arrlist, abi_type.arrlist)
|
|
163
|
+
last_dim = cast(Tuple[int, ...], arrlist[-1])
|
|
164
|
+
if len(last_dim) == 0:
|
|
165
|
+
# Is dynamic list. Don't restrict length.
|
|
166
|
+
return st.lists(item_strategy)
|
|
167
|
+
else:
|
|
168
|
+
# Is static list. Restrict length.
|
|
169
|
+
dim_size = last_dim[0]
|
|
170
|
+
return st.lists(item_strategy, min_size=dim_size, max_size=dim_size)
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def get_tuple_strategy(
|
|
174
|
+
abi_type: TupleType, registry: StrategyRegistry
|
|
175
|
+
) -> st.SearchStrategy:
|
|
176
|
+
component_strategies = [
|
|
177
|
+
registry.get_strategy(comp_abi_type.to_type_str())
|
|
178
|
+
for comp_abi_type in abi_type.components
|
|
179
|
+
]
|
|
180
|
+
|
|
181
|
+
return st.tuples(*component_strategies)
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
strategy_registry: Final = StrategyRegistry()
|
|
185
|
+
|
|
186
|
+
strategy_registry.register_strategy(
|
|
187
|
+
BaseEquals("uint"),
|
|
188
|
+
get_uint_strategy,
|
|
189
|
+
label="uint",
|
|
190
|
+
)
|
|
191
|
+
strategy_registry.register_strategy(
|
|
192
|
+
BaseEquals("int"),
|
|
193
|
+
get_int_strategy,
|
|
194
|
+
label="int",
|
|
195
|
+
)
|
|
196
|
+
strategy_registry.register_strategy(
|
|
197
|
+
BaseEquals("address", with_sub=False),
|
|
198
|
+
address_strategy,
|
|
199
|
+
label="address",
|
|
200
|
+
)
|
|
201
|
+
strategy_registry.register_strategy(
|
|
202
|
+
BaseEquals("bool", with_sub=False),
|
|
203
|
+
bool_strategy,
|
|
204
|
+
label="bool",
|
|
205
|
+
)
|
|
206
|
+
strategy_registry.register_strategy(
|
|
207
|
+
BaseEquals("ufixed"),
|
|
208
|
+
get_ufixed_strategy,
|
|
209
|
+
label="ufixed",
|
|
210
|
+
)
|
|
211
|
+
strategy_registry.register_strategy(
|
|
212
|
+
BaseEquals("fixed"),
|
|
213
|
+
get_fixed_strategy,
|
|
214
|
+
label="fixed",
|
|
215
|
+
)
|
|
216
|
+
strategy_registry.register_strategy(
|
|
217
|
+
BaseEquals("bytes", with_sub=True),
|
|
218
|
+
get_bytes_strategy,
|
|
219
|
+
label="bytes<M>",
|
|
220
|
+
)
|
|
221
|
+
strategy_registry.register_strategy(
|
|
222
|
+
BaseEquals("bytes", with_sub=False),
|
|
223
|
+
bytes_strategy,
|
|
224
|
+
label="bytes",
|
|
225
|
+
)
|
|
226
|
+
strategy_registry.register_strategy(
|
|
227
|
+
BaseEquals("function", with_sub=False),
|
|
228
|
+
get_bytes_strategy,
|
|
229
|
+
label="function",
|
|
230
|
+
)
|
|
231
|
+
strategy_registry.register_strategy(
|
|
232
|
+
BaseEquals("string", with_sub=False),
|
|
233
|
+
string_strategy,
|
|
234
|
+
label="string",
|
|
235
|
+
)
|
|
236
|
+
strategy_registry.register_strategy(
|
|
237
|
+
has_arrlist,
|
|
238
|
+
get_array_strategy,
|
|
239
|
+
label="has_arrlist",
|
|
240
|
+
)
|
|
241
|
+
strategy_registry.register_strategy(
|
|
242
|
+
is_base_tuple,
|
|
243
|
+
get_tuple_strategy,
|
|
244
|
+
label="is_base_tuple",
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
get_abi_strategy: Final = strategy_registry.get_strategy
|