|
3 | 3 | They need to stay backwards compatible for old transactions/blocks to be fetchable. |
4 | 4 | """ |
5 | 5 |
|
| 6 | +import json |
6 | 7 | from abc import ABC |
7 | 8 | from dataclasses import dataclass, field |
8 | 9 | from enum import Enum |
9 | | -from typing import Any, Iterable, List, Optional, Union |
| 10 | +from typing import Any, Iterable, List, Literal, Optional, Union, cast |
10 | 11 |
|
11 | | -from typing_extensions import Literal |
| 12 | +from marshmallow import EXCLUDE |
12 | 13 |
|
13 | 14 | from starknet_py.abi.v0.shape import AbiDictList |
| 15 | +from starknet_py.abi.v1.schemas import ( |
| 16 | + ContractAbiEntrySchema as ContractAbiEntrySchemaV1, |
| 17 | +) |
| 18 | +from starknet_py.abi.v1.shape import AbiDictEntry as AbiDictEntryV1 |
| 19 | +from starknet_py.abi.v1.shape import AbiDictList as AbiDictListV1 |
| 20 | +from starknet_py.abi.v2.schemas import ( |
| 21 | + ContractAbiEntrySchema as ContractAbiEntrySchemaV2, |
| 22 | +) |
| 23 | +from starknet_py.abi.v2.shape import AbiDictEntry as AbiDictEntryV2 |
| 24 | +from starknet_py.abi.v2.shape import AbiDictList as AbiDictListV2 |
| 25 | +from starknet_py.utils.constructor_args_translator import _is_abi_v2 |
| 26 | + |
| 27 | +# pylint: disable=too-many-lines |
14 | 28 |
|
15 | 29 | Hash = Union[int, str] |
16 | 30 | Tag = Literal["pending", "latest"] |
@@ -764,6 +778,27 @@ class SierraContractClass: |
764 | 778 | entry_points_by_type: SierraEntryPointsByType |
765 | 779 | abi: Optional[str] = None |
766 | 780 |
|
| 781 | + @property |
| 782 | + def parsed_abi(self) -> Union[AbiDictListV2, AbiDictListV1]: |
| 783 | + if self.abi is None: |
| 784 | + return [] |
| 785 | + |
| 786 | + load_abi: List = json.loads(self.abi) |
| 787 | + |
| 788 | + if _is_abi_v2(load_abi): |
| 789 | + return [ |
| 790 | + cast( |
| 791 | + AbiDictEntryV2, |
| 792 | + ContractAbiEntrySchemaV2(unknown=EXCLUDE).load(entry), |
| 793 | + ) |
| 794 | + for entry in load_abi |
| 795 | + ] |
| 796 | + |
| 797 | + return [ |
| 798 | + cast(AbiDictEntryV1, ContractAbiEntrySchemaV1(unknown=EXCLUDE).load(entry)) |
| 799 | + for entry in load_abi |
| 800 | + ] |
| 801 | + |
767 | 802 |
|
768 | 803 | @dataclass |
769 | 804 | class SierraCompiledContract(SierraContractClass): |
|
0 commit comments