faster-eth-abi 5.2.10__tar.gz → 5.2.12__tar.gz
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-abi might be problematic. Click here for more details.
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/PKG-INFO +58 -4
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/README.md +5 -1
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/faster_eth_abi/_codec.py +0 -4
- faster_eth_abi-5.2.10/faster_eth_abi/grammar.py → faster_eth_abi-5.2.12/faster_eth_abi/_grammar.py +45 -164
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/faster_eth_abi/codec.py +8 -9
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/faster_eth_abi/exceptions.py +22 -13
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/faster_eth_abi/from_type_str.py +3 -1
- faster_eth_abi-5.2.12/faster_eth_abi/grammar.py +170 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/faster_eth_abi/registry.py +37 -24
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/faster_eth_abi/tools/_strategies.py +9 -5
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/faster_eth_abi.egg-info/PKG-INFO +59 -5
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/faster_eth_abi.egg-info/SOURCES.txt +1 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/faster_eth_abi.egg-info/requires.txt +4 -3
- faster_eth_abi-5.2.12/faster_eth_abi.egg-info/top_level.txt +1 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/pyproject.toml +6 -4
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/setup.py +37 -20
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/abi_tests/test_decode.py +11 -4
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/abi_tests/test_encode.py +14 -3
- faster_eth_abi-5.2.10/faster_eth_abi.egg-info/top_level.txt +0 -2
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/LICENSE +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/MANIFEST.in +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/faster_eth_abi/__init__.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/faster_eth_abi/_decoding.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/faster_eth_abi/_encoding.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/faster_eth_abi/abi.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/faster_eth_abi/base.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/faster_eth_abi/constants.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/faster_eth_abi/decoding.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/faster_eth_abi/encoding.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/faster_eth_abi/io.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/faster_eth_abi/packed.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/faster_eth_abi/py.typed +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/faster_eth_abi/tools/__init__.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/faster_eth_abi/utils/__init__.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/faster_eth_abi/utils/numeric.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/faster_eth_abi/utils/padding.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/faster_eth_abi/utils/string.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/faster_eth_abi/utils/validation.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/faster_eth_abi.egg-info/dependency_links.txt +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/faster_eth_abi.egg-info/not-zip-safe +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/scripts/benchmark/compare_benchmark_results.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/scripts/benchmark/generate_benchmark_markdown.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/scripts/benchmark/parse_benchmark_output.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/scripts/release/test_package.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/setup.cfg +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/__init__.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/abi_tests/__init__.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/abi_tests/test_is_encodable.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/abi_tests/test_is_encodable_type.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/abi_tests/test_reversibility_properties.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/abi_tests/test_uint_properties.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/base.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/common/__init__.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/common/strategies.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/common/unit.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/decoding/__init__.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/decoding/test_context_frames_bytes_io.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/decoding/test_decoder_properties.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/encoding/__init__.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/encoding/test_encoder_properties.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/end_to_end/__init__.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/end_to_end/test_custom_registrations.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/grammar.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/packed/__init__.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/packed/test_encode_packed.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/packed/test_is_encodable_packed.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/registry/__init__.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/registry/test_abi_registry.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/registry/test_predicate_mapping.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/registry/test_predicates.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/test_import_and_version.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/test_tools.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/utils/__init__.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/utils/test_abbr.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/utils/test_ceil32.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/utils/test_scale_places.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/utils/test_validation_utils.py +0 -0
- {faster_eth_abi-5.2.10 → faster_eth_abi-5.2.12}/tests/core/utils/test_zpad.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: faster_eth_abi
|
|
3
|
-
Version: 5.2.
|
|
3
|
+
Version: 5.2.12
|
|
4
4
|
Summary: A faster fork of eth_abi: Python utilities for working with Ethereum ABI definitions, especially encoding and decoding. Implemented in C.
|
|
5
5
|
Home-page: https://github.com/BobTheBuidler/faster-eth-abi
|
|
6
6
|
Author: The Ethereum Foundation
|
|
@@ -22,11 +22,61 @@ Classifier: Programming Language :: Python :: 3.14
|
|
|
22
22
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
23
23
|
Requires-Python: >=3.8, <4
|
|
24
24
|
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: cchecksum<0.4,>=0.2.6
|
|
27
|
+
Requires-Dist: faster-eth-utils>=2.0.0
|
|
28
|
+
Requires-Dist: eth-abi<6,>=5.0.1
|
|
29
|
+
Requires-Dist: eth-typing>=3.0.0
|
|
30
|
+
Requires-Dist: mypy_extensions
|
|
31
|
+
Requires-Dist: parsimonious<0.11.0,>=0.10.0
|
|
25
32
|
Provides-Extra: dev
|
|
33
|
+
Requires-Dist: build>=0.9.0; extra == "dev"
|
|
34
|
+
Requires-Dist: bump_my_version>=0.19.0; extra == "dev"
|
|
35
|
+
Requires-Dist: ipython; extra == "dev"
|
|
36
|
+
Requires-Dist: mypy==1.18.2; extra == "dev"
|
|
37
|
+
Requires-Dist: pre-commit>=3.4.0; extra == "dev"
|
|
38
|
+
Requires-Dist: tox>=4.0.0; extra == "dev"
|
|
39
|
+
Requires-Dist: twine; extra == "dev"
|
|
40
|
+
Requires-Dist: wheel; extra == "dev"
|
|
41
|
+
Requires-Dist: pytest-codspeed; extra == "dev"
|
|
42
|
+
Requires-Dist: pytest-benchmark; extra == "dev"
|
|
43
|
+
Requires-Dist: sphinx>=6.0.0; extra == "dev"
|
|
44
|
+
Requires-Dist: sphinx-autobuild>=2021.3.14; extra == "dev"
|
|
45
|
+
Requires-Dist: sphinx_rtd_theme>=1.0.0; extra == "dev"
|
|
46
|
+
Requires-Dist: towncrier<26,>=25; extra == "dev"
|
|
47
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
48
|
+
Requires-Dist: pytest-timeout>=2.0.0; extra == "dev"
|
|
49
|
+
Requires-Dist: pytest-xdist>=2.4.0; extra == "dev"
|
|
50
|
+
Requires-Dist: pytest-pythonpath>=0.7.1; extra == "dev"
|
|
51
|
+
Requires-Dist: eth-hash[pycryptodome]; extra == "dev"
|
|
52
|
+
Requires-Dist: hypothesis<6.108.7,>=6.22.0; extra == "dev"
|
|
26
53
|
Provides-Extra: docs
|
|
54
|
+
Requires-Dist: sphinx>=6.0.0; extra == "docs"
|
|
55
|
+
Requires-Dist: sphinx-autobuild>=2021.3.14; extra == "docs"
|
|
56
|
+
Requires-Dist: sphinx_rtd_theme>=1.0.0; extra == "docs"
|
|
57
|
+
Requires-Dist: towncrier<26,>=25; extra == "docs"
|
|
27
58
|
Provides-Extra: test
|
|
59
|
+
Requires-Dist: pytest>=7.0.0; extra == "test"
|
|
60
|
+
Requires-Dist: pytest-timeout>=2.0.0; extra == "test"
|
|
61
|
+
Requires-Dist: pytest-xdist>=2.4.0; extra == "test"
|
|
62
|
+
Requires-Dist: pytest-pythonpath>=0.7.1; extra == "test"
|
|
63
|
+
Requires-Dist: eth-hash[pycryptodome]; extra == "test"
|
|
64
|
+
Requires-Dist: hypothesis<6.108.7,>=6.22.0; extra == "test"
|
|
28
65
|
Provides-Extra: tools
|
|
29
|
-
|
|
66
|
+
Requires-Dist: hypothesis<6.108.7,>=6.22.0; extra == "tools"
|
|
67
|
+
Dynamic: author
|
|
68
|
+
Dynamic: author-email
|
|
69
|
+
Dynamic: classifier
|
|
70
|
+
Dynamic: description
|
|
71
|
+
Dynamic: description-content-type
|
|
72
|
+
Dynamic: home-page
|
|
73
|
+
Dynamic: keywords
|
|
74
|
+
Dynamic: license
|
|
75
|
+
Dynamic: license-file
|
|
76
|
+
Dynamic: provides-extra
|
|
77
|
+
Dynamic: requires-dist
|
|
78
|
+
Dynamic: requires-python
|
|
79
|
+
Dynamic: summary
|
|
30
80
|
|
|
31
81
|
### I forked eth-abi and compiled it to C. It does the same stuff, now faster
|
|
32
82
|
|
|
@@ -36,10 +86,14 @@ License-File: LICENSE
|
|
|
36
86
|
|
|
37
87
|
##### This fork will be kept up-to-date with [eth-abi](https://github.com/ethereum/eth-abi). I will pull updates as they are released and push new [faster-eth-abi](https://github.com/BobTheBuidler/faster-eth-abi) releases to [PyPI](https://pypi.org/project/faster-eth-abi/).
|
|
38
88
|
|
|
39
|
-
#####
|
|
89
|
+
##### Starting in [v5.2.12](https://github.com/BobTheBuidler/faster-eth-abi/releases/tag/v5.2.12), all `faster-eth-abi` Exception classes inherit from the matching Exception class in `eth-abi`, so porting to `faster-eth-abi` does not require any change to your existing exception handlers. All existing exception handling in your codebase will continue to work as it did when originaly implemented.
|
|
40
90
|
|
|
41
91
|
##### We benchmark `faster-eth-abi` against the original `eth-abi` for your convenience. [See results](https://github.com/BobTheBuidler/faster-eth-abi/tree/master/benchmarks/results).
|
|
42
92
|
|
|
93
|
+
##### You can find the compiled C code and header files in the [build](https://github.com/BobTheBuidler/faster-eth-abi/tree/master/build) directory.
|
|
94
|
+
|
|
95
|
+
###### You may also be interested in: [faster-web3.py](https://github.com/BobTheBuidler/faster-web3.py/), [faster-hexbytes](https://github.com/BobTheBuidler/faster-hexbytes/), and [faster-eth-utils](https://github.com/BobTheBuidler/faster-eth-utils/)
|
|
96
|
+
|
|
43
97
|
##### The original eth-abi readme is below:
|
|
44
98
|
|
|
45
99
|
# Ethereum Contract Interface (ABI) Utility
|
|
@@ -6,10 +6,14 @@
|
|
|
6
6
|
|
|
7
7
|
##### This fork will be kept up-to-date with [eth-abi](https://github.com/ethereum/eth-abi). I will pull updates as they are released and push new [faster-eth-abi](https://github.com/BobTheBuidler/faster-eth-abi) releases to [PyPI](https://pypi.org/project/faster-eth-abi/).
|
|
8
8
|
|
|
9
|
-
#####
|
|
9
|
+
##### Starting in [v5.2.12](https://github.com/BobTheBuidler/faster-eth-abi/releases/tag/v5.2.12), all `faster-eth-abi` Exception classes inherit from the matching Exception class in `eth-abi`, so porting to `faster-eth-abi` does not require any change to your existing exception handlers. All existing exception handling in your codebase will continue to work as it did when originaly implemented.
|
|
10
10
|
|
|
11
11
|
##### We benchmark `faster-eth-abi` against the original `eth-abi` for your convenience. [See results](https://github.com/BobTheBuidler/faster-eth-abi/tree/master/benchmarks/results).
|
|
12
12
|
|
|
13
|
+
##### You can find the compiled C code and header files in the [build](https://github.com/BobTheBuidler/faster-eth-abi/tree/master/build) directory.
|
|
14
|
+
|
|
15
|
+
###### You may also be interested in: [faster-web3.py](https://github.com/BobTheBuidler/faster-web3.py/), [faster-hexbytes](https://github.com/BobTheBuidler/faster-hexbytes/), and [faster-eth-utils](https://github.com/BobTheBuidler/faster-eth-utils/)
|
|
16
|
+
|
|
13
17
|
##### The original eth-abi readme is below:
|
|
14
18
|
|
|
15
19
|
# Ethereum Contract Interface (ABI) Utility
|
|
@@ -39,8 +39,6 @@ def encode_c(
|
|
|
39
39
|
:returns: The head-tail encoded binary representation of the python
|
|
40
40
|
values in ``args`` as values of the ABI types in ``types``.
|
|
41
41
|
"""
|
|
42
|
-
# validate encode types and args
|
|
43
|
-
validate_list_like_param(types, "types")
|
|
44
42
|
validate_list_like_param(args, "args")
|
|
45
43
|
|
|
46
44
|
encoder = self._registry.get_tuple_encoder(*types)
|
|
@@ -71,8 +69,6 @@ def decode_c(
|
|
|
71
69
|
:returns: A tuple of equivalent python values for the ABI values
|
|
72
70
|
represented in ``data``.
|
|
73
71
|
"""
|
|
74
|
-
# validate decode types and data
|
|
75
|
-
validate_list_like_param(types, "types")
|
|
76
72
|
validate_bytes_param(data, "data")
|
|
77
73
|
|
|
78
74
|
decoder = self._registry.get_tuple_decoder(*types, strict=strict)
|
faster_eth_abi-5.2.10/faster_eth_abi/grammar.py → faster_eth_abi-5.2.12/faster_eth_abi/_grammar.py
RENAMED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import functools
|
|
2
1
|
import re
|
|
3
2
|
from typing import (
|
|
4
3
|
Any,
|
|
5
4
|
Final,
|
|
5
|
+
NewType,
|
|
6
6
|
NoReturn,
|
|
7
7
|
Optional,
|
|
8
8
|
Sequence,
|
|
9
9
|
Tuple,
|
|
10
10
|
TypeVar,
|
|
11
|
+
Union,
|
|
11
12
|
final,
|
|
12
13
|
)
|
|
13
14
|
|
|
14
|
-
from eth_typing import (
|
|
15
|
+
from eth_typing.abi import (
|
|
15
16
|
TypeStr,
|
|
16
17
|
)
|
|
17
|
-
import
|
|
18
|
-
|
|
19
|
-
expressions,
|
|
18
|
+
from mypy_extensions import (
|
|
19
|
+
mypyc_attr,
|
|
20
20
|
)
|
|
21
21
|
from parsimonious.nodes import (
|
|
22
22
|
Node,
|
|
@@ -27,136 +27,29 @@ from typing_extensions import (
|
|
|
27
27
|
|
|
28
28
|
from faster_eth_abi.exceptions import (
|
|
29
29
|
ABITypeError,
|
|
30
|
-
ParseError,
|
|
31
30
|
)
|
|
32
31
|
|
|
33
|
-
grammar: Final = parsimonious.Grammar(
|
|
34
|
-
r"""
|
|
35
|
-
type = tuple_type / basic_type
|
|
36
32
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
base = alphas
|
|
46
|
-
|
|
47
|
-
sub = two_size / digits
|
|
48
|
-
two_size = (digits "x" digits)
|
|
49
|
-
|
|
50
|
-
arrlist = (const_arr / dynam_arr)+
|
|
51
|
-
const_arr = "[" digits "]"
|
|
52
|
-
dynam_arr = "[]"
|
|
33
|
+
TYPE_ALIASES: Final = {
|
|
34
|
+
"int": "int256",
|
|
35
|
+
"uint": "uint256",
|
|
36
|
+
"fixed": "fixed128x18",
|
|
37
|
+
"ufixed": "ufixed128x18",
|
|
38
|
+
"function": "bytes24",
|
|
39
|
+
"byte": "bytes1",
|
|
40
|
+
}
|
|
53
41
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
"""
|
|
42
|
+
TYPE_ALIAS_RE: Final = re.compile(
|
|
43
|
+
rf"\b({'|'.join(map(re.escape, TYPE_ALIASES.keys()))})\b"
|
|
57
44
|
)
|
|
58
45
|
|
|
59
46
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
Parsimonious node visitor which performs both parsing of type strings and
|
|
64
|
-
post-processing of parse trees. Parsing operations are cached.
|
|
65
|
-
"""
|
|
66
|
-
|
|
67
|
-
def __init__(self):
|
|
68
|
-
self.parse = functools.lru_cache(maxsize=None)(self._parse_uncached)
|
|
69
|
-
|
|
70
|
-
grammar = grammar
|
|
71
|
-
|
|
72
|
-
def visit_non_zero_tuple(self, node, visited_children):
|
|
73
|
-
# Ignore left and right parens
|
|
74
|
-
_, first, rest, _ = visited_children
|
|
75
|
-
|
|
76
|
-
return (first,) + rest
|
|
77
|
-
|
|
78
|
-
def visit_tuple_type(self, node, visited_children):
|
|
79
|
-
components, arrlist = visited_children
|
|
80
|
-
|
|
81
|
-
return TupleType(components, arrlist, node=node)
|
|
82
|
-
|
|
83
|
-
def visit_next_type(self, node, visited_children):
|
|
84
|
-
# Ignore comma
|
|
85
|
-
_, abi_type = visited_children
|
|
86
|
-
|
|
87
|
-
return abi_type
|
|
88
|
-
|
|
89
|
-
def visit_basic_type(self, node, visited_children):
|
|
90
|
-
base, sub, arrlist = visited_children
|
|
91
|
-
|
|
92
|
-
return BasicType(base, sub, arrlist, node=node)
|
|
93
|
-
|
|
94
|
-
def visit_two_size(self, node, visited_children):
|
|
95
|
-
# Ignore "x"
|
|
96
|
-
first, _, second = visited_children
|
|
97
|
-
|
|
98
|
-
return first, second
|
|
99
|
-
|
|
100
|
-
def visit_const_arr(self, node, visited_children):
|
|
101
|
-
# Ignore left and right brackets
|
|
102
|
-
_, int_value, _ = visited_children
|
|
103
|
-
|
|
104
|
-
return (int_value,)
|
|
105
|
-
|
|
106
|
-
def visit_dynam_arr(self, node, visited_children):
|
|
107
|
-
return ()
|
|
108
|
-
|
|
109
|
-
def visit_alphas(self, node, visited_children):
|
|
110
|
-
return node.text
|
|
111
|
-
|
|
112
|
-
def visit_digits(self, node, visited_children):
|
|
113
|
-
return int(node.text)
|
|
114
|
-
|
|
115
|
-
def generic_visit(self, node, visited_children):
|
|
116
|
-
expr = node.expr
|
|
117
|
-
if isinstance(expr, expressions.OneOf):
|
|
118
|
-
# Unwrap value chosen from alternatives
|
|
119
|
-
return visited_children[0]
|
|
120
|
-
|
|
121
|
-
if isinstance(expr, expressions.Quantifier) and expr.min == 0 and expr.max == 1:
|
|
122
|
-
# Unwrap optional value or return `None`
|
|
123
|
-
if len(visited_children) != 0:
|
|
124
|
-
return visited_children[0]
|
|
125
|
-
|
|
126
|
-
return None
|
|
127
|
-
|
|
128
|
-
return tuple(visited_children)
|
|
129
|
-
|
|
130
|
-
def _parse_uncached(self, type_str, **kwargs):
|
|
131
|
-
"""
|
|
132
|
-
Parses a type string into an appropriate instance of
|
|
133
|
-
:class:`~faster_eth_abi.grammar.ABIType`. If a type string cannot be parsed,
|
|
134
|
-
throws :class:`~faster_eth_abi.exceptions.ParseError`.
|
|
135
|
-
|
|
136
|
-
:param type_str: The type string to be parsed.
|
|
137
|
-
:returns: An instance of :class:`~faster_eth_abi.grammar.ABIType` containing
|
|
138
|
-
information about the parsed type string.
|
|
139
|
-
"""
|
|
140
|
-
if not isinstance(type_str, str):
|
|
141
|
-
raise TypeError(f"Can only parse string values: got {type(type_str)}")
|
|
142
|
-
|
|
143
|
-
try:
|
|
144
|
-
return super().parse(type_str, **kwargs)
|
|
145
|
-
except parsimonious.ParseError as e:
|
|
146
|
-
# This is a good place to add some better messaging around the type string.
|
|
147
|
-
# If this logic grows any bigger, we should abstract it to its own function.
|
|
148
|
-
if "()" in type_str:
|
|
149
|
-
# validate against zero-sized tuple types
|
|
150
|
-
raise ValueError(
|
|
151
|
-
'Zero-sized tuple types "()" are not supported.'
|
|
152
|
-
) from None
|
|
153
|
-
|
|
154
|
-
raise ParseError(e.text, e.pos, e.expr) from e
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
visitor: Final = NodeVisitor()
|
|
47
|
+
IntSubtype = NewType("IntSubtype", int)
|
|
48
|
+
FixedSubtype = NewType("FixedSubtype", Tuple[int, int])
|
|
49
|
+
Subtype = Union[IntSubtype, FixedSubtype]
|
|
158
50
|
|
|
159
51
|
|
|
52
|
+
@mypyc_attr(allow_interpreted_subclasses=True)
|
|
160
53
|
class ABIType:
|
|
161
54
|
"""
|
|
162
55
|
Base class for results of type string parsing operations.
|
|
@@ -165,7 +58,7 @@ class ABIType:
|
|
|
165
58
|
__slots__ = ("arrlist", "node")
|
|
166
59
|
|
|
167
60
|
def __init__(
|
|
168
|
-
self, arrlist: Optional[Sequence] = None, node: Optional[Node] = None
|
|
61
|
+
self, arrlist: Optional[Sequence[str]] = None, node: Optional[Node] = None
|
|
169
62
|
) -> None:
|
|
170
63
|
self.arrlist: Final = arrlist
|
|
171
64
|
"""
|
|
@@ -211,6 +104,7 @@ class ABIType:
|
|
|
211
104
|
"""
|
|
212
105
|
raise NotImplementedError("Must implement `validate`")
|
|
213
106
|
|
|
107
|
+
@final
|
|
214
108
|
def invalidate(self, error_msg: str) -> NoReturn:
|
|
215
109
|
# Invalidates an ABI type with the given error message. Expects that a
|
|
216
110
|
# parsimonious node was provided from the original parsing operation
|
|
@@ -222,6 +116,7 @@ class ABIType:
|
|
|
222
116
|
f"in '{node.full_text}': {error_msg}"
|
|
223
117
|
)
|
|
224
118
|
|
|
119
|
+
@final
|
|
225
120
|
@property
|
|
226
121
|
def is_array(self) -> bool:
|
|
227
122
|
"""
|
|
@@ -238,6 +133,7 @@ class ABIType:
|
|
|
238
133
|
"""
|
|
239
134
|
raise NotImplementedError("Must implement `is_dynamic`")
|
|
240
135
|
|
|
136
|
+
@final
|
|
241
137
|
@property
|
|
242
138
|
def _has_dynamic_arrlist(self) -> bool:
|
|
243
139
|
return self.is_array and any(len(dim) == 0 for dim in self.arrlist)
|
|
@@ -246,7 +142,7 @@ class ABIType:
|
|
|
246
142
|
TComp = TypeVar("TComp", bound=ABIType)
|
|
247
143
|
|
|
248
144
|
|
|
249
|
-
@
|
|
145
|
+
@mypyc_attr(allow_interpreted_subclasses=True)
|
|
250
146
|
class TupleType(ABIType):
|
|
251
147
|
"""
|
|
252
148
|
Represents the result of parsing a tuple type string e.g. "(int,bool)".
|
|
@@ -257,7 +153,7 @@ class TupleType(ABIType):
|
|
|
257
153
|
def __init__(
|
|
258
154
|
self,
|
|
259
155
|
components: Tuple[TComp, ...],
|
|
260
|
-
arrlist: Optional[Sequence] = None,
|
|
156
|
+
arrlist: Optional[Sequence[str]] = None,
|
|
261
157
|
*,
|
|
262
158
|
node: Optional[Node] = None,
|
|
263
159
|
) -> None:
|
|
@@ -273,7 +169,7 @@ class TupleType(ABIType):
|
|
|
273
169
|
arrlist = self.arrlist
|
|
274
170
|
|
|
275
171
|
if isinstance(arrlist, tuple):
|
|
276
|
-
arrlist = "".join(repr(list
|
|
172
|
+
arrlist = "".join(map(repr, map(list, arrlist)))
|
|
277
173
|
else:
|
|
278
174
|
arrlist = ""
|
|
279
175
|
|
|
@@ -286,11 +182,12 @@ class TupleType(ABIType):
|
|
|
286
182
|
f"Cannot determine item type for non-array type '{self.to_type_str()}'"
|
|
287
183
|
)
|
|
288
184
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
node=self.node
|
|
293
|
-
|
|
185
|
+
arrlist = self.arrlist[:-1] or None # type: ignore [index]
|
|
186
|
+
cls = type(self)
|
|
187
|
+
if cls is TupleType:
|
|
188
|
+
return TupleType(self.components, arrlist, node=self.node) # type: ignore [return-value]
|
|
189
|
+
else:
|
|
190
|
+
return cls(self.components, arrlist, node=self.node)
|
|
294
191
|
|
|
295
192
|
def validate(self) -> None:
|
|
296
193
|
for c in self.components:
|
|
@@ -304,7 +201,7 @@ class TupleType(ABIType):
|
|
|
304
201
|
return any(c.is_dynamic for c in self.components)
|
|
305
202
|
|
|
306
203
|
|
|
307
|
-
@
|
|
204
|
+
@mypyc_attr(allow_interpreted_subclasses=True)
|
|
308
205
|
class BasicType(ABIType):
|
|
309
206
|
"""
|
|
310
207
|
Represents the result of parsing a basic type string e.g. "uint", "address",
|
|
@@ -316,7 +213,7 @@ class BasicType(ABIType):
|
|
|
316
213
|
def __init__(
|
|
317
214
|
self,
|
|
318
215
|
base: str,
|
|
319
|
-
sub:
|
|
216
|
+
sub: Optional[Subtype] = None,
|
|
320
217
|
arrlist: Optional[Sequence] = None,
|
|
321
218
|
*,
|
|
322
219
|
node: Optional[Node] = None,
|
|
@@ -339,12 +236,12 @@ class BasicType(ABIType):
|
|
|
339
236
|
if isinstance(sub, int):
|
|
340
237
|
substr = str(sub)
|
|
341
238
|
elif isinstance(sub, tuple):
|
|
342
|
-
substr = "x".join(str
|
|
239
|
+
substr = "x".join(map(str, sub))
|
|
343
240
|
else:
|
|
344
241
|
substr = ""
|
|
345
242
|
|
|
346
243
|
if isinstance(arrlist, tuple):
|
|
347
|
-
return self.base + substr + "".join(repr(list
|
|
244
|
+
return self.base + substr + "".join(map(repr, map(list, arrlist)))
|
|
348
245
|
else:
|
|
349
246
|
return self.base + substr
|
|
350
247
|
|
|
@@ -355,22 +252,23 @@ class BasicType(ABIType):
|
|
|
355
252
|
f"Cannot determine item type for non-array type '{self.to_type_str()}'"
|
|
356
253
|
)
|
|
357
254
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
self.
|
|
362
|
-
|
|
363
|
-
|
|
255
|
+
cls = type(self)
|
|
256
|
+
arrlist = self.arrlist[:-1] or None # type: ignore [index]
|
|
257
|
+
if cls is BasicType:
|
|
258
|
+
return BasicType(self.base, self.sub, arrlist, node=self.node) # type: ignore [return-value]
|
|
259
|
+
else:
|
|
260
|
+
return cls(self.base, self.sub, arrlist, node=self.node)
|
|
364
261
|
|
|
365
262
|
@property
|
|
366
263
|
def is_dynamic(self) -> bool:
|
|
367
264
|
if self._has_dynamic_arrlist:
|
|
368
265
|
return True
|
|
369
266
|
|
|
370
|
-
|
|
267
|
+
base = self.base
|
|
268
|
+
if base == "string":
|
|
371
269
|
return True
|
|
372
270
|
|
|
373
|
-
if
|
|
271
|
+
if base == "bytes" and self.sub is None:
|
|
374
272
|
return True
|
|
375
273
|
|
|
376
274
|
return False
|
|
@@ -436,20 +334,6 @@ class BasicType(ABIType):
|
|
|
436
334
|
self.invalidate("address cannot have suffix")
|
|
437
335
|
|
|
438
336
|
|
|
439
|
-
TYPE_ALIASES: Final = {
|
|
440
|
-
"int": "int256",
|
|
441
|
-
"uint": "uint256",
|
|
442
|
-
"fixed": "fixed128x18",
|
|
443
|
-
"ufixed": "ufixed128x18",
|
|
444
|
-
"function": "bytes24",
|
|
445
|
-
"byte": "bytes1",
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
TYPE_ALIAS_RE: Final = re.compile(
|
|
449
|
-
rf"\b({'|'.join(re.escape(a) for a in TYPE_ALIASES.keys())})\b"
|
|
450
|
-
)
|
|
451
|
-
|
|
452
|
-
|
|
453
337
|
def normalize(type_str: TypeStr) -> TypeStr:
|
|
454
338
|
"""
|
|
455
339
|
Normalizes a type string into its canonical version e.g. the type string
|
|
@@ -463,6 +347,3 @@ def normalize(type_str: TypeStr) -> TypeStr:
|
|
|
463
347
|
|
|
464
348
|
def __normalize(match: "re.Match[str]") -> str:
|
|
465
349
|
return TYPE_ALIASES[match.group(0)]
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
parse: Final = visitor.parse
|
|
@@ -18,6 +18,7 @@ from faster_eth_abi.decoding import (
|
|
|
18
18
|
)
|
|
19
19
|
from faster_eth_abi.exceptions import (
|
|
20
20
|
EncodingError,
|
|
21
|
+
MultipleEntriesFound,
|
|
21
22
|
)
|
|
22
23
|
from faster_eth_abi.registry import (
|
|
23
24
|
ABIRegistry,
|
|
@@ -74,20 +75,18 @@ class ABIEncoder(BaseABICoder):
|
|
|
74
75
|
:returns: ``True`` if ``arg`` is encodable as a value of the ABI type
|
|
75
76
|
``typ``. Otherwise, ``False``.
|
|
76
77
|
"""
|
|
77
|
-
|
|
78
|
+
try:
|
|
79
|
+
encoder = self._registry.get_encoder(typ)
|
|
80
|
+
except MultipleEntriesFound:
|
|
81
|
+
raise
|
|
82
|
+
except:
|
|
78
83
|
return False
|
|
79
84
|
|
|
80
|
-
|
|
81
|
-
|
|
85
|
+
validate = getattr(encoder, "validate_value", encoder)
|
|
82
86
|
try:
|
|
83
|
-
|
|
87
|
+
validate(arg)
|
|
84
88
|
except EncodingError:
|
|
85
89
|
return False
|
|
86
|
-
except AttributeError:
|
|
87
|
-
try:
|
|
88
|
-
encoder(arg)
|
|
89
|
-
except EncodingError:
|
|
90
|
-
return False
|
|
91
90
|
|
|
92
91
|
return True
|
|
93
92
|
|
|
@@ -1,20 +1,29 @@
|
|
|
1
|
+
# mypy: disable-error-code="misc"
|
|
2
|
+
# cannot subclass `Any`
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
faster-eth-abi exceptions always inherit from eth-abi exceptions, so porting to faster-eth-abi
|
|
6
|
+
does not require any change to your existing exception handlers. They will continue to work.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import eth_abi.exceptions
|
|
1
10
|
import parsimonious
|
|
2
11
|
|
|
3
12
|
|
|
4
|
-
class EncodingError(
|
|
13
|
+
class EncodingError(eth_abi.exceptions.EncodingError):
|
|
5
14
|
"""
|
|
6
15
|
Base exception for any error that occurs during encoding.
|
|
7
16
|
"""
|
|
8
17
|
|
|
9
18
|
|
|
10
|
-
class EncodingTypeError(EncodingError):
|
|
19
|
+
class EncodingTypeError(EncodingError, eth_abi.exceptions.EncodingTypeError):
|
|
11
20
|
"""
|
|
12
21
|
Raised when trying to encode a python value whose type is not supported for
|
|
13
22
|
the output ABI type.
|
|
14
23
|
"""
|
|
15
24
|
|
|
16
25
|
|
|
17
|
-
class IllegalValue(EncodingError):
|
|
26
|
+
class IllegalValue(EncodingError, eth_abi.exceptions.IllegalValue):
|
|
18
27
|
"""
|
|
19
28
|
Raised when trying to encode a python value with the correct type but with
|
|
20
29
|
a value that is not considered legal for the output ABI type.
|
|
@@ -26,7 +35,7 @@ class IllegalValue(EncodingError):
|
|
|
26
35
|
"""
|
|
27
36
|
|
|
28
37
|
|
|
29
|
-
class ValueOutOfBounds(IllegalValue):
|
|
38
|
+
class ValueOutOfBounds(IllegalValue, eth_abi.exceptions.ValueOutOfBounds):
|
|
30
39
|
"""
|
|
31
40
|
Raised when trying to encode a python value with the correct type but with
|
|
32
41
|
a value that appears outside the range of valid values for the output ABI
|
|
@@ -39,31 +48,31 @@ class ValueOutOfBounds(IllegalValue):
|
|
|
39
48
|
"""
|
|
40
49
|
|
|
41
50
|
|
|
42
|
-
class DecodingError(
|
|
51
|
+
class DecodingError(eth_abi.exceptions.DecodingError):
|
|
43
52
|
"""
|
|
44
53
|
Base exception for any error that occurs during decoding.
|
|
45
54
|
"""
|
|
46
55
|
|
|
47
56
|
|
|
48
|
-
class InsufficientDataBytes(DecodingError):
|
|
57
|
+
class InsufficientDataBytes(DecodingError, eth_abi.exceptions.InsufficientDataBytes):
|
|
49
58
|
"""
|
|
50
59
|
Raised when there are insufficient data to decode a value for a given ABI type.
|
|
51
60
|
"""
|
|
52
61
|
|
|
53
62
|
|
|
54
|
-
class NonEmptyPaddingBytes(DecodingError):
|
|
63
|
+
class NonEmptyPaddingBytes(DecodingError, eth_abi.exceptions.NonEmptyPaddingBytes):
|
|
55
64
|
"""
|
|
56
65
|
Raised when the padding bytes of an ABI value are malformed.
|
|
57
66
|
"""
|
|
58
67
|
|
|
59
68
|
|
|
60
|
-
class InvalidPointer(DecodingError):
|
|
69
|
+
class InvalidPointer(DecodingError, eth_abi.exceptions.InvalidPointer):
|
|
61
70
|
"""
|
|
62
71
|
Raised when the pointer to a value in the ABI encoding is invalid.
|
|
63
72
|
"""
|
|
64
73
|
|
|
65
74
|
|
|
66
|
-
class ParseError(
|
|
75
|
+
class ParseError(eth_abi.exceptions.ParseError):
|
|
67
76
|
"""
|
|
68
77
|
Raised when an ABI type string cannot be parsed.
|
|
69
78
|
"""
|
|
@@ -75,7 +84,7 @@ class ParseError(parsimonious.ParseError): # type: ignore[misc] # subclasses An
|
|
|
75
84
|
)
|
|
76
85
|
|
|
77
86
|
|
|
78
|
-
class ABITypeError(
|
|
87
|
+
class ABITypeError(eth_abi.exceptions.ABITypeError):
|
|
79
88
|
"""
|
|
80
89
|
Raised when a parsed ABI type has inconsistent properties; for example,
|
|
81
90
|
when trying to parse the type string ``'uint7'`` (which has a bit-width
|
|
@@ -83,13 +92,13 @@ class ABITypeError(ValueError):
|
|
|
83
92
|
"""
|
|
84
93
|
|
|
85
94
|
|
|
86
|
-
class PredicateMappingError(
|
|
95
|
+
class PredicateMappingError(eth_abi.exceptions.PredicateMappingError):
|
|
87
96
|
"""
|
|
88
97
|
Raised when an error occurs in a registry's internal mapping.
|
|
89
98
|
"""
|
|
90
99
|
|
|
91
100
|
|
|
92
|
-
class NoEntriesFound(
|
|
101
|
+
class NoEntriesFound(PredicateMappingError, eth_abi.exceptions.NoEntriesFound):
|
|
93
102
|
"""
|
|
94
103
|
Raised when no registration is found for a type string in a registry's
|
|
95
104
|
internal mapping.
|
|
@@ -101,7 +110,7 @@ class NoEntriesFound(ValueError, PredicateMappingError):
|
|
|
101
110
|
"""
|
|
102
111
|
|
|
103
112
|
|
|
104
|
-
class MultipleEntriesFound(
|
|
113
|
+
class MultipleEntriesFound(PredicateMappingError, eth_abi.exceptions.MultipleEntriesFound):
|
|
105
114
|
"""
|
|
106
115
|
Raised when multiple registrations are found for a type string in a
|
|
107
116
|
registry's internal mapping. This error is non-recoverable and indicates
|