This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
/
elementary.ts
289 lines (268 loc) · 5.21 KB
/
elementary.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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
import type BN from "bn.js";
import type Big from "big.js";
import type * as Types from "./types";
//note that we often want an elementary *value*, and not an error!
//so let's define those types too
/**
* An elementary value
*
* @Category General categories
*/
export type ElementaryValue =
| UintValue
| IntValue
| BoolValue
| BytesValue
| AddressValue
| StringValue
| FixedValue
| UfixedValue
| EnumValue
| UserDefinedValueTypeValue
| ContractValue;
export type BuiltInValueValue =
| UintValue
| IntValue
| BoolValue
| BytesStaticValue
| AddressValue
| FixedValue
| UfixedValue;
/**
* A bytestring value (static or dynamic)
*
* @Category Elementary types
*/
export type BytesValue = BytesStaticValue | BytesDynamicValue;
/**
* An unsigned integer value
*
* @Category Elementary types
*/
export interface UintValue {
type: Types.UintType;
kind: "value";
value: {
asBN: BN;
rawAsBN?: BN;
};
}
/**
* A signed integer value
*
* @Category Elementary types
*/
export interface IntValue {
type: Types.IntType;
kind: "value";
value: {
asBN: BN;
rawAsBN?: BN;
};
}
/**
* A boolean value
*
* @Category Elementary types
*/
export interface BoolValue {
type: Types.BoolType;
kind: "value";
value: {
asBoolean: boolean;
};
}
/**
* A bytestring value (static length)
*
* @Category Elementary types
*/
export interface BytesStaticValue {
type: Types.BytesTypeStatic;
kind: "value";
value: {
/**
* hex-formatted, with leading "0x"
*/
asHex: string;
rawAsHex?: string;
};
}
/**
* A bytestring value (dynamic length)
*
* @Category Elementary types
*/
export interface BytesDynamicValue {
type: Types.BytesTypeDynamic;
kind: "value";
value: {
/**
* hex-formatted, with leading "0x"
*/
asHex: string;
};
}
/**
* An address value
*
* @Category Elementary types
*/
export interface AddressValue {
type: Types.AddressType;
kind: "value";
value: {
/**
* has leading "0x" and is checksum-cased
*/
asAddress: string;
/**
* just a hex string, so no checksum
*/
rawAsHex?: string;
};
}
/**
* A string value; see [[StringValueInfo]] for more detail
*
* @Category Elementary types
*/
export interface StringValue {
type: Types.StringType;
kind: "value";
value: StringValueInfo;
}
/**
* These come in two types: valid strings and malformed strings.
*
* @Category Elementary types
*/
export type StringValueInfo = StringValueInfoValid | StringValueInfoMalformed;
/**
* This type of StringValueInfo represents a valid UTF-8 string.
*
* @Category Elementary types
*/
export interface StringValueInfoValid {
kind: "valid";
asString: string;
}
/**
* This type of StringValueInfo represents a malformed string.
*
* @Category Elementary types
*/
export interface StringValueInfoMalformed {
kind: "malformed";
/**
* hex-formatted, with leading "0x"
*/
asHex: string;
}
/**
* A signed fixed-point value
*
* @Category Elementary types
*/
export interface FixedValue {
type: Types.FixedType;
kind: "value";
value: {
asBig: Big;
rawAsBig?: Big;
};
}
/**
* An unsigned fixed-point value
*
* @Category Elementary types
*/
export interface UfixedValue {
type: Types.UfixedType;
kind: "value";
value: {
asBig: Big;
rawAsBig?: Big;
};
}
/**
* An enum value
*
* @Category User-defined elementary types
*/
export interface EnumValue {
type: Types.EnumType;
kind: "value";
value: {
name: string;
/**
* the numeric value of the enum
*/
numericAsBN: BN;
};
}
/**
* A UDVT value
*
* @Category User-defined elementary types
*/
export interface UserDefinedValueTypeValue {
type: Types.UserDefinedValueTypeType;
kind: "value";
value: BuiltInValueValue;
}
/**
* A contract value; see [[ContractValueInfo]] for more detail
*
* @Category User-defined elementary types
*/
export interface ContractValue {
type: Types.ContractType;
kind: "value";
value: ContractValueInfo;
}
/**
* There are two types -- one for contracts whose class we can identify, and one
* for when we can't identify the class.
*
* @Category User-defined elementary types
*/
export type ContractValueInfo =
| ContractValueInfoKnown
| ContractValueInfoUnknown;
/**
* This type of ContractValueInfo is used when we can identify the class.
*
* @Category User-defined elementary types
*/
export interface ContractValueInfoKnown {
kind: "known";
/**
* formatted as address (leading "0x", checksum-cased);
* note that this is not an AddressResult!
*/
address: string;
/**
* this is just a hexstring; no checksum (also may have padding beforehand)
*/
rawAddress?: string;
class: Types.ContractType;
//may have more optional members defined later, but I'll leave these out for now
}
/**
* This type of ContractValueInfo is used when we can't identify the class.
*
* @Category User-defined elementary types
*/
export interface ContractValueInfoUnknown {
kind: "unknown";
/**
* formatted as address (leading "0x", checksum-cased);
* note that this is not an AddressResult!
*/
address: string;
/**
* this is just a hexstring; no checksum (also may have padding beforehand)
*/
rawAddress?: string;
}