@taquito/michel-codec 24.2.0-beta.1 → 24.3.0-beta.0
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/dist/lib/base58.js +1 -1
- package/dist/lib/binary.js +2 -3
- package/dist/lib/errors.js +7 -7
- package/dist/lib/formatters.js +2 -4
- package/dist/lib/macros.js +9 -6
- package/dist/lib/micheline-emitter.js +4 -8
- package/dist/lib/micheline-parser.js +13 -14
- package/dist/lib/michelson-contract.js +3 -3
- package/dist/lib/michelson-typecheck.js +61 -57
- package/dist/lib/michelson-validator.js +7 -9
- package/dist/lib/scan.js +1 -1
- package/dist/lib/utils.js +12 -10
- package/dist/lib/version.js +2 -2
- package/dist/taquito-michel-codec.es6.js +124 -148
- package/dist/taquito-michel-codec.es6.js.map +1 -1
- package/dist/taquito-michel-codec.umd.js +124 -148
- package/dist/taquito-michel-codec.umd.js.map +1 -1
- package/dist/types/base58.d.ts +1 -1
- package/dist/types/errors.d.ts +7 -7
- package/dist/types/macros.d.ts +1 -1
- package/dist/types/micheline-parser.d.ts +2 -2
- package/dist/types/scan.d.ts +1 -1
- package/dist/types/utils.d.ts +1 -2
- package/package.json +22 -8
- package/LICENSE +0 -202
package/dist/lib/base58.js
CHANGED
|
@@ -84,7 +84,7 @@ const K = [
|
|
|
84
84
|
];
|
|
85
85
|
/**
|
|
86
86
|
* @category Error
|
|
87
|
-
*
|
|
87
|
+
* Error that indicates a failure when decoding a base58 encoding
|
|
88
88
|
*/
|
|
89
89
|
class Base58DecodingError extends core_1.TaquitoError {
|
|
90
90
|
constructor(message) {
|
package/dist/lib/binary.js
CHANGED
|
@@ -439,7 +439,6 @@ function writePublicKey(pk, w) {
|
|
|
439
439
|
w.writeBytes(Array.from(pk.publicKey));
|
|
440
440
|
}
|
|
441
441
|
function writeExpr(expr, wr, tf) {
|
|
442
|
-
var _a, _b;
|
|
443
442
|
const [e, args] = tf(expr);
|
|
444
443
|
if (Array.isArray(e)) {
|
|
445
444
|
const w = new Writer();
|
|
@@ -497,9 +496,9 @@ function writeExpr(expr, wr, tf) {
|
|
|
497
496
|
if (prim === undefined) {
|
|
498
497
|
throw new TypeError(`Can't encode primary: ${e.prim}`);
|
|
499
498
|
}
|
|
500
|
-
const tag = (
|
|
499
|
+
const tag = (e.args?.length || 0) < 3
|
|
501
500
|
? Tag.Prim0 +
|
|
502
|
-
(
|
|
501
|
+
(e.args?.length || 0) * 2 +
|
|
503
502
|
(e.annots === undefined || e.annots.length === 0 ? 0 : 1)
|
|
504
503
|
: Tag.Prim;
|
|
505
504
|
wr.writeUint8(tag);
|
package/dist/lib/errors.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.HexParseError = exports.LongIntegerError = exports.TezosIdEncodeError =
|
|
|
4
4
|
const core_1 = require("@taquito/core");
|
|
5
5
|
/**
|
|
6
6
|
* @category Error
|
|
7
|
-
*
|
|
7
|
+
* Error that indicates an invalid Michelson being passed or used
|
|
8
8
|
*/
|
|
9
9
|
class InvalidMichelsonError extends core_1.ParameterValidationError {
|
|
10
10
|
constructor(message) {
|
|
@@ -16,7 +16,7 @@ class InvalidMichelsonError extends core_1.ParameterValidationError {
|
|
|
16
16
|
exports.InvalidMichelsonError = InvalidMichelsonError;
|
|
17
17
|
/**
|
|
18
18
|
* @category Error
|
|
19
|
-
*
|
|
19
|
+
* Error that indicates an invalid type expression being passed or used
|
|
20
20
|
*/
|
|
21
21
|
class InvalidTypeExpressionError extends core_1.ParameterValidationError {
|
|
22
22
|
constructor(message) {
|
|
@@ -28,7 +28,7 @@ class InvalidTypeExpressionError extends core_1.ParameterValidationError {
|
|
|
28
28
|
exports.InvalidTypeExpressionError = InvalidTypeExpressionError;
|
|
29
29
|
/**
|
|
30
30
|
* @category Error
|
|
31
|
-
*
|
|
31
|
+
* Error that indicates an invalid data expression being passed or used
|
|
32
32
|
*/
|
|
33
33
|
class InvalidDataExpressionError extends core_1.ParameterValidationError {
|
|
34
34
|
constructor(message) {
|
|
@@ -40,7 +40,7 @@ class InvalidDataExpressionError extends core_1.ParameterValidationError {
|
|
|
40
40
|
exports.InvalidDataExpressionError = InvalidDataExpressionError;
|
|
41
41
|
/**
|
|
42
42
|
* @category Error
|
|
43
|
-
*
|
|
43
|
+
* Error that indicates an invalid contract entrypoint being referenced or passed
|
|
44
44
|
*/
|
|
45
45
|
class InvalidEntrypointError extends core_1.ParameterValidationError {
|
|
46
46
|
constructor(entrypoint) {
|
|
@@ -53,7 +53,7 @@ class InvalidEntrypointError extends core_1.ParameterValidationError {
|
|
|
53
53
|
exports.InvalidEntrypointError = InvalidEntrypointError;
|
|
54
54
|
/**
|
|
55
55
|
* @category Error
|
|
56
|
-
*
|
|
56
|
+
* Error that indicates a failure happening when trying to encode Tezos ID
|
|
57
57
|
*/
|
|
58
58
|
class TezosIdEncodeError extends core_1.ParameterValidationError {
|
|
59
59
|
constructor(message) {
|
|
@@ -65,7 +65,7 @@ class TezosIdEncodeError extends core_1.ParameterValidationError {
|
|
|
65
65
|
exports.TezosIdEncodeError = TezosIdEncodeError;
|
|
66
66
|
/**
|
|
67
67
|
* @category Error
|
|
68
|
-
*
|
|
68
|
+
* Error that indicates a general error happening when trying to create a LongInteger
|
|
69
69
|
*/
|
|
70
70
|
class LongIntegerError extends core_1.TaquitoError {
|
|
71
71
|
constructor(message) {
|
|
@@ -77,7 +77,7 @@ class LongIntegerError extends core_1.TaquitoError {
|
|
|
77
77
|
exports.LongIntegerError = LongIntegerError;
|
|
78
78
|
/**
|
|
79
79
|
* @category Error
|
|
80
|
-
*
|
|
80
|
+
* Error that indicates a failure occurring when trying to parse a hex byte
|
|
81
81
|
*/
|
|
82
82
|
class HexParseError extends core_1.TaquitoError {
|
|
83
83
|
constructor(hexByte) {
|
package/dist/lib/formatters.js
CHANGED
|
@@ -20,11 +20,10 @@ function formatStack(s) {
|
|
|
20
20
|
}
|
|
21
21
|
function traceDumpFunc(blocks, cb) {
|
|
22
22
|
return (v) => {
|
|
23
|
-
var _a;
|
|
24
23
|
if (Array.isArray(v) && !blocks) {
|
|
25
24
|
return;
|
|
26
25
|
}
|
|
27
|
-
const macro =
|
|
26
|
+
const macro = v.op[micheline_1.sourceReference]?.macro;
|
|
28
27
|
const msg = `${macro ? 'Macro' : 'Op'}: ${macro ? (0, micheline_emitter_1.emitMicheline)(macro, undefined, true) + ' / ' : ''}${(0, micheline_emitter_1.emitMicheline)(v.op)}
|
|
29
28
|
Input:
|
|
30
29
|
${formatStack(v.in)}
|
|
@@ -35,9 +34,8 @@ ${formatStack(v.out)}
|
|
|
35
34
|
};
|
|
36
35
|
}
|
|
37
36
|
function formatError(err) {
|
|
38
|
-
var _a;
|
|
39
37
|
if (err instanceof michelson_typecheck_1.MichelsonInstructionError) {
|
|
40
|
-
const macro =
|
|
38
|
+
const macro = err.val[micheline_1.sourceReference]?.macro;
|
|
41
39
|
return `${macro ? 'Macro' : 'Op'}: ${macro ? (0, micheline_emitter_1.emitMicheline)(macro, undefined, true) + ' / ' : ''}${(0, micheline_emitter_1.emitMicheline)(err.val)}
|
|
42
40
|
Stack:
|
|
43
41
|
${formatStack(err.stackState)}
|
package/dist/lib/macros.js
CHANGED
|
@@ -6,7 +6,7 @@ const core_1 = require("@taquito/core");
|
|
|
6
6
|
const michelson_types_1 = require("./michelson-types");
|
|
7
7
|
/**
|
|
8
8
|
* @category Error
|
|
9
|
-
*
|
|
9
|
+
* Error that indicates macros failed to be expanded
|
|
10
10
|
*/
|
|
11
11
|
class MacroError extends core_1.TaquitoError {
|
|
12
12
|
constructor(prim, message) {
|
|
@@ -18,11 +18,10 @@ class MacroError extends core_1.TaquitoError {
|
|
|
18
18
|
}
|
|
19
19
|
exports.MacroError = MacroError;
|
|
20
20
|
function assertArgs(ex, n) {
|
|
21
|
-
|
|
22
|
-
if ((n === 0 && ex.args === undefined) || ((_a = ex.args) === null || _a === void 0 ? void 0 : _a.length) === n) {
|
|
21
|
+
if ((n === 0 && ex.args === undefined) || ex.args?.length === n) {
|
|
23
22
|
return true;
|
|
24
23
|
}
|
|
25
|
-
throw new MacroError(ex, `macro ${ex.prim} expects ${n} arguments, was given ${
|
|
24
|
+
throw new MacroError(ex, `macro ${ex.prim} expects ${n} arguments, was given ${ex.args?.length}`);
|
|
26
25
|
}
|
|
27
26
|
function assertNoAnnots(ex) {
|
|
28
27
|
if (ex.annots === undefined) {
|
|
@@ -140,7 +139,11 @@ function filterAnnotations(a) {
|
|
|
140
139
|
return { fields, rest };
|
|
141
140
|
}
|
|
142
141
|
function mkPrim({ prim, annots, args }) {
|
|
143
|
-
return
|
|
142
|
+
return {
|
|
143
|
+
prim,
|
|
144
|
+
...(annots && { annots }),
|
|
145
|
+
...(args && { args }),
|
|
146
|
+
};
|
|
144
147
|
}
|
|
145
148
|
const pairRe = /^P[PAI]{3,}R$/;
|
|
146
149
|
const unpairRe = /^UNP[PAI]{2,}R$/;
|
|
@@ -150,7 +153,7 @@ const mapCadrRe = /^MAP_C[AD]+R$/;
|
|
|
150
153
|
const diipRe = /^DI{2,}P$/;
|
|
151
154
|
const duupRe = /^DU+P$/;
|
|
152
155
|
function expandMacros(ex, opt) {
|
|
153
|
-
const proto =
|
|
156
|
+
const proto = opt?.protocol || michelson_types_1.DefaultProtocol;
|
|
154
157
|
function mayRename(annots) {
|
|
155
158
|
return annots !== undefined ? [{ prim: 'RENAME', annots }] : [];
|
|
156
159
|
}
|
|
@@ -8,9 +8,8 @@ class Formatter {
|
|
|
8
8
|
this.lev = lev;
|
|
9
9
|
}
|
|
10
10
|
indent(n = 0) {
|
|
11
|
-
var _a;
|
|
12
11
|
let ret = '';
|
|
13
|
-
if (
|
|
12
|
+
if (this.opt?.indent !== undefined) {
|
|
14
13
|
for (let i = this.lev + n; i > 0; i--) {
|
|
15
14
|
ret += this.opt.indent;
|
|
16
15
|
}
|
|
@@ -18,12 +17,10 @@ class Formatter {
|
|
|
18
17
|
return ret;
|
|
19
18
|
}
|
|
20
19
|
get lf() {
|
|
21
|
-
|
|
22
|
-
return ((_a = this.opt) === null || _a === void 0 ? void 0 : _a.newline) || '';
|
|
20
|
+
return this.opt?.newline || '';
|
|
23
21
|
}
|
|
24
22
|
get lfsp() {
|
|
25
|
-
|
|
26
|
-
return ((_a = this.opt) === null || _a === void 0 ? void 0 : _a.newline) || ' ';
|
|
23
|
+
return this.opt?.newline || ' ';
|
|
27
24
|
}
|
|
28
25
|
down(n) {
|
|
29
26
|
return new Formatter(this.opt, this.lev + n);
|
|
@@ -45,8 +42,7 @@ function isMultiline(node) {
|
|
|
45
42
|
return false;
|
|
46
43
|
}
|
|
47
44
|
function emitExpr(node, f, foldMacros) {
|
|
48
|
-
|
|
49
|
-
const macro = (_a = node[micheline_1.sourceReference]) === null || _a === void 0 ? void 0 : _a.macro;
|
|
45
|
+
const macro = node[micheline_1.sourceReference]?.macro;
|
|
50
46
|
if (foldMacros && macro) {
|
|
51
47
|
return emitExpr(macro, f, foldMacros);
|
|
52
48
|
}
|
|
@@ -8,7 +8,7 @@ const global_constants_1 = require("./global-constants");
|
|
|
8
8
|
const core_1 = require("@taquito/core");
|
|
9
9
|
/**
|
|
10
10
|
* @category Error
|
|
11
|
-
*
|
|
11
|
+
* Error that indicates a failure when parsing Micheline expressions
|
|
12
12
|
*/
|
|
13
13
|
class MichelineParseError extends core_1.TaquitoError {
|
|
14
14
|
/**
|
|
@@ -25,7 +25,7 @@ class MichelineParseError extends core_1.TaquitoError {
|
|
|
25
25
|
exports.MichelineParseError = MichelineParseError;
|
|
26
26
|
/**
|
|
27
27
|
* @category Error
|
|
28
|
-
*
|
|
28
|
+
* Error indicates a failure when parsing Micheline JSON
|
|
29
29
|
*/
|
|
30
30
|
class JSONParseError extends core_1.TaquitoError {
|
|
31
31
|
/**
|
|
@@ -83,18 +83,20 @@ class Parser {
|
|
|
83
83
|
this.opt = opt;
|
|
84
84
|
}
|
|
85
85
|
expand(ex) {
|
|
86
|
-
|
|
87
|
-
if (((_a = this.opt) === null || _a === void 0 ? void 0 : _a.expandGlobalConstant) !== undefined && ex.prim === 'constant') {
|
|
86
|
+
if (this.opt?.expandGlobalConstant !== undefined && ex.prim === 'constant') {
|
|
88
87
|
const ret = (0, global_constants_1.expandGlobalConstants)(ex, this.opt.expandGlobalConstant);
|
|
89
88
|
if (ret !== ex) {
|
|
90
|
-
ret[micheline_1.sourceReference] =
|
|
89
|
+
ret[micheline_1.sourceReference] = {
|
|
90
|
+
...(ex[micheline_1.sourceReference] || { first: 0, last: 0 }),
|
|
91
|
+
globalConstant: ex,
|
|
92
|
+
};
|
|
91
93
|
}
|
|
92
94
|
return ret;
|
|
93
95
|
}
|
|
94
|
-
if (
|
|
96
|
+
if (this.opt?.expandMacros !== undefined ? this.opt?.expandMacros : true) {
|
|
95
97
|
const ret = (0, macros_1.expandMacros)(ex, this.opt);
|
|
96
98
|
if (ret !== ex) {
|
|
97
|
-
ret[micheline_1.sourceReference] =
|
|
99
|
+
ret[micheline_1.sourceReference] = { ...(ex[micheline_1.sourceReference] || { first: 0, last: 0 }), macro: ex };
|
|
98
100
|
}
|
|
99
101
|
return ret;
|
|
100
102
|
}
|
|
@@ -103,7 +105,6 @@ class Parser {
|
|
|
103
105
|
}
|
|
104
106
|
}
|
|
105
107
|
parseListExpr(scanner, start) {
|
|
106
|
-
var _a;
|
|
107
108
|
const ref = {
|
|
108
109
|
first: start.first,
|
|
109
110
|
last: start.last,
|
|
@@ -150,14 +151,13 @@ class Parser {
|
|
|
150
151
|
else {
|
|
151
152
|
ret.args = ret.args || [];
|
|
152
153
|
const arg = this.parseExpr(scanner, tok.value);
|
|
153
|
-
ref.last =
|
|
154
|
+
ref.last = arg[micheline_1.sourceReference]?.last || ref.last;
|
|
154
155
|
ret.args.push(arg);
|
|
155
156
|
}
|
|
156
157
|
}
|
|
157
158
|
return this.expand(ret);
|
|
158
159
|
}
|
|
159
160
|
parseArgs(scanner, start) {
|
|
160
|
-
var _a;
|
|
161
161
|
// Identifier with arguments
|
|
162
162
|
const ref = {
|
|
163
163
|
first: start.first,
|
|
@@ -179,14 +179,13 @@ class Parser {
|
|
|
179
179
|
}
|
|
180
180
|
else {
|
|
181
181
|
const arg = this.parseExpr(scanner, t.value);
|
|
182
|
-
ref.last =
|
|
182
|
+
ref.last = arg[micheline_1.sourceReference]?.last || ref.last;
|
|
183
183
|
p.args = p.args || [];
|
|
184
184
|
p.args.push(arg);
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
188
|
parseSequenceExpr(scanner, start) {
|
|
189
|
-
var _a, _b;
|
|
190
189
|
const ref = {
|
|
191
190
|
first: start.first,
|
|
192
191
|
last: start.last,
|
|
@@ -221,14 +220,14 @@ class Parser {
|
|
|
221
220
|
else if (tok.value.t === scan_1.Literal.Ident) {
|
|
222
221
|
// Identifier with arguments
|
|
223
222
|
const [itm, n] = this.parseArgs(scanner, tok.value);
|
|
224
|
-
ref.last =
|
|
223
|
+
ref.last = itm[micheline_1.sourceReference]?.last || ref.last;
|
|
225
224
|
seq.push(this.expand(itm));
|
|
226
225
|
tok = n;
|
|
227
226
|
}
|
|
228
227
|
else {
|
|
229
228
|
// Other
|
|
230
229
|
const ex = this.parseExpr(scanner, tok.value);
|
|
231
|
-
ref.last =
|
|
230
|
+
ref.last = ex[micheline_1.sourceReference]?.last || ref.last;
|
|
232
231
|
seq.push(ex);
|
|
233
232
|
tok = null;
|
|
234
233
|
}
|
|
@@ -8,7 +8,7 @@ const errors_1 = require("./errors");
|
|
|
8
8
|
class Contract {
|
|
9
9
|
constructor(contract, opt) {
|
|
10
10
|
this.contract = contract;
|
|
11
|
-
this.ctx =
|
|
11
|
+
this.ctx = { contract, ...opt };
|
|
12
12
|
this.output = (0, michelson_typecheck_1.assertContractValid)(contract, this.ctx);
|
|
13
13
|
}
|
|
14
14
|
static parse(src, opt) {
|
|
@@ -64,7 +64,7 @@ class Contract {
|
|
|
64
64
|
assertParameterValid(ep, d) {
|
|
65
65
|
const t = this.entryPoint(ep || undefined);
|
|
66
66
|
if (t === null) {
|
|
67
|
-
throw new errors_1.InvalidEntrypointError(ep
|
|
67
|
+
throw new errors_1.InvalidEntrypointError(ep?.toString());
|
|
68
68
|
}
|
|
69
69
|
this.assertDataValid(d, t);
|
|
70
70
|
}
|
|
@@ -73,7 +73,7 @@ class Contract {
|
|
|
73
73
|
this.assertParameterValid(ep, d);
|
|
74
74
|
return true;
|
|
75
75
|
}
|
|
76
|
-
catch
|
|
76
|
+
catch {
|
|
77
77
|
return false;
|
|
78
78
|
}
|
|
79
79
|
}
|
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.MichelsonInstructionError = void 0;
|
|
15
4
|
exports.assertTypeAnnotationsValid = assertTypeAnnotationsValid;
|
|
@@ -104,19 +93,18 @@ function assertStacksEqual(a, b) {
|
|
|
104
93
|
}
|
|
105
94
|
}
|
|
106
95
|
function assertTypeAnnotationsValid(t, field = false) {
|
|
107
|
-
var _a, _b, _c;
|
|
108
96
|
if (!Array.isArray(t)) {
|
|
109
97
|
const ann = (0, utils_1.unpackAnnotations)(t);
|
|
110
|
-
if ((
|
|
98
|
+
if ((ann.t?.length || 0) > 1) {
|
|
111
99
|
throw new utils_1.MichelsonTypeError(t, `${t.prim}: at most one type annotation allowed: ${t.annots}`, undefined);
|
|
112
100
|
}
|
|
113
101
|
if (field) {
|
|
114
|
-
if ((
|
|
102
|
+
if ((ann.f?.length || 0) > 1) {
|
|
115
103
|
throw new utils_1.MichelsonTypeError(t, `${t.prim}: at most one field annotation allowed: ${t.annots}`, undefined);
|
|
116
104
|
}
|
|
117
105
|
}
|
|
118
106
|
else {
|
|
119
|
-
if ((
|
|
107
|
+
if ((ann.f?.length || 0) > 0) {
|
|
120
108
|
throw new utils_1.MichelsonTypeError(t, `${t.prim}: field annotations aren't allowed: ${t.annots}`, undefined);
|
|
121
109
|
}
|
|
122
110
|
}
|
|
@@ -466,7 +454,7 @@ function instructionListType(inst, stack, ctx) {
|
|
|
466
454
|
i !== inst.length - 1) {
|
|
467
455
|
throw new MichelsonInstructionError(inst, ret, 'FAIL must appear in a tail position');
|
|
468
456
|
}
|
|
469
|
-
if (
|
|
457
|
+
if (ctx?.traceCallback !== undefined) {
|
|
470
458
|
const trace = {
|
|
471
459
|
op: inst,
|
|
472
460
|
in: stack,
|
|
@@ -477,7 +465,7 @@ function instructionListType(inst, stack, ctx) {
|
|
|
477
465
|
return 'failed' in ret ? { failed: ret.failed, level: ret.level + 1 } : ret;
|
|
478
466
|
}
|
|
479
467
|
function functionTypeInternal(inst, stack, ctx) {
|
|
480
|
-
const proto =
|
|
468
|
+
const proto = ctx?.protocol || michelson_types_1.DefaultProtocol;
|
|
481
469
|
if (Array.isArray(inst)) {
|
|
482
470
|
return instructionListType(inst, stack, ctx);
|
|
483
471
|
}
|
|
@@ -542,7 +530,11 @@ function functionTypeInternal(inst, stack, ctx) {
|
|
|
542
530
|
const ensureBigMapStorableType = rethrowTypeGuard(michelson_validator_1.assertMichelsonBigMapStorableType);
|
|
543
531
|
// unpack instruction annotations and assert their maximum number
|
|
544
532
|
function instructionAnn(num, opt) {
|
|
545
|
-
const a = argAnn(instruction,
|
|
533
|
+
const a = argAnn(instruction, {
|
|
534
|
+
...opt,
|
|
535
|
+
emptyFields: num.f !== undefined && num.f > 1,
|
|
536
|
+
emptyVar: num.v !== undefined && num.v > 1,
|
|
537
|
+
});
|
|
546
538
|
const assertNum = (a, n, type) => {
|
|
547
539
|
if (a && a.length > (n || 0)) {
|
|
548
540
|
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: at most ${n || 0} ${type} annotations allowed`);
|
|
@@ -565,8 +557,8 @@ function functionTypeInternal(inst, stack, ctx) {
|
|
|
565
557
|
...((a.f === null ? src.f : a.f) || []),
|
|
566
558
|
]
|
|
567
559
|
: undefined;
|
|
568
|
-
const { annots: _annots
|
|
569
|
-
return
|
|
560
|
+
const { annots: _annots, ...rest } = t;
|
|
561
|
+
return { ...rest, ...(ann && ann.length !== 0 && { annots: ann }) };
|
|
570
562
|
}
|
|
571
563
|
// shortcut to copy at most one variable annotation from the instruction to the type
|
|
572
564
|
function annotateVar(t, def) {
|
|
@@ -578,17 +570,16 @@ function functionTypeInternal(inst, stack, ctx) {
|
|
|
578
570
|
}
|
|
579
571
|
// annotate CAR/CDR/UNPAIR/GET
|
|
580
572
|
function annotateField(arg, field, insAnn, n, defField) {
|
|
581
|
-
|
|
582
|
-
const
|
|
583
|
-
const insFieldAnn = (_b = insAnn.f) === null || _b === void 0 ? void 0 : _b[n];
|
|
573
|
+
const fieldAnn = argAnn(field).f?.[0]; // field's field annotation
|
|
574
|
+
const insFieldAnn = insAnn.f?.[n];
|
|
584
575
|
if (insFieldAnn !== undefined &&
|
|
585
576
|
insFieldAnn !== '%' &&
|
|
586
577
|
fieldAnn !== undefined &&
|
|
587
578
|
insFieldAnn !== fieldAnn) {
|
|
588
579
|
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: field names doesn't match: ${insFieldAnn} !== ${fieldAnn}`);
|
|
589
580
|
}
|
|
590
|
-
const insVarAnn =
|
|
591
|
-
const varAnn =
|
|
581
|
+
const insVarAnn = insAnn.v?.[n]; // nth instruction's variable annotation
|
|
582
|
+
const varAnn = argAnn(arg).v?.[0]; // instruction argument's variable annotation
|
|
592
583
|
return annotate(field, {
|
|
593
584
|
t: null,
|
|
594
585
|
v: insVarAnn
|
|
@@ -646,14 +637,23 @@ function functionTypeInternal(inst, stack, ctx) {
|
|
|
646
637
|
}
|
|
647
638
|
const p = (0, utils_1.unpackComb)('pair', src);
|
|
648
639
|
if (i === 1) {
|
|
649
|
-
return
|
|
640
|
+
return {
|
|
641
|
+
...p,
|
|
642
|
+
args: [x, p.args[1]],
|
|
643
|
+
};
|
|
650
644
|
}
|
|
651
645
|
const right = p.args[1];
|
|
652
646
|
if ((0, utils_1.isPairType)(right)) {
|
|
653
|
-
return
|
|
647
|
+
return {
|
|
648
|
+
...p,
|
|
649
|
+
args: [p.args[0], updateNth(right, x, n, i - 2)],
|
|
650
|
+
};
|
|
654
651
|
}
|
|
655
652
|
else if (i === 2) {
|
|
656
|
-
return
|
|
653
|
+
return {
|
|
654
|
+
...p,
|
|
655
|
+
args: [p.args[0], x],
|
|
656
|
+
};
|
|
657
657
|
}
|
|
658
658
|
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: at least ${n + 1} fields are expected`);
|
|
659
659
|
}
|
|
@@ -670,7 +670,6 @@ function functionTypeInternal(inst, stack, ctx) {
|
|
|
670
670
|
}
|
|
671
671
|
}
|
|
672
672
|
const retStack = ((instruction) => {
|
|
673
|
-
var _a, _b, _c, _d, _e;
|
|
674
673
|
switch (instruction.prim) {
|
|
675
674
|
case 'DUP': {
|
|
676
675
|
const n = instruction.args ? parseInt(instruction.args[0].int, 10) : 1;
|
|
@@ -707,12 +706,11 @@ function functionTypeInternal(inst, stack, ctx) {
|
|
|
707
706
|
return s.slice(i > 0 ? i + 1 : 1);
|
|
708
707
|
};
|
|
709
708
|
const retArgs = s.map((v, i) => {
|
|
710
|
-
var _a;
|
|
711
709
|
const va = argAnn(v);
|
|
712
710
|
const f = ia.f && ia.f.length > i && ia.f[i] !== '%'
|
|
713
711
|
? ia.f[i] === '%@'
|
|
714
712
|
? va.v
|
|
715
|
-
? ['%' + trim(
|
|
713
|
+
? ['%' + trim(va.v?.[0] || '')]
|
|
716
714
|
: undefined
|
|
717
715
|
: [ia.f[i]]
|
|
718
716
|
: undefined;
|
|
@@ -825,24 +823,24 @@ function functionTypeInternal(inst, stack, ctx) {
|
|
|
825
823
|
ensureComparableType(s[0]);
|
|
826
824
|
ensureTypesEqual(s[0], s[2].args[0]);
|
|
827
825
|
ensureTypesEqual(s[1].args[0], s[2].args[1]);
|
|
828
|
-
const va =
|
|
826
|
+
const va = ia.v?.map((v) => (v !== '@' ? [v] : undefined));
|
|
829
827
|
if (s[2].prim === 'map') {
|
|
830
828
|
return [
|
|
831
|
-
annotate({ prim: 'option', args: [s[2].args[1]] }, { v: va
|
|
829
|
+
annotate({ prim: 'option', args: [s[2].args[1]] }, { v: va?.[0] }),
|
|
832
830
|
annotate({
|
|
833
831
|
prim: 'map',
|
|
834
832
|
args: [annotate(s[0], { t: null }), annotate(s[1].args[0], { t: null })],
|
|
835
|
-
}, { v: va
|
|
833
|
+
}, { v: va?.[1] }),
|
|
836
834
|
...stack.slice(3),
|
|
837
835
|
];
|
|
838
836
|
}
|
|
839
837
|
ensureBigMapStorableType(s[1].args[0]);
|
|
840
838
|
return [
|
|
841
|
-
annotate({ prim: 'option', args: [s[2].args[1]] }, { v: va
|
|
839
|
+
annotate({ prim: 'option', args: [s[2].args[1]] }, { v: va?.[0] }),
|
|
842
840
|
annotate({
|
|
843
841
|
prim: 'big_map',
|
|
844
842
|
args: [annotate(s[0], { t: null }), annotate(s[1].args[0], { t: null })],
|
|
845
|
-
}, { v: va
|
|
843
|
+
}, { v: va?.[1] }),
|
|
846
844
|
...stack.slice(3),
|
|
847
845
|
];
|
|
848
846
|
}
|
|
@@ -1050,11 +1048,11 @@ function functionTypeInternal(inst, stack, ctx) {
|
|
|
1050
1048
|
args(0, ['int']);
|
|
1051
1049
|
return [annotateVar({ prim: 'bool' }), ...stack.slice(1)];
|
|
1052
1050
|
case 'SELF': {
|
|
1053
|
-
if (
|
|
1051
|
+
if (ctx?.contract === undefined) {
|
|
1054
1052
|
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: contract required`);
|
|
1055
1053
|
}
|
|
1056
1054
|
const ia = instructionAnn({ f: 1, v: 1 });
|
|
1057
|
-
const ep = contractEntryPoint(ctx.contract,
|
|
1055
|
+
const ep = contractEntryPoint(ctx.contract, ia.f?.[0]);
|
|
1058
1056
|
if (ep === null) {
|
|
1059
1057
|
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: contract has no entrypoint ${ep}`);
|
|
1060
1058
|
}
|
|
@@ -1111,7 +1109,7 @@ function functionTypeInternal(inst, stack, ctx) {
|
|
|
1111
1109
|
}
|
|
1112
1110
|
case 'SELF_ADDRESS': {
|
|
1113
1111
|
const addr = { prim: 'address' };
|
|
1114
|
-
if (
|
|
1112
|
+
if (ctx?.contract !== undefined) {
|
|
1115
1113
|
addr[michelson_types_1.refContract] = {
|
|
1116
1114
|
prim: 'contract',
|
|
1117
1115
|
args: [contractSection(ctx.contract, 'parameter').args[0]],
|
|
@@ -1192,7 +1190,7 @@ function functionTypeInternal(inst, stack, ctx) {
|
|
|
1192
1190
|
const ia = instructionAnn({ v: 1, f: 1 });
|
|
1193
1191
|
const contract = s[michelson_types_1.refContract];
|
|
1194
1192
|
if (contract !== undefined) {
|
|
1195
|
-
const ep = contractEntryPoint(contract,
|
|
1193
|
+
const ep = contractEntryPoint(contract, ia.f?.[0]);
|
|
1196
1194
|
if (ep === null) {
|
|
1197
1195
|
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: contract has no entrypoint ${ep}`);
|
|
1198
1196
|
}
|
|
@@ -1342,22 +1340,25 @@ function functionTypeInternal(inst, stack, ctx) {
|
|
|
1342
1340
|
assertContractValid(instruction.args[0]);
|
|
1343
1341
|
assertScalarTypesEqual(contractSection(instruction.args[0], 'storage').args[0], s[2]);
|
|
1344
1342
|
}
|
|
1345
|
-
const va =
|
|
1343
|
+
const va = ia.v?.map((v) => (v !== '@' ? [v] : undefined));
|
|
1346
1344
|
return [
|
|
1347
|
-
annotate({ prim: 'operation' }, { v: va
|
|
1345
|
+
annotate({ prim: 'operation' }, { v: va?.[0] }),
|
|
1348
1346
|
annotate({
|
|
1349
1347
|
prim: 'address',
|
|
1350
1348
|
[michelson_types_1.refContract]: {
|
|
1351
1349
|
prim: 'contract',
|
|
1352
1350
|
args: [contractSection(instruction.args[0], 'parameter').args[0]],
|
|
1353
1351
|
},
|
|
1354
|
-
}, { v: va
|
|
1352
|
+
}, { v: va?.[1] }),
|
|
1355
1353
|
...stack.slice(3),
|
|
1356
1354
|
];
|
|
1357
1355
|
}
|
|
1358
1356
|
case 'PUSH':
|
|
1359
1357
|
assertTypeAnnotationsValid(instruction.args[0]);
|
|
1360
|
-
assertDataValidInternal(instruction.args[1], instruction.args[0],
|
|
1358
|
+
assertDataValidInternal(instruction.args[1], instruction.args[0], {
|
|
1359
|
+
...ctx,
|
|
1360
|
+
contract: undefined,
|
|
1361
|
+
});
|
|
1361
1362
|
return [annotateVar(instruction.args[0]), ...stack];
|
|
1362
1363
|
case 'EMPTY_SET':
|
|
1363
1364
|
assertTypeAnnotationsValid(instruction.args[0]);
|
|
@@ -1391,7 +1392,10 @@ function functionTypeInternal(inst, stack, ctx) {
|
|
|
1391
1392
|
if (instruction.prim === 'LAMBDA_REC') {
|
|
1392
1393
|
s.push({ prim: 'lambda', args: [instruction.args[0], instruction.args[1]] });
|
|
1393
1394
|
}
|
|
1394
|
-
const body = functionTypeInternal(instruction.args[2], s,
|
|
1395
|
+
const body = functionTypeInternal(instruction.args[2], s, {
|
|
1396
|
+
...ctx,
|
|
1397
|
+
contract: undefined,
|
|
1398
|
+
});
|
|
1395
1399
|
if ('failed' in body) {
|
|
1396
1400
|
return { failed: body.failed, level: body.level + 1 };
|
|
1397
1401
|
}
|
|
@@ -1467,13 +1471,13 @@ function functionTypeInternal(inst, stack, ctx) {
|
|
|
1467
1471
|
case 'READ_TICKET': {
|
|
1468
1472
|
const ia = instructionAnn({ v: 2 });
|
|
1469
1473
|
const s = args(0, ['ticket'])[0];
|
|
1470
|
-
const va =
|
|
1474
|
+
const va = ia.v?.map((v) => (v !== '@' ? [v] : undefined));
|
|
1471
1475
|
return [
|
|
1472
1476
|
annotate({
|
|
1473
1477
|
prim: 'pair',
|
|
1474
1478
|
args: [{ prim: 'address' }, annotate(s.args[0], { t: null }), { prim: 'nat' }],
|
|
1475
|
-
}, { v: va
|
|
1476
|
-
annotate(s, { v: va
|
|
1479
|
+
}, { v: va?.[0] }),
|
|
1480
|
+
annotate(s, { v: va?.[1], t: null }),
|
|
1477
1481
|
...stack.slice(1),
|
|
1478
1482
|
];
|
|
1479
1483
|
}
|
|
@@ -1568,7 +1572,7 @@ function functionTypeInternal(inst, stack, ctx) {
|
|
|
1568
1572
|
throw new utils_1.MichelsonError(instruction, `unexpected instruction: ${instruction.prim}`);
|
|
1569
1573
|
}
|
|
1570
1574
|
})(instruction);
|
|
1571
|
-
if (
|
|
1575
|
+
if (ctx?.traceCallback !== undefined) {
|
|
1572
1576
|
const trace = {
|
|
1573
1577
|
op: instruction,
|
|
1574
1578
|
in: stack,
|
|
@@ -1648,11 +1652,11 @@ function assertContractValid(contract, ctx) {
|
|
|
1648
1652
|
const arg = {
|
|
1649
1653
|
prim: 'pair',
|
|
1650
1654
|
args: [
|
|
1651
|
-
|
|
1652
|
-
|
|
1655
|
+
{ ...parameter, ...{ annots: ['@parameter'] } },
|
|
1656
|
+
{ ...storage, ...{ annots: ['@storage'] } },
|
|
1653
1657
|
],
|
|
1654
1658
|
};
|
|
1655
|
-
const out = functionTypeInternal(code, [arg],
|
|
1659
|
+
const out = functionTypeInternal(code, [arg], { ...ctx, ...{ contract } });
|
|
1656
1660
|
if ('failed' in out) {
|
|
1657
1661
|
return out;
|
|
1658
1662
|
}
|
|
@@ -1691,7 +1695,7 @@ function functionType(inst, stack, ctx) {
|
|
|
1691
1695
|
for (const t of stack) {
|
|
1692
1696
|
assertTypeAnnotationsValid(t);
|
|
1693
1697
|
}
|
|
1694
|
-
if (
|
|
1698
|
+
if (ctx?.contract !== undefined) {
|
|
1695
1699
|
for (const typesec of ['parameter', 'storage']) {
|
|
1696
1700
|
const sec = contractSection(ctx.contract, typesec).args[0];
|
|
1697
1701
|
assertTypeAnnotationsValid(sec);
|
|
@@ -1720,7 +1724,7 @@ function isTypeAnnotationsValid(t, field = false) {
|
|
|
1720
1724
|
assertTypeAnnotationsValid(t, field);
|
|
1721
1725
|
return true;
|
|
1722
1726
|
}
|
|
1723
|
-
catch
|
|
1727
|
+
catch {
|
|
1724
1728
|
return false;
|
|
1725
1729
|
}
|
|
1726
1730
|
}
|
|
@@ -1728,7 +1732,7 @@ function isContractValid(contract, ctx) {
|
|
|
1728
1732
|
try {
|
|
1729
1733
|
return assertContractValid(contract, ctx);
|
|
1730
1734
|
}
|
|
1731
|
-
catch
|
|
1735
|
+
catch {
|
|
1732
1736
|
return null;
|
|
1733
1737
|
}
|
|
1734
1738
|
}
|
|
@@ -1737,7 +1741,7 @@ function isDataValid(d, t, ctx) {
|
|
|
1737
1741
|
assertDataValid(d, t, ctx);
|
|
1738
1742
|
return true;
|
|
1739
1743
|
}
|
|
1740
|
-
catch
|
|
1744
|
+
catch {
|
|
1741
1745
|
return false;
|
|
1742
1746
|
}
|
|
1743
1747
|
}
|
|
@@ -1746,7 +1750,7 @@ function isTypeEqual(a, b, field = false) {
|
|
|
1746
1750
|
assertTypesEqual(a, b, field);
|
|
1747
1751
|
return true;
|
|
1748
1752
|
}
|
|
1749
|
-
catch
|
|
1753
|
+
catch {
|
|
1750
1754
|
return false;
|
|
1751
1755
|
}
|
|
1752
1756
|
}
|