@taquito/michel-codec 11.2.0 → 12.0.1
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.
- package/README.md +54 -20
- package/dist/lib/base58.js +88 -37
- package/dist/lib/base58.js.map +1 -1
- package/dist/lib/binary.js +401 -242
- package/dist/lib/binary.js.map +1 -1
- package/dist/lib/formatters.js +15 -11
- package/dist/lib/formatters.js.map +1 -1
- package/dist/lib/global-constants.js +4 -1
- package/dist/lib/global-constants.js.map +1 -1
- package/dist/lib/macros.js +227 -218
- package/dist/lib/macros.js.map +1 -1
- package/dist/lib/michelson-contract.js +10 -15
- package/dist/lib/michelson-contract.js.map +1 -1
- package/dist/lib/michelson-typecheck.js +32 -45
- package/dist/lib/michelson-typecheck.js.map +1 -1
- package/dist/lib/michelson-types.js.map +1 -1
- package/dist/lib/michelson-validator.js +233 -121
- package/dist/lib/michelson-validator.js.map +1 -1
- package/dist/lib/scan.js +20 -20
- package/dist/lib/scan.js.map +1 -1
- package/dist/lib/utils.js +1 -1
- package/dist/lib/version.js +2 -2
- package/dist/taquito-michel-codec.es6.js +1036 -807
- package/dist/taquito-michel-codec.es6.js.map +1 -1
- package/dist/taquito-michel-codec.umd.js +1036 -807
- package/dist/taquito-michel-codec.umd.js.map +1 -1
- package/dist/types/binary.d.ts +4 -4
- package/dist/types/formatters.d.ts +3 -3
- package/dist/types/macros.d.ts +2 -2
- package/dist/types/michelson-contract.d.ts +4 -4
- package/dist/types/michelson-types.d.ts +2 -1
- package/dist/types/michelson-validator.d.ts +7 -7
- package/dist/types/scan.d.ts +1 -1
- package/dist/types/taquito-michel-codec.d.ts +12 -12
- package/package.json +2 -2
- package/signature.json +7 -27
|
@@ -5,37 +5,150 @@ const utils_1 = require("./utils");
|
|
|
5
5
|
// Michelson validator
|
|
6
6
|
const maxViewNameLength = 31;
|
|
7
7
|
const noArgInstructionIDs = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
ABS: true,
|
|
9
|
+
ADD: true,
|
|
10
|
+
ADDRESS: true,
|
|
11
|
+
AMOUNT: true,
|
|
12
|
+
AND: true,
|
|
13
|
+
APPLY: true,
|
|
14
|
+
BALANCE: true,
|
|
15
|
+
BLAKE2B: true,
|
|
16
|
+
CAR: true,
|
|
17
|
+
CDR: true,
|
|
18
|
+
CHAIN_ID: true,
|
|
19
|
+
CHECK_SIGNATURE: true,
|
|
20
|
+
COMPARE: true,
|
|
21
|
+
CONCAT: true,
|
|
22
|
+
CONS: true,
|
|
23
|
+
EDIV: true,
|
|
24
|
+
EQ: true,
|
|
25
|
+
EXEC: true,
|
|
26
|
+
FAILWITH: true,
|
|
27
|
+
GE: true,
|
|
28
|
+
GET_AND_UPDATE: true,
|
|
29
|
+
GT: true,
|
|
30
|
+
HASH_KEY: true,
|
|
31
|
+
IMPLICIT_ACCOUNT: true,
|
|
32
|
+
INT: true,
|
|
33
|
+
ISNAT: true,
|
|
34
|
+
JOIN_TICKETS: true,
|
|
35
|
+
KECCAK: true,
|
|
36
|
+
LE: true,
|
|
37
|
+
LEVEL: true,
|
|
38
|
+
LSL: true,
|
|
39
|
+
LSR: true,
|
|
40
|
+
LT: true,
|
|
41
|
+
MEM: true,
|
|
42
|
+
MUL: true,
|
|
43
|
+
NEG: true,
|
|
44
|
+
NEQ: true,
|
|
45
|
+
NEVER: true,
|
|
46
|
+
NOT: true,
|
|
47
|
+
NOW: true,
|
|
48
|
+
OR: true,
|
|
49
|
+
PACK: true,
|
|
50
|
+
PAIRING_CHECK: true,
|
|
51
|
+
READ_TICKET: true,
|
|
52
|
+
SAPLING_VERIFY_UPDATE: true,
|
|
53
|
+
SELF: true,
|
|
54
|
+
SELF_ADDRESS: true,
|
|
55
|
+
SENDER: true,
|
|
56
|
+
SET_DELEGATE: true,
|
|
57
|
+
SHA256: true,
|
|
58
|
+
SHA3: true,
|
|
59
|
+
SHA512: true,
|
|
60
|
+
SIZE: true,
|
|
61
|
+
SLICE: true,
|
|
62
|
+
SOME: true,
|
|
63
|
+
SOURCE: true,
|
|
64
|
+
SPLIT_TICKET: true,
|
|
65
|
+
SUB: true,
|
|
66
|
+
SWAP: true,
|
|
67
|
+
TICKET: true,
|
|
68
|
+
TOTAL_VOTING_POWER: true,
|
|
69
|
+
TRANSFER_TOKENS: true,
|
|
70
|
+
UNIT: true,
|
|
71
|
+
VOTING_POWER: true,
|
|
72
|
+
XOR: true,
|
|
73
|
+
RENAME: true,
|
|
74
|
+
OPEN_CHEST: true,
|
|
75
|
+
SUB_MUTEZ: true,
|
|
16
76
|
};
|
|
17
77
|
exports.instructionIDs = Object.assign({}, noArgInstructionIDs, {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
78
|
+
CONTRACT: true,
|
|
79
|
+
CREATE_CONTRACT: true,
|
|
80
|
+
DIG: true,
|
|
81
|
+
DIP: true,
|
|
82
|
+
DROP: true,
|
|
83
|
+
DUG: true,
|
|
84
|
+
DUP: true,
|
|
85
|
+
EMPTY_BIG_MAP: true,
|
|
86
|
+
EMPTY_MAP: true,
|
|
87
|
+
EMPTY_SET: true,
|
|
88
|
+
GET: true,
|
|
89
|
+
IF: true,
|
|
90
|
+
IF_CONS: true,
|
|
91
|
+
IF_LEFT: true,
|
|
92
|
+
IF_NONE: true,
|
|
93
|
+
ITER: true,
|
|
94
|
+
LAMBDA: true,
|
|
95
|
+
LEFT: true,
|
|
96
|
+
LOOP: true,
|
|
97
|
+
LOOP_LEFT: true,
|
|
98
|
+
MAP: true,
|
|
99
|
+
NIL: true,
|
|
100
|
+
NONE: true,
|
|
101
|
+
PAIR: true,
|
|
102
|
+
PUSH: true,
|
|
103
|
+
RIGHT: true,
|
|
104
|
+
SAPLING_EMPTY_STATE: true,
|
|
105
|
+
UNPACK: true,
|
|
106
|
+
UNPAIR: true,
|
|
107
|
+
UPDATE: true,
|
|
108
|
+
CAST: true,
|
|
109
|
+
VIEW: true,
|
|
22
110
|
});
|
|
23
111
|
const simpleComparableTypeIDs = {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
112
|
+
unit: true,
|
|
113
|
+
never: true,
|
|
114
|
+
bool: true,
|
|
115
|
+
int: true,
|
|
116
|
+
nat: true,
|
|
117
|
+
string: true,
|
|
118
|
+
chain_id: true,
|
|
119
|
+
bytes: true,
|
|
120
|
+
mutez: true,
|
|
121
|
+
key_hash: true,
|
|
122
|
+
key: true,
|
|
123
|
+
signature: true,
|
|
124
|
+
timestamp: true,
|
|
125
|
+
address: true,
|
|
27
126
|
};
|
|
28
127
|
const typeIDs = Object.assign({}, simpleComparableTypeIDs, {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
128
|
+
or: true,
|
|
129
|
+
pair: true,
|
|
130
|
+
set: true,
|
|
131
|
+
big_map: true,
|
|
132
|
+
contract: true,
|
|
133
|
+
lambda: true,
|
|
134
|
+
list: true,
|
|
135
|
+
map: true,
|
|
136
|
+
operation: true,
|
|
137
|
+
option: true,
|
|
138
|
+
bls12_381_g1: true,
|
|
139
|
+
bls12_381_g2: true,
|
|
140
|
+
bls12_381_fr: true,
|
|
141
|
+
sapling_transaction: true,
|
|
142
|
+
sapling_state: true,
|
|
143
|
+
ticket: true,
|
|
144
|
+
chest_key: true,
|
|
145
|
+
chest: true,
|
|
33
146
|
});
|
|
34
147
|
class MichelsonValidationError extends utils_1.MichelsonError {
|
|
35
148
|
/**
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
149
|
+
* @param val Value of a node caused the error
|
|
150
|
+
* @param message An error message
|
|
151
|
+
*/
|
|
39
152
|
constructor(val, message) {
|
|
40
153
|
super(val, message);
|
|
41
154
|
this.val = val;
|
|
@@ -44,45 +157,45 @@ class MichelsonValidationError extends utils_1.MichelsonError {
|
|
|
44
157
|
}
|
|
45
158
|
exports.MichelsonValidationError = MichelsonValidationError;
|
|
46
159
|
function isPrim(ex) {
|
|
47
|
-
return
|
|
160
|
+
return 'prim' in ex;
|
|
48
161
|
}
|
|
49
162
|
function isPrimOrSeq(ex) {
|
|
50
|
-
return Array.isArray(ex) ||
|
|
163
|
+
return Array.isArray(ex) || 'prim' in ex;
|
|
51
164
|
}
|
|
52
165
|
function assertPrim(ex) {
|
|
53
166
|
if (isPrim(ex)) {
|
|
54
167
|
return true;
|
|
55
168
|
}
|
|
56
|
-
throw new MichelsonValidationError(ex,
|
|
169
|
+
throw new MichelsonValidationError(ex, 'prim expression expected');
|
|
57
170
|
}
|
|
58
171
|
function assertSeq(ex) {
|
|
59
172
|
if (Array.isArray(ex)) {
|
|
60
173
|
return true;
|
|
61
174
|
}
|
|
62
|
-
throw new MichelsonValidationError(ex,
|
|
175
|
+
throw new MichelsonValidationError(ex, 'sequence expression expected');
|
|
63
176
|
}
|
|
64
177
|
function assertPrimOrSeq(ex) {
|
|
65
178
|
if (isPrimOrSeq(ex)) {
|
|
66
179
|
return true;
|
|
67
180
|
}
|
|
68
|
-
throw new MichelsonValidationError(ex,
|
|
181
|
+
throw new MichelsonValidationError(ex, 'prim or sequence expression expected');
|
|
69
182
|
}
|
|
70
183
|
function assertNatural(i) {
|
|
71
|
-
if (i.int[0] ===
|
|
72
|
-
throw new MichelsonValidationError(i,
|
|
184
|
+
if (i.int[0] === '-') {
|
|
185
|
+
throw new MichelsonValidationError(i, 'natural number expected');
|
|
73
186
|
}
|
|
74
187
|
}
|
|
75
188
|
function assertIntLiteral(ex) {
|
|
76
|
-
if (
|
|
189
|
+
if ('int' in ex) {
|
|
77
190
|
return true;
|
|
78
191
|
}
|
|
79
|
-
throw new MichelsonValidationError(ex,
|
|
192
|
+
throw new MichelsonValidationError(ex, 'int literal expected');
|
|
80
193
|
}
|
|
81
194
|
function assertStringLiteral(ex) {
|
|
82
|
-
if (
|
|
195
|
+
if ('string' in ex) {
|
|
83
196
|
return true;
|
|
84
197
|
}
|
|
85
|
-
throw new MichelsonValidationError(ex,
|
|
198
|
+
throw new MichelsonValidationError(ex, 'string literal expected');
|
|
86
199
|
}
|
|
87
200
|
function assertArgs(ex, n) {
|
|
88
201
|
var _a;
|
|
@@ -101,7 +214,7 @@ function assertMichelsonInstruction(ex) {
|
|
|
101
214
|
if (Array.isArray(ex)) {
|
|
102
215
|
for (const n of ex) {
|
|
103
216
|
if (!Array.isArray(n) && !isPrim(n)) {
|
|
104
|
-
throw new MichelsonValidationError(ex,
|
|
217
|
+
throw new MichelsonValidationError(ex, 'sequence or prim expected');
|
|
105
218
|
}
|
|
106
219
|
assertMichelsonInstruction(n);
|
|
107
220
|
}
|
|
@@ -113,12 +226,12 @@ function assertMichelsonInstruction(ex) {
|
|
|
113
226
|
return true;
|
|
114
227
|
}
|
|
115
228
|
switch (ex.prim) {
|
|
116
|
-
case
|
|
117
|
-
case
|
|
118
|
-
case
|
|
119
|
-
case
|
|
120
|
-
case
|
|
121
|
-
case
|
|
229
|
+
case 'DROP':
|
|
230
|
+
case 'PAIR':
|
|
231
|
+
case 'UNPAIR':
|
|
232
|
+
case 'DUP':
|
|
233
|
+
case 'UPDATE':
|
|
234
|
+
case 'GET':
|
|
122
235
|
if (ex.args !== undefined && assertArgs(ex, 1)) {
|
|
123
236
|
/* istanbul ignore else */
|
|
124
237
|
if (assertIntLiteral(ex.args[0])) {
|
|
@@ -126,9 +239,9 @@ function assertMichelsonInstruction(ex) {
|
|
|
126
239
|
}
|
|
127
240
|
}
|
|
128
241
|
break;
|
|
129
|
-
case
|
|
130
|
-
case
|
|
131
|
-
case
|
|
242
|
+
case 'DIG':
|
|
243
|
+
case 'DUG':
|
|
244
|
+
case 'SAPLING_EMPTY_STATE':
|
|
132
245
|
/* istanbul ignore else */
|
|
133
246
|
if (assertArgs(ex, 1)) {
|
|
134
247
|
/* istanbul ignore else */
|
|
@@ -137,32 +250,32 @@ function assertMichelsonInstruction(ex) {
|
|
|
137
250
|
}
|
|
138
251
|
}
|
|
139
252
|
break;
|
|
140
|
-
case
|
|
141
|
-
case
|
|
142
|
-
case
|
|
143
|
-
case
|
|
144
|
-
case
|
|
253
|
+
case 'NONE':
|
|
254
|
+
case 'LEFT':
|
|
255
|
+
case 'RIGHT':
|
|
256
|
+
case 'NIL':
|
|
257
|
+
case 'CAST':
|
|
145
258
|
/* istanbul ignore else */
|
|
146
259
|
if (assertArgs(ex, 1)) {
|
|
147
260
|
assertMichelsonType(ex.args[0]);
|
|
148
261
|
}
|
|
149
262
|
break;
|
|
150
|
-
case
|
|
263
|
+
case 'UNPACK':
|
|
151
264
|
/* istanbul ignore else */
|
|
152
265
|
if (assertArgs(ex, 1)) {
|
|
153
266
|
assertMichelsonPackableType(ex.args[0]);
|
|
154
267
|
}
|
|
155
268
|
break;
|
|
156
|
-
case
|
|
269
|
+
case 'CONTRACT':
|
|
157
270
|
/* istanbul ignore else */
|
|
158
271
|
if (assertArgs(ex, 1)) {
|
|
159
272
|
assertMichelsonPassableType(ex.args[0]);
|
|
160
273
|
}
|
|
161
274
|
break;
|
|
162
|
-
case
|
|
163
|
-
case
|
|
164
|
-
case
|
|
165
|
-
case
|
|
275
|
+
case 'IF_NONE':
|
|
276
|
+
case 'IF_LEFT':
|
|
277
|
+
case 'IF_CONS':
|
|
278
|
+
case 'IF':
|
|
166
279
|
/* istanbul ignore else */
|
|
167
280
|
if (assertArgs(ex, 2)) {
|
|
168
281
|
/* istanbul ignore else */
|
|
@@ -175,22 +288,22 @@ function assertMichelsonInstruction(ex) {
|
|
|
175
288
|
}
|
|
176
289
|
}
|
|
177
290
|
break;
|
|
178
|
-
case
|
|
179
|
-
case
|
|
180
|
-
case
|
|
181
|
-
case
|
|
291
|
+
case 'MAP':
|
|
292
|
+
case 'ITER':
|
|
293
|
+
case 'LOOP':
|
|
294
|
+
case 'LOOP_LEFT':
|
|
182
295
|
/* istanbul ignore else */
|
|
183
296
|
if (assertArgs(ex, 1)) {
|
|
184
297
|
assertMichelsonInstruction(ex.args[0]);
|
|
185
298
|
}
|
|
186
299
|
break;
|
|
187
|
-
case
|
|
300
|
+
case 'CREATE_CONTRACT':
|
|
188
301
|
/* istanbul ignore else */
|
|
189
302
|
if (assertArgs(ex, 1)) {
|
|
190
303
|
assertMichelsonContract(ex.args[0]);
|
|
191
304
|
}
|
|
192
305
|
break;
|
|
193
|
-
case
|
|
306
|
+
case 'DIP':
|
|
194
307
|
if (((_a = ex.args) === null || _a === void 0 ? void 0 : _a.length) === 2) {
|
|
195
308
|
/* istanbul ignore else */
|
|
196
309
|
if (assertIntLiteral(ex.args[0])) {
|
|
@@ -208,37 +321,37 @@ function assertMichelsonInstruction(ex) {
|
|
|
208
321
|
}
|
|
209
322
|
}
|
|
210
323
|
else {
|
|
211
|
-
throw new MichelsonValidationError(ex,
|
|
324
|
+
throw new MichelsonValidationError(ex, '1 or 2 arguments expected');
|
|
212
325
|
}
|
|
213
326
|
break;
|
|
214
|
-
case
|
|
327
|
+
case 'PUSH':
|
|
215
328
|
/* istanbul ignore else */
|
|
216
329
|
if (assertArgs(ex, 2)) {
|
|
217
330
|
assertMichelsonPushableType(ex.args[0]);
|
|
218
331
|
assertMichelsonData(ex.args[1]);
|
|
219
332
|
}
|
|
220
333
|
break;
|
|
221
|
-
case
|
|
334
|
+
case 'EMPTY_SET':
|
|
222
335
|
/* istanbul ignore else */
|
|
223
336
|
if (assertArgs(ex, 1)) {
|
|
224
337
|
assertMichelsonComparableType(ex.args[0]);
|
|
225
338
|
}
|
|
226
339
|
break;
|
|
227
|
-
case
|
|
340
|
+
case 'EMPTY_MAP':
|
|
228
341
|
/* istanbul ignore else */
|
|
229
342
|
if (assertArgs(ex, 2)) {
|
|
230
343
|
assertMichelsonComparableType(ex.args[0]);
|
|
231
344
|
assertMichelsonType(ex.args[1]);
|
|
232
345
|
}
|
|
233
346
|
break;
|
|
234
|
-
case
|
|
347
|
+
case 'EMPTY_BIG_MAP':
|
|
235
348
|
/* istanbul ignore else */
|
|
236
349
|
if (assertArgs(ex, 2)) {
|
|
237
350
|
assertMichelsonComparableType(ex.args[0]);
|
|
238
351
|
assertMichelsonBigMapStorableType(ex.args[1]);
|
|
239
352
|
}
|
|
240
353
|
break;
|
|
241
|
-
case
|
|
354
|
+
case 'LAMBDA':
|
|
242
355
|
/* istanbul ignore else */
|
|
243
356
|
if (assertArgs(ex, 3)) {
|
|
244
357
|
assertMichelsonType(ex.args[0]);
|
|
@@ -249,7 +362,7 @@ function assertMichelsonInstruction(ex) {
|
|
|
249
362
|
}
|
|
250
363
|
}
|
|
251
364
|
break;
|
|
252
|
-
case
|
|
365
|
+
case 'VIEW':
|
|
253
366
|
/* istanbul ignore else */
|
|
254
367
|
if (assertArgs(ex, 2)) {
|
|
255
368
|
if (assertStringLiteral(ex.args[0])) {
|
|
@@ -261,7 +374,7 @@ function assertMichelsonInstruction(ex) {
|
|
|
261
374
|
}
|
|
262
375
|
break;
|
|
263
376
|
default:
|
|
264
|
-
throw new MichelsonValidationError(ex,
|
|
377
|
+
throw new MichelsonValidationError(ex, 'instruction expected');
|
|
265
378
|
}
|
|
266
379
|
}
|
|
267
380
|
return true;
|
|
@@ -270,7 +383,7 @@ exports.assertMichelsonInstruction = assertMichelsonInstruction;
|
|
|
270
383
|
function assertMichelsonComparableType(ex) {
|
|
271
384
|
/* istanbul ignore else */
|
|
272
385
|
if (assertPrimOrSeq(ex)) {
|
|
273
|
-
if (Array.isArray(ex) || ex.prim ===
|
|
386
|
+
if (Array.isArray(ex) || ex.prim === 'pair' || ex.prim === 'or' || ex.prim === 'option') {
|
|
274
387
|
traverseType(ex, (ex) => assertMichelsonComparableType(ex));
|
|
275
388
|
}
|
|
276
389
|
else if (!Object.prototype.hasOwnProperty.call(simpleComparableTypeIDs, ex.prim)) {
|
|
@@ -285,10 +398,10 @@ function assertMichelsonPackableType(ex) {
|
|
|
285
398
|
if (assertPrimOrSeq(ex)) {
|
|
286
399
|
if (isPrim(ex)) {
|
|
287
400
|
if (!Object.prototype.hasOwnProperty.call(typeIDs, ex.prim) ||
|
|
288
|
-
ex.prim ===
|
|
289
|
-
ex.prim ===
|
|
290
|
-
ex.prim ===
|
|
291
|
-
ex.prim ===
|
|
401
|
+
ex.prim === 'big_map' ||
|
|
402
|
+
ex.prim === 'operation' ||
|
|
403
|
+
ex.prim === 'sapling_state' ||
|
|
404
|
+
ex.prim === 'ticket') {
|
|
292
405
|
throw new MichelsonValidationError(ex, `${ex.prim}: type can't be used inside PACK/UNPACK instructions`);
|
|
293
406
|
}
|
|
294
407
|
traverseType(ex, (ex) => assertMichelsonPackableType(ex));
|
|
@@ -302,11 +415,11 @@ function assertMichelsonPushableType(ex) {
|
|
|
302
415
|
if (assertPrimOrSeq(ex)) {
|
|
303
416
|
if (isPrim(ex)) {
|
|
304
417
|
if (!Object.prototype.hasOwnProperty.call(typeIDs, ex.prim) ||
|
|
305
|
-
ex.prim ===
|
|
306
|
-
ex.prim ===
|
|
307
|
-
ex.prim ===
|
|
308
|
-
ex.prim ===
|
|
309
|
-
ex.prim ===
|
|
418
|
+
ex.prim === 'big_map' ||
|
|
419
|
+
ex.prim === 'operation' ||
|
|
420
|
+
ex.prim === 'sapling_state' ||
|
|
421
|
+
ex.prim === 'ticket' ||
|
|
422
|
+
ex.prim === 'contract') {
|
|
310
423
|
throw new MichelsonValidationError(ex, `${ex.prim}: type can't be pushed`);
|
|
311
424
|
}
|
|
312
425
|
traverseType(ex, (ex) => assertMichelsonPushableType(ex));
|
|
@@ -320,8 +433,8 @@ function assertMichelsonStorableType(ex) {
|
|
|
320
433
|
if (assertPrimOrSeq(ex)) {
|
|
321
434
|
if (isPrim(ex)) {
|
|
322
435
|
if (!Object.prototype.hasOwnProperty.call(typeIDs, ex.prim) ||
|
|
323
|
-
ex.prim ===
|
|
324
|
-
ex.prim ===
|
|
436
|
+
ex.prim === 'operation' ||
|
|
437
|
+
ex.prim === 'contract') {
|
|
325
438
|
throw new MichelsonValidationError(ex, `${ex.prim}: type can't be used as part of a storage`);
|
|
326
439
|
}
|
|
327
440
|
traverseType(ex, (ex) => assertMichelsonStorableType(ex));
|
|
@@ -334,8 +447,7 @@ function assertMichelsonPassableType(ex) {
|
|
|
334
447
|
/* istanbul ignore else */
|
|
335
448
|
if (assertPrimOrSeq(ex)) {
|
|
336
449
|
if (isPrim(ex)) {
|
|
337
|
-
if (!Object.prototype.hasOwnProperty.call(typeIDs, ex.prim) ||
|
|
338
|
-
ex.prim === "operation") {
|
|
450
|
+
if (!Object.prototype.hasOwnProperty.call(typeIDs, ex.prim) || ex.prim === 'operation') {
|
|
339
451
|
throw new MichelsonValidationError(ex, `${ex.prim}: type can't be used as part of a parameter`);
|
|
340
452
|
}
|
|
341
453
|
traverseType(ex, (ex) => assertMichelsonPassableType(ex));
|
|
@@ -349,9 +461,9 @@ function assertMichelsonBigMapStorableType(ex) {
|
|
|
349
461
|
if (assertPrimOrSeq(ex)) {
|
|
350
462
|
if (isPrim(ex)) {
|
|
351
463
|
if (!Object.prototype.hasOwnProperty.call(typeIDs, ex.prim) ||
|
|
352
|
-
ex.prim ===
|
|
353
|
-
ex.prim ===
|
|
354
|
-
ex.prim ===
|
|
464
|
+
ex.prim === 'big_map' ||
|
|
465
|
+
ex.prim === 'operation' ||
|
|
466
|
+
ex.prim === 'sapling_state') {
|
|
355
467
|
throw new MichelsonValidationError(ex, `${ex.prim}: type can't be used inside a big_map`);
|
|
356
468
|
}
|
|
357
469
|
traverseType(ex, (ex) => assertMichelsonBigMapStorableType(ex));
|
|
@@ -360,7 +472,7 @@ function assertMichelsonBigMapStorableType(ex) {
|
|
|
360
472
|
return true;
|
|
361
473
|
}
|
|
362
474
|
exports.assertMichelsonBigMapStorableType = assertMichelsonBigMapStorableType;
|
|
363
|
-
const viewRe = new RegExp(
|
|
475
|
+
const viewRe = new RegExp('^[a-zA-Z0-9_.%@]*$');
|
|
364
476
|
function assertViewNameValid(name) {
|
|
365
477
|
if (name.string.length > maxViewNameLength) {
|
|
366
478
|
throw new MichelsonValidationError(name, `view name too long: ${name.string}`);
|
|
@@ -380,7 +492,7 @@ function assertMichelsonType(ex) {
|
|
|
380
492
|
if (assertPrimOrSeq(ex)) {
|
|
381
493
|
if (isPrim(ex)) {
|
|
382
494
|
if (!Object.prototype.hasOwnProperty.call(typeIDs, ex.prim)) {
|
|
383
|
-
throw new MichelsonValidationError(ex,
|
|
495
|
+
throw new MichelsonValidationError(ex, 'type expected');
|
|
384
496
|
}
|
|
385
497
|
traverseType(ex, (ex) => assertMichelsonType(ex));
|
|
386
498
|
}
|
|
@@ -389,12 +501,12 @@ function assertMichelsonType(ex) {
|
|
|
389
501
|
}
|
|
390
502
|
exports.assertMichelsonType = assertMichelsonType;
|
|
391
503
|
function traverseType(ex, cb) {
|
|
392
|
-
if (Array.isArray(ex) || ex.prim ===
|
|
504
|
+
if (Array.isArray(ex) || ex.prim === 'pair') {
|
|
393
505
|
const args = Array.isArray(ex) ? ex : ex.args;
|
|
394
506
|
if (args === undefined || args.length < 2) {
|
|
395
|
-
throw new MichelsonValidationError(ex,
|
|
507
|
+
throw new MichelsonValidationError(ex, 'at least 2 arguments expected');
|
|
396
508
|
}
|
|
397
|
-
args.forEach(a => {
|
|
509
|
+
args.forEach((a) => {
|
|
398
510
|
if (assertPrimOrSeq(a)) {
|
|
399
511
|
cb(a);
|
|
400
512
|
}
|
|
@@ -402,47 +514,47 @@ function traverseType(ex, cb) {
|
|
|
402
514
|
return true;
|
|
403
515
|
}
|
|
404
516
|
switch (ex.prim) {
|
|
405
|
-
case
|
|
406
|
-
case
|
|
517
|
+
case 'option':
|
|
518
|
+
case 'list':
|
|
407
519
|
/* istanbul ignore else */
|
|
408
520
|
if (assertArgs(ex, 1) && assertPrimOrSeq(ex.args[0])) {
|
|
409
521
|
cb(ex.args[0]);
|
|
410
522
|
}
|
|
411
523
|
break;
|
|
412
|
-
case
|
|
524
|
+
case 'contract':
|
|
413
525
|
/* istanbul ignore else */
|
|
414
526
|
if (assertArgs(ex, 1)) {
|
|
415
527
|
assertMichelsonPassableType(ex.args[0]);
|
|
416
528
|
}
|
|
417
529
|
break;
|
|
418
|
-
case
|
|
530
|
+
case 'or':
|
|
419
531
|
/* istanbul ignore else */
|
|
420
532
|
if (assertArgs(ex, 2) && assertPrimOrSeq(ex.args[0]) && assertPrimOrSeq(ex.args[1])) {
|
|
421
533
|
cb(ex.args[0]);
|
|
422
534
|
cb(ex.args[1]);
|
|
423
535
|
}
|
|
424
536
|
break;
|
|
425
|
-
case
|
|
537
|
+
case 'lambda':
|
|
426
538
|
/* istanbul ignore else */
|
|
427
539
|
if (assertArgs(ex, 2)) {
|
|
428
540
|
assertMichelsonType(ex.args[0]);
|
|
429
541
|
assertMichelsonType(ex.args[1]);
|
|
430
542
|
}
|
|
431
543
|
break;
|
|
432
|
-
case
|
|
544
|
+
case 'set':
|
|
433
545
|
/* istanbul ignore else */
|
|
434
546
|
if (assertArgs(ex, 1)) {
|
|
435
547
|
assertMichelsonComparableType(ex.args[0]);
|
|
436
548
|
}
|
|
437
549
|
break;
|
|
438
|
-
case
|
|
550
|
+
case 'map':
|
|
439
551
|
/* istanbul ignore else */
|
|
440
552
|
if (assertArgs(ex, 2) && assertPrimOrSeq(ex.args[0]) && assertPrimOrSeq(ex.args[1])) {
|
|
441
553
|
assertMichelsonComparableType(ex.args[0]);
|
|
442
554
|
cb(ex.args[1]);
|
|
443
555
|
}
|
|
444
556
|
break;
|
|
445
|
-
case
|
|
557
|
+
case 'big_map':
|
|
446
558
|
/* istanbul ignore else */
|
|
447
559
|
if (assertArgs(ex, 2) && assertPrimOrSeq(ex.args[0]) && assertPrimOrSeq(ex.args[1])) {
|
|
448
560
|
assertMichelsonComparableType(ex.args[0]);
|
|
@@ -450,14 +562,14 @@ function traverseType(ex, cb) {
|
|
|
450
562
|
cb(ex.args[1]);
|
|
451
563
|
}
|
|
452
564
|
break;
|
|
453
|
-
case
|
|
565
|
+
case 'ticket':
|
|
454
566
|
/* istanbul ignore else */
|
|
455
567
|
if (assertArgs(ex, 1) && assertPrimOrSeq(ex.args[0])) {
|
|
456
568
|
assertMichelsonComparableType(ex.args[0]);
|
|
457
569
|
}
|
|
458
570
|
break;
|
|
459
|
-
case
|
|
460
|
-
case
|
|
571
|
+
case 'sapling_state':
|
|
572
|
+
case 'sapling_transaction':
|
|
461
573
|
if (assertArgs(ex, 1)) {
|
|
462
574
|
assertIntLiteral(ex.args[0]);
|
|
463
575
|
}
|
|
@@ -473,13 +585,13 @@ function traverseType(ex, cb) {
|
|
|
473
585
|
* @param ex An AST node
|
|
474
586
|
*/
|
|
475
587
|
function assertMichelsonData(ex) {
|
|
476
|
-
if (
|
|
588
|
+
if ('int' in ex || 'string' in ex || 'bytes' in ex) {
|
|
477
589
|
return true;
|
|
478
590
|
}
|
|
479
591
|
if (Array.isArray(ex)) {
|
|
480
592
|
let mapElts = 0;
|
|
481
593
|
for (const n of ex) {
|
|
482
|
-
if (isPrim(n) && n.prim ===
|
|
594
|
+
if (isPrim(n) && n.prim === 'Elt') {
|
|
483
595
|
/* istanbul ignore else */
|
|
484
596
|
if (assertArgs(n, 2)) {
|
|
485
597
|
assertMichelsonData(n.args[0]);
|
|
@@ -498,24 +610,24 @@ function assertMichelsonData(ex) {
|
|
|
498
610
|
}
|
|
499
611
|
if (isPrim(ex)) {
|
|
500
612
|
switch (ex.prim) {
|
|
501
|
-
case
|
|
502
|
-
case
|
|
503
|
-
case
|
|
504
|
-
case
|
|
613
|
+
case 'Unit':
|
|
614
|
+
case 'True':
|
|
615
|
+
case 'False':
|
|
616
|
+
case 'None':
|
|
505
617
|
assertArgs(ex, 0);
|
|
506
618
|
break;
|
|
507
|
-
case
|
|
619
|
+
case 'Pair':
|
|
508
620
|
/* istanbul ignore else */
|
|
509
621
|
if (ex.args === undefined || ex.args.length < 2) {
|
|
510
|
-
throw new MichelsonValidationError(ex,
|
|
622
|
+
throw new MichelsonValidationError(ex, 'at least 2 arguments expected');
|
|
511
623
|
}
|
|
512
624
|
for (const a of ex.args) {
|
|
513
625
|
assertMichelsonData(a);
|
|
514
626
|
}
|
|
515
627
|
break;
|
|
516
|
-
case
|
|
517
|
-
case
|
|
518
|
-
case
|
|
628
|
+
case 'Left':
|
|
629
|
+
case 'Right':
|
|
630
|
+
case 'Some':
|
|
519
631
|
/* istanbul ignore else */
|
|
520
632
|
if (assertArgs(ex, 1)) {
|
|
521
633
|
assertMichelsonData(ex.args[0]);
|
|
@@ -526,12 +638,12 @@ function assertMichelsonData(ex) {
|
|
|
526
638
|
assertMichelsonInstruction(ex);
|
|
527
639
|
}
|
|
528
640
|
else {
|
|
529
|
-
throw new MichelsonValidationError(ex,
|
|
641
|
+
throw new MichelsonValidationError(ex, 'data entry or instruction expected');
|
|
530
642
|
}
|
|
531
643
|
}
|
|
532
644
|
}
|
|
533
645
|
else {
|
|
534
|
-
throw new MichelsonValidationError(ex,
|
|
646
|
+
throw new MichelsonValidationError(ex, 'data entry expected');
|
|
535
647
|
}
|
|
536
648
|
return true;
|
|
537
649
|
}
|
|
@@ -548,7 +660,7 @@ function assertMichelsonContract(ex) {
|
|
|
548
660
|
const views = {};
|
|
549
661
|
for (const sec of ex) {
|
|
550
662
|
if (assertPrim(sec)) {
|
|
551
|
-
if (sec.prim !==
|
|
663
|
+
if (sec.prim !== 'view') {
|
|
552
664
|
if (sec.prim in toplevelSec) {
|
|
553
665
|
throw new MichelsonValidationError(ex, `duplicate contract section: ${sec.prim}`);
|
|
554
666
|
}
|
|
@@ -556,7 +668,7 @@ function assertMichelsonContract(ex) {
|
|
|
556
668
|
}
|
|
557
669
|
/* istanbul ignore else */
|
|
558
670
|
switch (sec.prim) {
|
|
559
|
-
case
|
|
671
|
+
case 'code':
|
|
560
672
|
if (assertArgs(sec, 1)) {
|
|
561
673
|
/* istanbul ignore else */
|
|
562
674
|
if (assertSeq(sec.args[0])) {
|
|
@@ -564,17 +676,17 @@ function assertMichelsonContract(ex) {
|
|
|
564
676
|
}
|
|
565
677
|
}
|
|
566
678
|
break;
|
|
567
|
-
case
|
|
679
|
+
case 'parameter':
|
|
568
680
|
if (assertArgs(sec, 1)) {
|
|
569
681
|
assertMichelsonPassableType(sec.args[0]);
|
|
570
682
|
}
|
|
571
683
|
break;
|
|
572
|
-
case
|
|
684
|
+
case 'storage':
|
|
573
685
|
if (assertArgs(sec, 1)) {
|
|
574
686
|
assertMichelsonStorableType(sec.args[0]);
|
|
575
687
|
}
|
|
576
688
|
break;
|
|
577
|
-
case
|
|
689
|
+
case 'view':
|
|
578
690
|
if (assertArgs(sec, 4)) {
|
|
579
691
|
if (assertStringLiteral(sec.args[0])) {
|
|
580
692
|
const name = sec.args[0];
|
|
@@ -665,11 +777,11 @@ function assertDataListIfAny(d) {
|
|
|
665
777
|
return false;
|
|
666
778
|
}
|
|
667
779
|
for (const v of d) {
|
|
668
|
-
if (
|
|
780
|
+
if ('prim' in v) {
|
|
669
781
|
if (isInstruction(v)) {
|
|
670
782
|
throw new utils_1.MichelsonError(d, `Instruction outside of a lambda: ${JSON.stringify(d)}`);
|
|
671
783
|
}
|
|
672
|
-
else if (v.prim ===
|
|
784
|
+
else if (v.prim === 'Elt') {
|
|
673
785
|
throw new utils_1.MichelsonError(d, `Elt item outside of a map literal: ${JSON.stringify(d)}`);
|
|
674
786
|
}
|
|
675
787
|
}
|