-
Notifications
You must be signed in to change notification settings - Fork 8
/
models.py
110 lines (86 loc) · 2.48 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
from __future__ import annotations
import enum
import typing
from typing import Literal, Sequence
import attrs
from immutabledict import immutabledict
if typing.TYPE_CHECKING:
from puya.avm_type import AVMType
from puya.parse import SourceLocation
class OnCompletionAction(enum.IntEnum):
NoOp = 0
OptIn = 1
CloseOut = 2
ClearState = 3
UpdateApplication = 4
DeleteApplication = 5
@attrs.frozen(kw_only=True)
class ARC4MethodConfig:
source_location: SourceLocation
name: str
is_bare: bool = False
allow_create: bool = False
require_create: bool = False
readonly: bool = False
allowed_completion_types: Sequence[OnCompletionAction] = attrs.field(
default=(OnCompletionAction.NoOp,),
converter=tuple[OnCompletionAction],
validator=attrs.validators.min_len(1),
)
default_args: immutabledict[str, str] = immutabledict()
"""Mapping is from parameter -> source"""
structs: immutabledict[str, ARC32StructDef] = immutabledict()
@attrs.define
class ARC4MethodArg:
name: str
type_: str
desc: str | None
@attrs.define
class ARC4Returns:
type_: str
desc: str | None
@attrs.define
class ARC4Method:
name: str
desc: str | None
args: list[ARC4MethodArg]
returns: ARC4Returns
config: ARC4MethodConfig
@attrs.frozen
class ARC32StructDef:
name: str
elements: Sequence[tuple[str, str]] = attrs.field(
factory=list, converter=tuple[tuple[str, str], ...]
)
@attrs.define(eq=False)
class ContractState:
name: str
source_location: SourceLocation
key: bytes
storage_type: Literal[AVMType.uint64, AVMType.bytes]
description: str | None
@attrs.frozen
class ContractMetaData:
description: str | None
name_override: str | None
module_name: str
class_name: str
global_state: immutabledict[str, ContractState]
local_state: immutabledict[str, ContractState]
arc4_methods: Sequence[ARC4Method]
@property
def is_arc4(self) -> bool:
return bool(self.arc4_methods)
@property
def name(self) -> str:
return self.name_override or self.class_name
@property
def full_name(self) -> str:
return ".".join((self.module_name, self.class_name))
@attrs.define(kw_only=True)
class CompiledContract:
approval_program: list[str]
"""lines of the TEAL approval program for the contract"""
clear_program: list[str]
"""lines of the TEAL clear program for the contract"""
metadata: ContractMetaData