This repository has been archived by the owner on Apr 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
specs.ts
198 lines (169 loc) · 4.48 KB
/
specs.ts
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
export interface IContractMetadata {
readonly metadataVersion: string;
readonly source: ISource;
readonly contract: IContract;
readonly spec: IContractSpec;
readonly types: Array<ITypeDef>;
readonly storage: ILayout;
}
export interface ISource {
readonly hash: string;
language: string;
readonly compiler: string;
}
export type ITypeDef =
| IPrimitiveDef
| ITupleDef
| IArrayDef
| ISequenceDef
| ICompositeDef
| IVariantDef;
interface Def<T> {
readonly def: T;
}
export type ILayout = IStructLayout | ICellLayout | IHashLayout | IArrayLayout | StructLayout;
export interface IStructLayout {
struct: ArrayFieldLayout;
}
export interface ArrayFieldLayout {
fields: Array<IFieldLayout>;
}
export interface ICellLayout {
readonly key: string;
readonly ty: number;
}
export interface IArrayLayout {
readonly offset: string;
readonly len: number;
readonly cellsPerElem: number;
readonly layout: ILayout;
}
export interface IFieldLayout {
readonly name: string | null;
readonly layout: ILayout;
}
export interface IHashLayout {
readonly offset: string;
readonly strategy: IHashingStrategy;
readonly layout: ILayout;
}
export interface IHashingStrategy {
readonly hasher: string;
readonly prefix: string;
readonly postfix: string;
}
export type IPrimitiveDef = Def<{
primitive: string;
}>;
export type ITupleDef = Def<{
tuple: {
fields: Array<number>;
};
}>;
export type IArrayDef = Def<{
array: {
len: number;
type: number;
};
}>;
export type ISequenceDef = Def<{
sequence: {
type: number;
};
}>;
export type ICompositeDef = Def<{
composite: {
fields: Array<IField>;
};
}>;
export type IVariantDef = Def<{
variants: Array<IVariant>;
}>;
export interface IVariant {
readonly name: string;
readonly fields: Array<IField>;
readonly discriminant: number | null;
}
export interface IField {
readonly name?: string | null;
readonly type: number;
}
export interface IContract {
readonly name: string;
readonly version: string;
readonly authors: Array<string>;
readonly description: string | null;
readonly documentation: string | null;
readonly repository: string | null;
readonly homepage: string | null;
readonly license: string | null;
}
export interface IContractSpec {
/**
* The set of constructors of the contract.
*/
readonly constructors: Array<IConstructorSpec>;
/**
* The external messages of the contract.
*/
readonly messages: Array<IMessageSpec>;
/**
* The events of the contract.
*/
readonly events: Array<IEventSpec>;
/**
* The contract documentation.
*/
readonly docs: Array<string>;
}
export interface IConstructorSpec extends NameSelectorSpec {
/// The parameters of the deploy handler.
readonly args: Array<IMessageParamSpec>;
readonly docs: Array<string>;
}
export interface IMessageSpec extends NameSelectorSpec {
/// If the message is allowed to mutate the contract state.
readonly mutates: boolean;
/// If the message is payable by the caller.
readonly payable: boolean;
/// The parameters of the message.
readonly args: Array<IMessageParamSpec>;
/// The return type of the message.
readonly returnType: ITypeSpec | null;
readonly docs: Array<string>;
}
export interface IEventSpec extends NameSpec {
/// The event arguments.
readonly args: Array<IEventParamSpec>;
readonly docs: Array<string>;
}
export interface IEventParamSpec extends NameSpec {
/// If the event parameter is indexed.
readonly indexed: boolean;
/// The type of the parameter.
readonly type: ITypeSpec;
readonly docs: Array<string>;
}
export interface IMessageParamSpec extends NameSpec {
/// The type of the parameter.
readonly type: ITypeSpec;
}
export interface ITypeSpec {
/// The actual type.
readonly type: number;
/// The compile-time known displayed representation of the type.
readonly displayName: string[];
}
interface NameSelectorSpec {
/// The name of the message and some optional prefixes.
///
/// In case of interface provided messages and constructors the prefix
/// by convention in ask is the name of the interface.
readonly name: Array<string>;
/// The selector hash of the message.
readonly selector: string;
}
interface NameSpec {
/// The name of the parameter.
readonly name: string;
}