coinex-api 0.0.14__py3-none-any.whl → 0.0.15__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.
- {coinex_api-0.0.14.dist-info → coinex_api-0.0.15.dist-info}/METADATA +1 -1
- coinex_api-0.0.15.dist-info/RECORD +3 -0
- coinex/__init__.py +0 -7
- coinex/ccxt/__init__.py +0 -101
- coinex/ccxt/abstract/coinex.py +0 -237
- coinex/ccxt/async_support/__init__.py +0 -80
- coinex/ccxt/async_support/base/__init__.py +0 -1
- coinex/ccxt/async_support/base/exchange.py +0 -2100
- coinex/ccxt/async_support/base/throttler.py +0 -50
- coinex/ccxt/async_support/base/ws/__init__.py +0 -38
- coinex/ccxt/async_support/base/ws/aiohttp_client.py +0 -147
- coinex/ccxt/async_support/base/ws/cache.py +0 -213
- coinex/ccxt/async_support/base/ws/client.py +0 -214
- coinex/ccxt/async_support/base/ws/fast_client.py +0 -97
- coinex/ccxt/async_support/base/ws/functions.py +0 -59
- coinex/ccxt/async_support/base/ws/future.py +0 -69
- coinex/ccxt/async_support/base/ws/order_book.py +0 -78
- coinex/ccxt/async_support/base/ws/order_book_side.py +0 -174
- coinex/ccxt/async_support/coinex.py +0 -5833
- coinex/ccxt/base/__init__.py +0 -27
- coinex/ccxt/base/decimal_to_precision.py +0 -174
- coinex/ccxt/base/errors.py +0 -267
- coinex/ccxt/base/exchange.py +0 -6769
- coinex/ccxt/base/precise.py +0 -297
- coinex/ccxt/base/types.py +0 -577
- coinex/ccxt/coinex.py +0 -5832
- coinex/ccxt/pro/__init__.py +0 -21
- coinex/ccxt/pro/coinex.py +0 -1366
- coinex/ccxt/static_dependencies/README.md +0 -1
- coinex/ccxt/static_dependencies/__init__.py +0 -1
- coinex/ccxt/static_dependencies/ecdsa/__init__.py +0 -14
- coinex/ccxt/static_dependencies/ecdsa/_version.py +0 -520
- coinex/ccxt/static_dependencies/ecdsa/curves.py +0 -56
- coinex/ccxt/static_dependencies/ecdsa/der.py +0 -221
- coinex/ccxt/static_dependencies/ecdsa/ecdsa.py +0 -310
- coinex/ccxt/static_dependencies/ecdsa/ellipticcurve.py +0 -197
- coinex/ccxt/static_dependencies/ecdsa/keys.py +0 -332
- coinex/ccxt/static_dependencies/ecdsa/numbertheory.py +0 -531
- coinex/ccxt/static_dependencies/ecdsa/rfc6979.py +0 -100
- coinex/ccxt/static_dependencies/ecdsa/util.py +0 -266
- coinex/ccxt/static_dependencies/ethereum/__init__.py +0 -7
- coinex/ccxt/static_dependencies/ethereum/abi/__init__.py +0 -16
- coinex/ccxt/static_dependencies/ethereum/abi/abi.py +0 -19
- coinex/ccxt/static_dependencies/ethereum/abi/base.py +0 -152
- coinex/ccxt/static_dependencies/ethereum/abi/codec.py +0 -217
- coinex/ccxt/static_dependencies/ethereum/abi/constants.py +0 -3
- coinex/ccxt/static_dependencies/ethereum/abi/decoding.py +0 -565
- coinex/ccxt/static_dependencies/ethereum/abi/encoding.py +0 -720
- coinex/ccxt/static_dependencies/ethereum/abi/exceptions.py +0 -139
- coinex/ccxt/static_dependencies/ethereum/abi/grammar.py +0 -443
- coinex/ccxt/static_dependencies/ethereum/abi/packed.py +0 -13
- coinex/ccxt/static_dependencies/ethereum/abi/py.typed +0 -0
- coinex/ccxt/static_dependencies/ethereum/abi/registry.py +0 -643
- coinex/ccxt/static_dependencies/ethereum/abi/tools/__init__.py +0 -3
- coinex/ccxt/static_dependencies/ethereum/abi/tools/_strategies.py +0 -230
- coinex/ccxt/static_dependencies/ethereum/abi/utils/__init__.py +0 -0
- coinex/ccxt/static_dependencies/ethereum/abi/utils/numeric.py +0 -83
- coinex/ccxt/static_dependencies/ethereum/abi/utils/padding.py +0 -27
- coinex/ccxt/static_dependencies/ethereum/abi/utils/string.py +0 -19
- coinex/ccxt/static_dependencies/ethereum/account/__init__.py +0 -3
- coinex/ccxt/static_dependencies/ethereum/account/encode_typed_data/__init__.py +0 -4
- coinex/ccxt/static_dependencies/ethereum/account/encode_typed_data/encoding_and_hashing.py +0 -239
- coinex/ccxt/static_dependencies/ethereum/account/encode_typed_data/helpers.py +0 -40
- coinex/ccxt/static_dependencies/ethereum/account/messages.py +0 -263
- coinex/ccxt/static_dependencies/ethereum/account/py.typed +0 -0
- coinex/ccxt/static_dependencies/ethereum/hexbytes/__init__.py +0 -5
- coinex/ccxt/static_dependencies/ethereum/hexbytes/_utils.py +0 -54
- coinex/ccxt/static_dependencies/ethereum/hexbytes/main.py +0 -65
- coinex/ccxt/static_dependencies/ethereum/hexbytes/py.typed +0 -0
- coinex/ccxt/static_dependencies/ethereum/typing/__init__.py +0 -63
- coinex/ccxt/static_dependencies/ethereum/typing/abi.py +0 -6
- coinex/ccxt/static_dependencies/ethereum/typing/bls.py +0 -7
- coinex/ccxt/static_dependencies/ethereum/typing/discovery.py +0 -5
- coinex/ccxt/static_dependencies/ethereum/typing/encoding.py +0 -7
- coinex/ccxt/static_dependencies/ethereum/typing/enums.py +0 -17
- coinex/ccxt/static_dependencies/ethereum/typing/ethpm.py +0 -9
- coinex/ccxt/static_dependencies/ethereum/typing/evm.py +0 -20
- coinex/ccxt/static_dependencies/ethereum/typing/networks.py +0 -1122
- coinex/ccxt/static_dependencies/ethereum/typing/py.typed +0 -0
- coinex/ccxt/static_dependencies/ethereum/utils/__init__.py +0 -115
- coinex/ccxt/static_dependencies/ethereum/utils/abi.py +0 -72
- coinex/ccxt/static_dependencies/ethereum/utils/address.py +0 -171
- coinex/ccxt/static_dependencies/ethereum/utils/applicators.py +0 -151
- coinex/ccxt/static_dependencies/ethereum/utils/conversions.py +0 -190
- coinex/ccxt/static_dependencies/ethereum/utils/currency.py +0 -107
- coinex/ccxt/static_dependencies/ethereum/utils/curried/__init__.py +0 -269
- coinex/ccxt/static_dependencies/ethereum/utils/debug.py +0 -20
- coinex/ccxt/static_dependencies/ethereum/utils/decorators.py +0 -132
- coinex/ccxt/static_dependencies/ethereum/utils/encoding.py +0 -6
- coinex/ccxt/static_dependencies/ethereum/utils/exceptions.py +0 -4
- coinex/ccxt/static_dependencies/ethereum/utils/functional.py +0 -75
- coinex/ccxt/static_dependencies/ethereum/utils/hexadecimal.py +0 -74
- coinex/ccxt/static_dependencies/ethereum/utils/humanize.py +0 -188
- coinex/ccxt/static_dependencies/ethereum/utils/logging.py +0 -159
- coinex/ccxt/static_dependencies/ethereum/utils/module_loading.py +0 -31
- coinex/ccxt/static_dependencies/ethereum/utils/numeric.py +0 -43
- coinex/ccxt/static_dependencies/ethereum/utils/py.typed +0 -0
- coinex/ccxt/static_dependencies/ethereum/utils/toolz.py +0 -76
- coinex/ccxt/static_dependencies/ethereum/utils/types.py +0 -54
- coinex/ccxt/static_dependencies/ethereum/utils/typing/__init__.py +0 -18
- coinex/ccxt/static_dependencies/ethereum/utils/typing/misc.py +0 -14
- coinex/ccxt/static_dependencies/ethereum/utils/units.py +0 -31
- coinex/ccxt/static_dependencies/keccak/__init__.py +0 -3
- coinex/ccxt/static_dependencies/keccak/keccak.py +0 -197
- coinex/ccxt/static_dependencies/lark/__init__.py +0 -38
- coinex/ccxt/static_dependencies/lark/__pyinstaller/__init__.py +0 -6
- coinex/ccxt/static_dependencies/lark/__pyinstaller/hook-lark.py +0 -14
- coinex/ccxt/static_dependencies/lark/ast_utils.py +0 -59
- coinex/ccxt/static_dependencies/lark/common.py +0 -86
- coinex/ccxt/static_dependencies/lark/exceptions.py +0 -292
- coinex/ccxt/static_dependencies/lark/grammar.py +0 -130
- coinex/ccxt/static_dependencies/lark/grammars/__init__.py +0 -0
- coinex/ccxt/static_dependencies/lark/grammars/common.lark +0 -59
- coinex/ccxt/static_dependencies/lark/grammars/lark.lark +0 -62
- coinex/ccxt/static_dependencies/lark/grammars/python.lark +0 -302
- coinex/ccxt/static_dependencies/lark/grammars/unicode.lark +0 -7
- coinex/ccxt/static_dependencies/lark/indenter.py +0 -143
- coinex/ccxt/static_dependencies/lark/lark.py +0 -658
- coinex/ccxt/static_dependencies/lark/lexer.py +0 -678
- coinex/ccxt/static_dependencies/lark/load_grammar.py +0 -1428
- coinex/ccxt/static_dependencies/lark/parse_tree_builder.py +0 -391
- coinex/ccxt/static_dependencies/lark/parser_frontends.py +0 -257
- coinex/ccxt/static_dependencies/lark/parsers/__init__.py +0 -0
- coinex/ccxt/static_dependencies/lark/parsers/cyk.py +0 -340
- coinex/ccxt/static_dependencies/lark/parsers/earley.py +0 -314
- coinex/ccxt/static_dependencies/lark/parsers/earley_common.py +0 -42
- coinex/ccxt/static_dependencies/lark/parsers/earley_forest.py +0 -801
- coinex/ccxt/static_dependencies/lark/parsers/grammar_analysis.py +0 -203
- coinex/ccxt/static_dependencies/lark/parsers/lalr_analysis.py +0 -332
- coinex/ccxt/static_dependencies/lark/parsers/lalr_interactive_parser.py +0 -158
- coinex/ccxt/static_dependencies/lark/parsers/lalr_parser.py +0 -122
- coinex/ccxt/static_dependencies/lark/parsers/lalr_parser_state.py +0 -110
- coinex/ccxt/static_dependencies/lark/parsers/xearley.py +0 -165
- coinex/ccxt/static_dependencies/lark/py.typed +0 -0
- coinex/ccxt/static_dependencies/lark/reconstruct.py +0 -107
- coinex/ccxt/static_dependencies/lark/tools/__init__.py +0 -70
- coinex/ccxt/static_dependencies/lark/tools/nearley.py +0 -202
- coinex/ccxt/static_dependencies/lark/tools/serialize.py +0 -32
- coinex/ccxt/static_dependencies/lark/tools/standalone.py +0 -196
- coinex/ccxt/static_dependencies/lark/tree.py +0 -267
- coinex/ccxt/static_dependencies/lark/tree_matcher.py +0 -186
- coinex/ccxt/static_dependencies/lark/tree_templates.py +0 -180
- coinex/ccxt/static_dependencies/lark/utils.py +0 -343
- coinex/ccxt/static_dependencies/lark/visitors.py +0 -596
- coinex/ccxt/static_dependencies/marshmallow/__init__.py +0 -81
- coinex/ccxt/static_dependencies/marshmallow/base.py +0 -65
- coinex/ccxt/static_dependencies/marshmallow/class_registry.py +0 -94
- coinex/ccxt/static_dependencies/marshmallow/decorators.py +0 -231
- coinex/ccxt/static_dependencies/marshmallow/error_store.py +0 -60
- coinex/ccxt/static_dependencies/marshmallow/exceptions.py +0 -71
- coinex/ccxt/static_dependencies/marshmallow/fields.py +0 -2114
- coinex/ccxt/static_dependencies/marshmallow/orderedset.py +0 -89
- coinex/ccxt/static_dependencies/marshmallow/py.typed +0 -0
- coinex/ccxt/static_dependencies/marshmallow/schema.py +0 -1228
- coinex/ccxt/static_dependencies/marshmallow/types.py +0 -12
- coinex/ccxt/static_dependencies/marshmallow/utils.py +0 -378
- coinex/ccxt/static_dependencies/marshmallow/validate.py +0 -678
- coinex/ccxt/static_dependencies/marshmallow/warnings.py +0 -2
- coinex/ccxt/static_dependencies/marshmallow_dataclass/__init__.py +0 -1047
- coinex/ccxt/static_dependencies/marshmallow_dataclass/collection_field.py +0 -51
- coinex/ccxt/static_dependencies/marshmallow_dataclass/lazy_class_attribute.py +0 -45
- coinex/ccxt/static_dependencies/marshmallow_dataclass/mypy.py +0 -71
- coinex/ccxt/static_dependencies/marshmallow_dataclass/py.typed +0 -0
- coinex/ccxt/static_dependencies/marshmallow_dataclass/typing.py +0 -14
- coinex/ccxt/static_dependencies/marshmallow_dataclass/union_field.py +0 -82
- coinex/ccxt/static_dependencies/marshmallow_oneofschema/__init__.py +0 -1
- coinex/ccxt/static_dependencies/marshmallow_oneofschema/one_of_schema.py +0 -193
- coinex/ccxt/static_dependencies/marshmallow_oneofschema/py.typed +0 -0
- coinex/ccxt/static_dependencies/msgpack/__init__.py +0 -55
- coinex/ccxt/static_dependencies/msgpack/_cmsgpack.pyx +0 -11
- coinex/ccxt/static_dependencies/msgpack/_packer.pyx +0 -374
- coinex/ccxt/static_dependencies/msgpack/_unpacker.pyx +0 -547
- coinex/ccxt/static_dependencies/msgpack/buff_converter.h +0 -8
- coinex/ccxt/static_dependencies/msgpack/exceptions.py +0 -48
- coinex/ccxt/static_dependencies/msgpack/ext.py +0 -168
- coinex/ccxt/static_dependencies/msgpack/fallback.py +0 -951
- coinex/ccxt/static_dependencies/msgpack/pack.h +0 -89
- coinex/ccxt/static_dependencies/msgpack/pack_template.h +0 -820
- coinex/ccxt/static_dependencies/msgpack/sysdep.h +0 -194
- coinex/ccxt/static_dependencies/msgpack/unpack.h +0 -391
- coinex/ccxt/static_dependencies/msgpack/unpack_define.h +0 -95
- coinex/ccxt/static_dependencies/msgpack/unpack_template.h +0 -464
- coinex/ccxt/static_dependencies/parsimonious/__init__.py +0 -10
- coinex/ccxt/static_dependencies/parsimonious/exceptions.py +0 -105
- coinex/ccxt/static_dependencies/parsimonious/expressions.py +0 -479
- coinex/ccxt/static_dependencies/parsimonious/grammar.py +0 -487
- coinex/ccxt/static_dependencies/parsimonious/nodes.py +0 -325
- coinex/ccxt/static_dependencies/parsimonious/utils.py +0 -40
- coinex/ccxt/static_dependencies/starknet/__init__.py +0 -0
- coinex/ccxt/static_dependencies/starknet/abi/v0/__init__.py +0 -2
- coinex/ccxt/static_dependencies/starknet/abi/v0/model.py +0 -44
- coinex/ccxt/static_dependencies/starknet/abi/v0/parser.py +0 -216
- coinex/ccxt/static_dependencies/starknet/abi/v0/schemas.py +0 -72
- coinex/ccxt/static_dependencies/starknet/abi/v0/shape.py +0 -63
- coinex/ccxt/static_dependencies/starknet/abi/v1/__init__.py +0 -2
- coinex/ccxt/static_dependencies/starknet/abi/v1/core_structures.json +0 -14
- coinex/ccxt/static_dependencies/starknet/abi/v1/model.py +0 -39
- coinex/ccxt/static_dependencies/starknet/abi/v1/parser.py +0 -220
- coinex/ccxt/static_dependencies/starknet/abi/v1/parser_transformer.py +0 -179
- coinex/ccxt/static_dependencies/starknet/abi/v1/schemas.py +0 -66
- coinex/ccxt/static_dependencies/starknet/abi/v1/shape.py +0 -47
- coinex/ccxt/static_dependencies/starknet/abi/v2/__init__.py +0 -2
- coinex/ccxt/static_dependencies/starknet/abi/v2/model.py +0 -89
- coinex/ccxt/static_dependencies/starknet/abi/v2/parser.py +0 -293
- coinex/ccxt/static_dependencies/starknet/abi/v2/parser_transformer.py +0 -192
- coinex/ccxt/static_dependencies/starknet/abi/v2/schemas.py +0 -132
- coinex/ccxt/static_dependencies/starknet/abi/v2/shape.py +0 -107
- coinex/ccxt/static_dependencies/starknet/cairo/__init__.py +0 -0
- coinex/ccxt/static_dependencies/starknet/cairo/data_types.py +0 -123
- coinex/ccxt/static_dependencies/starknet/cairo/deprecated_parse/__init__.py +0 -0
- coinex/ccxt/static_dependencies/starknet/cairo/deprecated_parse/cairo_types.py +0 -77
- coinex/ccxt/static_dependencies/starknet/cairo/deprecated_parse/parser.py +0 -46
- coinex/ccxt/static_dependencies/starknet/cairo/deprecated_parse/parser_transformer.py +0 -138
- coinex/ccxt/static_dependencies/starknet/cairo/felt.py +0 -64
- coinex/ccxt/static_dependencies/starknet/cairo/type_parser.py +0 -121
- coinex/ccxt/static_dependencies/starknet/cairo/v1/__init__.py +0 -0
- coinex/ccxt/static_dependencies/starknet/cairo/v1/type_parser.py +0 -59
- coinex/ccxt/static_dependencies/starknet/cairo/v2/__init__.py +0 -0
- coinex/ccxt/static_dependencies/starknet/cairo/v2/type_parser.py +0 -77
- coinex/ccxt/static_dependencies/starknet/ccxt_utils.py +0 -7
- coinex/ccxt/static_dependencies/starknet/common.py +0 -15
- coinex/ccxt/static_dependencies/starknet/constants.py +0 -39
- coinex/ccxt/static_dependencies/starknet/hash/__init__.py +0 -0
- coinex/ccxt/static_dependencies/starknet/hash/address.py +0 -79
- coinex/ccxt/static_dependencies/starknet/hash/compiled_class_hash_objects.py +0 -111
- coinex/ccxt/static_dependencies/starknet/hash/selector.py +0 -16
- coinex/ccxt/static_dependencies/starknet/hash/storage.py +0 -12
- coinex/ccxt/static_dependencies/starknet/hash/utils.py +0 -78
- coinex/ccxt/static_dependencies/starknet/models/__init__.py +0 -0
- coinex/ccxt/static_dependencies/starknet/models/typed_data.py +0 -45
- coinex/ccxt/static_dependencies/starknet/serialization/__init__.py +0 -24
- coinex/ccxt/static_dependencies/starknet/serialization/_calldata_reader.py +0 -40
- coinex/ccxt/static_dependencies/starknet/serialization/_context.py +0 -142
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/__init__.py +0 -10
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/_common.py +0 -82
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/array_serializer.py +0 -43
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/bool_serializer.py +0 -37
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/byte_array_serializer.py +0 -66
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/cairo_data_serializer.py +0 -71
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/enum_serializer.py +0 -71
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/felt_serializer.py +0 -50
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/named_tuple_serializer.py +0 -58
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/option_serializer.py +0 -43
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/output_serializer.py +0 -40
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/payload_serializer.py +0 -72
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/struct_serializer.py +0 -36
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/tuple_serializer.py +0 -36
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/uint256_serializer.py +0 -76
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/uint_serializer.py +0 -100
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/unit_serializer.py +0 -32
- coinex/ccxt/static_dependencies/starknet/serialization/errors.py +0 -10
- coinex/ccxt/static_dependencies/starknet/serialization/factory.py +0 -229
- coinex/ccxt/static_dependencies/starknet/serialization/function_serialization_adapter.py +0 -110
- coinex/ccxt/static_dependencies/starknet/serialization/tuple_dataclass.py +0 -59
- coinex/ccxt/static_dependencies/starknet/utils/__init__.py +0 -0
- coinex/ccxt/static_dependencies/starknet/utils/constructor_args_translator.py +0 -86
- coinex/ccxt/static_dependencies/starknet/utils/iterable.py +0 -13
- coinex/ccxt/static_dependencies/starknet/utils/schema.py +0 -13
- coinex/ccxt/static_dependencies/starknet/utils/typed_data.py +0 -182
- coinex/ccxt/static_dependencies/starkware/__init__.py +0 -0
- coinex/ccxt/static_dependencies/starkware/crypto/__init__.py +0 -0
- coinex/ccxt/static_dependencies/starkware/crypto/fast_pedersen_hash.py +0 -50
- coinex/ccxt/static_dependencies/starkware/crypto/math_utils.py +0 -78
- coinex/ccxt/static_dependencies/starkware/crypto/signature.py +0 -2344
- coinex/ccxt/static_dependencies/starkware/crypto/utils.py +0 -63
- coinex/ccxt/static_dependencies/sympy/__init__.py +0 -0
- coinex/ccxt/static_dependencies/sympy/core/__init__.py +0 -0
- coinex/ccxt/static_dependencies/sympy/core/intfunc.py +0 -35
- coinex/ccxt/static_dependencies/sympy/external/__init__.py +0 -0
- coinex/ccxt/static_dependencies/sympy/external/gmpy.py +0 -345
- coinex/ccxt/static_dependencies/sympy/external/importtools.py +0 -187
- coinex/ccxt/static_dependencies/sympy/external/ntheory.py +0 -637
- coinex/ccxt/static_dependencies/sympy/external/pythonmpq.py +0 -341
- coinex/ccxt/static_dependencies/toolz/__init__.py +0 -26
- coinex/ccxt/static_dependencies/toolz/_signatures.py +0 -784
- coinex/ccxt/static_dependencies/toolz/_version.py +0 -520
- coinex/ccxt/static_dependencies/toolz/compatibility.py +0 -30
- coinex/ccxt/static_dependencies/toolz/curried/__init__.py +0 -101
- coinex/ccxt/static_dependencies/toolz/curried/exceptions.py +0 -22
- coinex/ccxt/static_dependencies/toolz/curried/operator.py +0 -22
- coinex/ccxt/static_dependencies/toolz/dicttoolz.py +0 -339
- coinex/ccxt/static_dependencies/toolz/functoolz.py +0 -1049
- coinex/ccxt/static_dependencies/toolz/itertoolz.py +0 -1057
- coinex/ccxt/static_dependencies/toolz/recipes.py +0 -46
- coinex/ccxt/static_dependencies/toolz/utils.py +0 -9
- coinex/ccxt/static_dependencies/typing_inspect/__init__.py +0 -0
- coinex/ccxt/static_dependencies/typing_inspect/typing_inspect.py +0 -851
- coinex_api-0.0.14.dist-info/RECORD +0 -288
- {coinex_api-0.0.14.dist-info → coinex_api-0.0.15.dist-info}/WHEEL +0 -0
@@ -1,325 +0,0 @@
|
|
1
|
-
"""Nodes that make up parse trees
|
2
|
-
|
3
|
-
Parsing spits out a tree of these, which you can then tell to walk itself and
|
4
|
-
spit out a useful value. Or you can walk it yourself; the structural attributes
|
5
|
-
are public.
|
6
|
-
|
7
|
-
"""
|
8
|
-
# TODO: If this is slow, think about using cElementTree or something.
|
9
|
-
from inspect import isfunction
|
10
|
-
from sys import version_info, exc_info
|
11
|
-
|
12
|
-
from .exceptions import VisitationError, UndefinedLabel
|
13
|
-
|
14
|
-
|
15
|
-
class Node(object):
|
16
|
-
"""A parse tree node
|
17
|
-
|
18
|
-
Consider these immutable once constructed. As a side effect of a
|
19
|
-
memory-saving strategy in the cache, multiple references to a single
|
20
|
-
``Node`` might be returned in a single parse tree. So, if you start
|
21
|
-
messing with one, you'll see surprising parallel changes pop up elsewhere.
|
22
|
-
|
23
|
-
My philosophy is that parse trees (and their nodes) should be
|
24
|
-
representation-agnostic. That is, they shouldn't get all mixed up with what
|
25
|
-
the final rendered form of a wiki page (or the intermediate representation
|
26
|
-
of a programming language, or whatever) is going to be: you should be able
|
27
|
-
to parse once and render several representations from the tree, one after
|
28
|
-
another.
|
29
|
-
|
30
|
-
"""
|
31
|
-
# I tried making this subclass list, but it got ugly. I had to construct
|
32
|
-
# invalid ones and patch them up later, and there were other problems.
|
33
|
-
__slots__ = ['expr', # The expression that generated me
|
34
|
-
'full_text', # The full text fed to the parser
|
35
|
-
'start', # The position in the text where that expr started matching
|
36
|
-
'end', # The position after start where the expr first didn't
|
37
|
-
# match. [start:end] follow Python slice conventions.
|
38
|
-
'children'] # List of child parse tree nodes
|
39
|
-
|
40
|
-
def __init__(self, expr, full_text, start, end, children=None):
|
41
|
-
self.expr = expr
|
42
|
-
self.full_text = full_text
|
43
|
-
self.start = start
|
44
|
-
self.end = end
|
45
|
-
self.children = children or []
|
46
|
-
|
47
|
-
@property
|
48
|
-
def expr_name(self):
|
49
|
-
# backwards compatibility
|
50
|
-
return self.expr.name
|
51
|
-
|
52
|
-
def __iter__(self):
|
53
|
-
"""Support looping over my children and doing tuple unpacks on me.
|
54
|
-
|
55
|
-
It can be very handy to unpack nodes in arg lists; see
|
56
|
-
:class:`PegVisitor` for an example.
|
57
|
-
|
58
|
-
"""
|
59
|
-
return iter(self.children)
|
60
|
-
|
61
|
-
@property
|
62
|
-
def text(self):
|
63
|
-
"""Return the text this node matched."""
|
64
|
-
return self.full_text[self.start:self.end]
|
65
|
-
|
66
|
-
# From here down is just stuff for testing and debugging.
|
67
|
-
|
68
|
-
def prettily(self, error=None):
|
69
|
-
"""Return a unicode, pretty-printed representation of me.
|
70
|
-
|
71
|
-
:arg error: The node to highlight because an error occurred there
|
72
|
-
|
73
|
-
"""
|
74
|
-
# TODO: If a Node appears multiple times in the tree, we'll point to
|
75
|
-
# them all. Whoops.
|
76
|
-
def indent(text):
|
77
|
-
return '\n'.join((' ' + line) for line in text.splitlines())
|
78
|
-
ret = [u'<%s%s matching "%s">%s' % (
|
79
|
-
self.__class__.__name__,
|
80
|
-
(' called "%s"' % self.expr_name) if self.expr_name else '',
|
81
|
-
self.text,
|
82
|
-
' <-- *** We were here. ***' if error is self else '')]
|
83
|
-
for n in self:
|
84
|
-
ret.append(indent(n.prettily(error=error)))
|
85
|
-
return '\n'.join(ret)
|
86
|
-
|
87
|
-
def __str__(self):
|
88
|
-
"""Return a compact, human-readable representation of me."""
|
89
|
-
return self.prettily()
|
90
|
-
|
91
|
-
def __eq__(self, other):
|
92
|
-
"""Support by-value deep comparison with other nodes for testing."""
|
93
|
-
if not isinstance(other, Node):
|
94
|
-
return NotImplemented
|
95
|
-
|
96
|
-
return (self.expr == other.expr and
|
97
|
-
self.full_text == other.full_text and
|
98
|
-
self.start == other.start and
|
99
|
-
self.end == other.end and
|
100
|
-
self.children == other.children)
|
101
|
-
|
102
|
-
def __ne__(self, other):
|
103
|
-
return not self == other
|
104
|
-
|
105
|
-
def __repr__(self, top_level=True):
|
106
|
-
"""Return a bit of code (though not an expression) that will recreate
|
107
|
-
me."""
|
108
|
-
# repr() of unicode flattens everything out to ASCII, so we don't need
|
109
|
-
# to explicitly encode things afterward.
|
110
|
-
ret = ["s = %r" % self.full_text] if top_level else []
|
111
|
-
ret.append("%s(%r, s, %s, %s%s)" % (
|
112
|
-
self.__class__.__name__,
|
113
|
-
self.expr,
|
114
|
-
self.start,
|
115
|
-
self.end,
|
116
|
-
(', children=[%s]' %
|
117
|
-
', '.join([c.__repr__(top_level=False) for c in self.children]))
|
118
|
-
if self.children else ''))
|
119
|
-
return '\n'.join(ret)
|
120
|
-
|
121
|
-
|
122
|
-
class RegexNode(Node):
|
123
|
-
"""Node returned from a ``Regex`` expression
|
124
|
-
|
125
|
-
Grants access to the ``re.Match`` object, in case you want to access
|
126
|
-
capturing groups, etc.
|
127
|
-
|
128
|
-
"""
|
129
|
-
__slots__ = ['match']
|
130
|
-
|
131
|
-
|
132
|
-
class RuleDecoratorMeta(type):
|
133
|
-
def __new__(metaclass, name, bases, namespace):
|
134
|
-
def unvisit(name):
|
135
|
-
"""Remove any leading "visit_" from a method name."""
|
136
|
-
return name[6:] if name.startswith('visit_') else name
|
137
|
-
|
138
|
-
methods = [v for k, v in namespace.items() if
|
139
|
-
hasattr(v, '_rule') and isfunction(v)]
|
140
|
-
if methods:
|
141
|
-
from .grammar import Grammar # circular import dodge
|
142
|
-
|
143
|
-
methods.sort(key=(lambda x: x.func_code.co_firstlineno)
|
144
|
-
if version_info[0] < 3 else
|
145
|
-
(lambda x: x.__code__.co_firstlineno))
|
146
|
-
# Possible enhancement: once we get the Grammar extensibility story
|
147
|
-
# solidified, we can have @rules *add* to the default grammar
|
148
|
-
# rather than pave over it.
|
149
|
-
namespace['grammar'] = Grammar(
|
150
|
-
'\n'.join('{name} = {expr}'.format(name=unvisit(m.__name__),
|
151
|
-
expr=m._rule)
|
152
|
-
for m in methods))
|
153
|
-
return super(RuleDecoratorMeta,
|
154
|
-
metaclass).__new__(metaclass, name, bases, namespace)
|
155
|
-
|
156
|
-
|
157
|
-
class NodeVisitor(object, metaclass=RuleDecoratorMeta):
|
158
|
-
"""A shell for writing things that turn parse trees into something useful
|
159
|
-
|
160
|
-
Performs a depth-first traversal of an AST. Subclass this, add methods for
|
161
|
-
each expr you care about, instantiate, and call
|
162
|
-
``visit(top_node_of_parse_tree)``. It'll return the useful stuff. This API
|
163
|
-
is very similar to that of ``ast.NodeVisitor``.
|
164
|
-
|
165
|
-
These could easily all be static methods, but that would add at least as
|
166
|
-
much weirdness at the call site as the ``()`` for instantiation. And this
|
167
|
-
way, we support subclasses that require state: options, for example, or a
|
168
|
-
symbol table constructed from a programming language's AST.
|
169
|
-
|
170
|
-
We never transform the parse tree in place, because...
|
171
|
-
|
172
|
-
* There are likely multiple references to the same ``Node`` object in a
|
173
|
-
parse tree, and changes to one reference would surprise you elsewhere.
|
174
|
-
* It makes it impossible to report errors: you'd end up with the "error"
|
175
|
-
arrow pointing someplace in a half-transformed mishmash of nodes--and
|
176
|
-
that's assuming you're even transforming the tree into another tree.
|
177
|
-
Heaven forbid you're making it into a string or something else.
|
178
|
-
|
179
|
-
"""
|
180
|
-
|
181
|
-
#: The :term:`default grammar`: the one recommended for use with this
|
182
|
-
#: visitor. If you populate this, you will be able to call
|
183
|
-
#: :meth:`NodeVisitor.parse()` as a shortcut.
|
184
|
-
grammar = None
|
185
|
-
|
186
|
-
#: Classes of exceptions you actually intend to raise during visitation
|
187
|
-
#: and which should propagate out of the visitor. These will not be
|
188
|
-
#: wrapped in a VisitationError when they arise.
|
189
|
-
unwrapped_exceptions = ()
|
190
|
-
|
191
|
-
# TODO: If we need to optimize this, we can go back to putting subclasses
|
192
|
-
# in charge of visiting children; they know when not to bother. Or we can
|
193
|
-
# mark nodes as not descent-worthy in the grammar.
|
194
|
-
def visit(self, node):
|
195
|
-
"""Walk a parse tree, transforming it into another representation.
|
196
|
-
|
197
|
-
Recursively descend a parse tree, dispatching to the method named after
|
198
|
-
the rule in the :class:`~.grammar.Grammar` that produced
|
199
|
-
each node. If, for example, a rule was... ::
|
200
|
-
|
201
|
-
bold = '<b>'
|
202
|
-
|
203
|
-
...the ``visit_bold()`` method would be called. It is your
|
204
|
-
responsibility to subclass :class:`NodeVisitor` and implement those
|
205
|
-
methods.
|
206
|
-
|
207
|
-
"""
|
208
|
-
method = getattr(self, 'visit_' + node.expr_name, self.generic_visit)
|
209
|
-
|
210
|
-
# Call that method, and show where in the tree it failed if it blows
|
211
|
-
# up.
|
212
|
-
try:
|
213
|
-
return method(node, [self.visit(n) for n in node])
|
214
|
-
except (VisitationError, UndefinedLabel):
|
215
|
-
# Don't catch and re-wrap already-wrapped exceptions.
|
216
|
-
raise
|
217
|
-
except Exception as exc:
|
218
|
-
# implentors may define exception classes that should not be
|
219
|
-
# wrapped.
|
220
|
-
if isinstance(exc, self.unwrapped_exceptions):
|
221
|
-
raise
|
222
|
-
# Catch any exception, and tack on a parse tree so it's easier to
|
223
|
-
# see where it went wrong.
|
224
|
-
exc_class = type(exc)
|
225
|
-
raise VisitationError(exc, exc_class, node)
|
226
|
-
|
227
|
-
def generic_visit(self, node, visited_children):
|
228
|
-
"""Default visitor method
|
229
|
-
|
230
|
-
:arg node: The node we're visiting
|
231
|
-
:arg visited_children: The results of visiting the children of that
|
232
|
-
node, in a list
|
233
|
-
|
234
|
-
I'm not sure there's an implementation of this that makes sense across
|
235
|
-
all (or even most) use cases, so we leave it to subclasses to implement
|
236
|
-
for now.
|
237
|
-
|
238
|
-
"""
|
239
|
-
raise NotImplementedError('No visitor method was defined for this expression: %s' %
|
240
|
-
node.expr.as_rule())
|
241
|
-
|
242
|
-
# Convenience methods:
|
243
|
-
|
244
|
-
def parse(self, text, pos=0):
|
245
|
-
"""Parse some text with this Visitor's default grammar and return the
|
246
|
-
result of visiting it.
|
247
|
-
|
248
|
-
``SomeVisitor().parse('some_string')`` is a shortcut for
|
249
|
-
``SomeVisitor().visit(some_grammar.parse('some_string'))``.
|
250
|
-
|
251
|
-
"""
|
252
|
-
return self._parse_or_match(text, pos, 'parse')
|
253
|
-
|
254
|
-
def match(self, text, pos=0):
|
255
|
-
"""Parse and visit some text with this Visitor's default grammar, but
|
256
|
-
don't insist on parsing all the way to the end.
|
257
|
-
|
258
|
-
``SomeVisitor().match('some_string')`` is a shortcut for
|
259
|
-
``SomeVisitor().visit(some_grammar.match('some_string'))``.
|
260
|
-
|
261
|
-
"""
|
262
|
-
return self._parse_or_match(text, pos, 'match')
|
263
|
-
|
264
|
-
# Internal convenience methods to help you write your own visitors:
|
265
|
-
|
266
|
-
def lift_child(self, node, children):
|
267
|
-
"""Lift the sole child of ``node`` up to replace the node."""
|
268
|
-
first_child, = children
|
269
|
-
return first_child
|
270
|
-
|
271
|
-
# Private methods:
|
272
|
-
|
273
|
-
def _parse_or_match(self, text, pos, method_name):
|
274
|
-
"""Execute a parse or match on the default grammar, followed by a
|
275
|
-
visitation.
|
276
|
-
|
277
|
-
Raise RuntimeError if there is no default grammar specified.
|
278
|
-
|
279
|
-
"""
|
280
|
-
if not self.grammar:
|
281
|
-
raise RuntimeError(
|
282
|
-
"The {cls}.{method}() shortcut won't work because {cls} was "
|
283
|
-
"never associated with a specific " "grammar. Fill out its "
|
284
|
-
"`grammar` attribute, and try again.".format(
|
285
|
-
cls=self.__class__.__name__,
|
286
|
-
method=method_name))
|
287
|
-
return self.visit(getattr(self.grammar, method_name)(text, pos=pos))
|
288
|
-
|
289
|
-
|
290
|
-
def rule(rule_string):
|
291
|
-
"""Decorate a NodeVisitor ``visit_*`` method to tie a grammar rule to it.
|
292
|
-
|
293
|
-
The following will arrange for the ``visit_digit`` method to receive the
|
294
|
-
results of the ``~"[0-9]"`` parse rule::
|
295
|
-
|
296
|
-
@rule('~"[0-9]"')
|
297
|
-
def visit_digit(self, node, visited_children):
|
298
|
-
...
|
299
|
-
|
300
|
-
Notice that there is no "digit = " as part of the rule; that gets inferred
|
301
|
-
from the method name.
|
302
|
-
|
303
|
-
In cases where there is only one kind of visitor interested in a grammar,
|
304
|
-
using ``@rule`` saves you having to look back and forth between the visitor
|
305
|
-
and the grammar definition.
|
306
|
-
|
307
|
-
On an implementation level, all ``@rule`` rules get stitched together into
|
308
|
-
a :class:`~.Grammar` that becomes the NodeVisitor's
|
309
|
-
:term:`default grammar`.
|
310
|
-
|
311
|
-
Typically, the choice of a default rule for this grammar is simple: whatever
|
312
|
-
``@rule`` comes first in the class is the default. But the choice may become
|
313
|
-
surprising if you divide the ``@rule`` calls among subclasses. At the
|
314
|
-
moment, which method "comes first" is decided simply by comparing line
|
315
|
-
numbers, so whatever method is on the smallest-numbered line will be the
|
316
|
-
default. In a future release, this will change to pick the
|
317
|
-
first ``@rule`` call on the basemost class that has one. That way, a
|
318
|
-
subclass which does not override the default rule's ``visit_*`` method
|
319
|
-
won't unintentionally change which rule is the default.
|
320
|
-
|
321
|
-
"""
|
322
|
-
def decorator(method):
|
323
|
-
method._rule = rule_string # XXX: Maybe register them on a class var instead so we can just override a @rule'd visitor method on a subclass without blowing away the rule string that comes with it.
|
324
|
-
return method
|
325
|
-
return decorator
|
@@ -1,40 +0,0 @@
|
|
1
|
-
"""General tools which don't depend on other parts of Parsimonious"""
|
2
|
-
|
3
|
-
import ast
|
4
|
-
|
5
|
-
|
6
|
-
class StrAndRepr(object):
|
7
|
-
"""Mix-in which gives the class the same __repr__ and __str__."""
|
8
|
-
|
9
|
-
def __repr__(self):
|
10
|
-
return self.__str__()
|
11
|
-
|
12
|
-
|
13
|
-
def evaluate_string(string):
|
14
|
-
"""Piggyback on Python's string support so we can have backslash escaping
|
15
|
-
and niceties like \n, \t, etc. string.decode('string_escape') would have
|
16
|
-
been a lower-level possibility.
|
17
|
-
|
18
|
-
"""
|
19
|
-
return ast.literal_eval(string)
|
20
|
-
|
21
|
-
|
22
|
-
class Token(StrAndRepr):
|
23
|
-
"""A class to represent tokens, for use with TokenGrammars
|
24
|
-
|
25
|
-
You will likely want to subclass this to hold additional information, like
|
26
|
-
the characters that you lexed to create this token. Alternately, feel free
|
27
|
-
to create your own class from scratch. The only contract is that tokens
|
28
|
-
must have a ``type`` attr.
|
29
|
-
|
30
|
-
"""
|
31
|
-
__slots__ = ['type']
|
32
|
-
|
33
|
-
def __init__(self, type):
|
34
|
-
self.type = type
|
35
|
-
|
36
|
-
def __str__(self):
|
37
|
-
return u'<Token "%s">' % (self.type,)
|
38
|
-
|
39
|
-
def __eq__(self, other):
|
40
|
-
return self.type == other.type
|
File without changes
|
@@ -1,44 +0,0 @@
|
|
1
|
-
from __future__ import annotations
|
2
|
-
|
3
|
-
from dataclasses import dataclass
|
4
|
-
from typing import Dict, Optional, OrderedDict
|
5
|
-
|
6
|
-
from ...cairo.data_types import CairoType, StructType
|
7
|
-
|
8
|
-
|
9
|
-
@dataclass
|
10
|
-
class Abi:
|
11
|
-
"""
|
12
|
-
Dataclass representing class abi. Contains parsed functions, events and structures.
|
13
|
-
"""
|
14
|
-
|
15
|
-
@dataclass
|
16
|
-
class Function:
|
17
|
-
"""
|
18
|
-
Dataclass representing function's abi.
|
19
|
-
"""
|
20
|
-
|
21
|
-
name: str
|
22
|
-
inputs: OrderedDict[str, CairoType]
|
23
|
-
outputs: OrderedDict[str, CairoType]
|
24
|
-
|
25
|
-
@dataclass
|
26
|
-
class Event:
|
27
|
-
"""
|
28
|
-
Dataclass representing event's abi.
|
29
|
-
"""
|
30
|
-
|
31
|
-
name: str
|
32
|
-
data: OrderedDict[str, CairoType]
|
33
|
-
|
34
|
-
defined_structures: Dict[
|
35
|
-
str, StructType
|
36
|
-
] #: Abi of structures defined by the class.
|
37
|
-
functions: Dict[str, Function] #: Functions defined by the class.
|
38
|
-
constructor: Optional[
|
39
|
-
Function
|
40
|
-
] #: Contract's constructor. It is None if class doesn't define one.
|
41
|
-
l1_handler: Optional[
|
42
|
-
Function
|
43
|
-
] #: Handler of L1 messages. It is None if class doesn't define one.
|
44
|
-
events: Dict[str, Event] #: Events defined by the class
|
@@ -1,216 +0,0 @@
|
|
1
|
-
from __future__ import annotations
|
2
|
-
|
3
|
-
import dataclasses
|
4
|
-
import json
|
5
|
-
from collections import OrderedDict, defaultdict
|
6
|
-
from typing import DefaultDict, Dict, List, Optional, cast
|
7
|
-
|
8
|
-
from ....marshmallow import EXCLUDE
|
9
|
-
|
10
|
-
from .model import Abi
|
11
|
-
from .schemas import ContractAbiEntrySchema
|
12
|
-
from .shape import (
|
13
|
-
CONSTRUCTOR_ENTRY,
|
14
|
-
EVENT_ENTRY,
|
15
|
-
FUNCTION_ENTRY,
|
16
|
-
L1_HANDLER_ENTRY,
|
17
|
-
STRUCT_ENTRY,
|
18
|
-
EventDict,
|
19
|
-
FunctionDict,
|
20
|
-
StructMemberDict,
|
21
|
-
TypedMemberDict,
|
22
|
-
)
|
23
|
-
from ...cairo.data_types import CairoType, StructType
|
24
|
-
from ...cairo.type_parser import TypeParser
|
25
|
-
|
26
|
-
|
27
|
-
class AbiParsingError(ValueError):
|
28
|
-
"""
|
29
|
-
Error raised when something wrong goes during abi parsing.
|
30
|
-
"""
|
31
|
-
|
32
|
-
|
33
|
-
class AbiParser:
|
34
|
-
"""
|
35
|
-
Utility class for parsing abi into a dataclass.
|
36
|
-
"""
|
37
|
-
|
38
|
-
# Entries from ABI grouped by entry type
|
39
|
-
_grouped: DefaultDict[str, List[Dict]]
|
40
|
-
# lazy init property
|
41
|
-
_type_parser: Optional[TypeParser] = None
|
42
|
-
|
43
|
-
def __init__(self, abi_list: List[Dict]):
|
44
|
-
"""
|
45
|
-
Abi parser constructor. Ensures that abi satisfies the abi schema.
|
46
|
-
|
47
|
-
:param abi_list: Contract's ABI as a list of dictionaries.
|
48
|
-
"""
|
49
|
-
abi = [
|
50
|
-
ContractAbiEntrySchema().load(entry, unknown=EXCLUDE) for entry in abi_list
|
51
|
-
]
|
52
|
-
grouped = defaultdict(list)
|
53
|
-
for entry in abi:
|
54
|
-
assert isinstance(entry, dict)
|
55
|
-
grouped[entry["type"]].append(entry)
|
56
|
-
|
57
|
-
self._grouped = grouped
|
58
|
-
|
59
|
-
def parse(self) -> Abi:
|
60
|
-
"""
|
61
|
-
Parse abi provided to constructor and return it as a dataclass. Ensures that there are no cycles in the abi.
|
62
|
-
|
63
|
-
:raises: AbiParsingError: on any parsing error.
|
64
|
-
:return: Abi dataclass.
|
65
|
-
"""
|
66
|
-
structures = self._parse_structures()
|
67
|
-
functions_dict = cast(
|
68
|
-
Dict[str, FunctionDict],
|
69
|
-
AbiParser._group_by_entry_name(
|
70
|
-
self._grouped[FUNCTION_ENTRY], "defined functions"
|
71
|
-
),
|
72
|
-
)
|
73
|
-
events_dict = cast(
|
74
|
-
Dict[str, EventDict],
|
75
|
-
AbiParser._group_by_entry_name(
|
76
|
-
self._grouped[EVENT_ENTRY], "defined events"
|
77
|
-
),
|
78
|
-
)
|
79
|
-
constructors = cast(List[FunctionDict], self._grouped[CONSTRUCTOR_ENTRY])
|
80
|
-
l1_handlers = cast(List[FunctionDict], self._grouped[L1_HANDLER_ENTRY])
|
81
|
-
|
82
|
-
if len(l1_handlers) > 1:
|
83
|
-
raise AbiParsingError("L1 handler in ABI must be defined at most once.")
|
84
|
-
|
85
|
-
if len(constructors) > 1:
|
86
|
-
raise AbiParsingError("Constructor in ABI must be defined at most once.")
|
87
|
-
|
88
|
-
return Abi(
|
89
|
-
defined_structures=structures,
|
90
|
-
constructor=(
|
91
|
-
self._parse_function(constructors[0]) if constructors else None
|
92
|
-
),
|
93
|
-
l1_handler=(self._parse_function(l1_handlers[0]) if l1_handlers else None),
|
94
|
-
functions={
|
95
|
-
name: self._parse_function(entry)
|
96
|
-
for name, entry in functions_dict.items()
|
97
|
-
},
|
98
|
-
events={
|
99
|
-
name: self._parse_event(entry) for name, entry in events_dict.items()
|
100
|
-
},
|
101
|
-
)
|
102
|
-
|
103
|
-
@property
|
104
|
-
def type_parser(self) -> TypeParser:
|
105
|
-
if self._type_parser:
|
106
|
-
return self._type_parser
|
107
|
-
|
108
|
-
raise RuntimeError("Tried to get type_parser before it was set.")
|
109
|
-
|
110
|
-
def _parse_structures(self) -> Dict[str, StructType]:
|
111
|
-
structs_dict = AbiParser._group_by_entry_name(
|
112
|
-
self._grouped[STRUCT_ENTRY], "defined structures"
|
113
|
-
)
|
114
|
-
|
115
|
-
# Contains sorted members of the struct
|
116
|
-
struct_members: Dict[str, List[StructMemberDict]] = {}
|
117
|
-
structs: Dict[str, StructType] = {}
|
118
|
-
|
119
|
-
# Example problem (with a simplified json structure):
|
120
|
-
# [{name: User, fields: {id: Uint256}}, {name: "Uint256", ...}]
|
121
|
-
# User refers to Uint256 even though it is not known yet (will be parsed next).
|
122
|
-
# This is why it is important to create the structure types first. This way other types can already refer to
|
123
|
-
# them when parsing types, even thought their fields are not filled yet.
|
124
|
-
# At the end we will mutate those structures to contain the right fields. An alternative would be to use
|
125
|
-
# topological sorting with an additional "unresolved type", so this flow is much easier.
|
126
|
-
for name, struct in structs_dict.items():
|
127
|
-
structs[name] = StructType(name, OrderedDict())
|
128
|
-
without_offset = [
|
129
|
-
member for member in struct["members"] if member.get("offset") is None
|
130
|
-
]
|
131
|
-
with_offset = [
|
132
|
-
member for member in struct["members"] if member not in without_offset
|
133
|
-
]
|
134
|
-
struct_members[name] = sorted(
|
135
|
-
with_offset, key=lambda member: member["offset"] # pyright: ignore
|
136
|
-
)
|
137
|
-
for member in without_offset:
|
138
|
-
member["offset"] = (
|
139
|
-
struct_members[name][-1].get("offset", 0) + 1
|
140
|
-
if struct_members[name]
|
141
|
-
else 0
|
142
|
-
)
|
143
|
-
struct_members[name].append(member)
|
144
|
-
|
145
|
-
# Now parse the types of members and save them.
|
146
|
-
self._type_parser = TypeParser(structs)
|
147
|
-
for name, struct in structs.items():
|
148
|
-
members = self._parse_members(
|
149
|
-
cast(List[TypedMemberDict], struct_members[name]),
|
150
|
-
f"members of structure '{name}'",
|
151
|
-
)
|
152
|
-
struct.types.update(members)
|
153
|
-
|
154
|
-
# All types have their members assigned now
|
155
|
-
|
156
|
-
self._check_for_cycles(structs)
|
157
|
-
|
158
|
-
return structs
|
159
|
-
|
160
|
-
@staticmethod
|
161
|
-
def _check_for_cycles(structs: Dict[str, StructType]):
|
162
|
-
# We want to avoid creating our own cycle checker as it would make it more complex. json module has a built-in
|
163
|
-
# checker for cycles.
|
164
|
-
try:
|
165
|
-
_to_json(structs)
|
166
|
-
except ValueError as err:
|
167
|
-
raise AbiParsingError(err) from ValueError
|
168
|
-
|
169
|
-
def _parse_function(self, function: FunctionDict) -> Abi.Function:
|
170
|
-
return Abi.Function(
|
171
|
-
name=function["name"],
|
172
|
-
inputs=self._parse_members(function["inputs"], function["name"]),
|
173
|
-
outputs=self._parse_members(function["outputs"], function["name"]),
|
174
|
-
)
|
175
|
-
|
176
|
-
def _parse_event(self, event: EventDict) -> Abi.Event:
|
177
|
-
return Abi.Event(
|
178
|
-
name=event["name"],
|
179
|
-
data=self._parse_members(event["data"], event["name"]),
|
180
|
-
)
|
181
|
-
|
182
|
-
def _parse_members(
|
183
|
-
self, params: List[TypedMemberDict], entity_name: str
|
184
|
-
) -> OrderedDict[str, CairoType]:
|
185
|
-
# Without cast, it complains that 'Type "TypedMemberDict" cannot be assigned to type "T@_group_by_name"'
|
186
|
-
members = AbiParser._group_by_entry_name(cast(List[Dict], params), entity_name)
|
187
|
-
return OrderedDict(
|
188
|
-
(name, self.type_parser.parse_inline_type(param["type"]))
|
189
|
-
for name, param in members.items()
|
190
|
-
)
|
191
|
-
|
192
|
-
@staticmethod
|
193
|
-
def _group_by_entry_name(
|
194
|
-
dicts: List[Dict], entity_name: str
|
195
|
-
) -> OrderedDict[str, Dict]:
|
196
|
-
grouped = OrderedDict()
|
197
|
-
for entry in dicts:
|
198
|
-
name = entry["name"]
|
199
|
-
if name in grouped:
|
200
|
-
raise AbiParsingError(
|
201
|
-
f"Name '{name}' was used more than once in {entity_name}."
|
202
|
-
)
|
203
|
-
grouped[name] = entry
|
204
|
-
return grouped
|
205
|
-
|
206
|
-
|
207
|
-
def _to_json(value):
|
208
|
-
class DataclassSupportingEncoder(json.JSONEncoder):
|
209
|
-
def default(self, o):
|
210
|
-
# Dataclasses are not supported by json. Additionally, dataclasses.asdict() works recursively and doesn't
|
211
|
-
# check for cycles, so we need to flatten dataclasses (by ONE LEVEL) ourselves.
|
212
|
-
if dataclasses.is_dataclass(o):
|
213
|
-
return tuple(getattr(o, field.name) for field in dataclasses.fields(o))
|
214
|
-
return super().default(o)
|
215
|
-
|
216
|
-
return json.dumps(value, cls=DataclassSupportingEncoder)
|