@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
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* @category Error
|
|
12
|
-
*
|
|
12
|
+
* Error that indicates a failure when performing the scan step when parsing Michelson
|
|
13
13
|
*/
|
|
14
14
|
class ScanError extends core.TaquitoError {
|
|
15
15
|
constructor(src, idx, message) {
|
|
@@ -211,7 +211,7 @@
|
|
|
211
211
|
|
|
212
212
|
/**
|
|
213
213
|
* @category Error
|
|
214
|
-
*
|
|
214
|
+
* Error that indicates macros failed to be expanded
|
|
215
215
|
*/
|
|
216
216
|
class MacroError extends core.TaquitoError {
|
|
217
217
|
constructor(prim, message) {
|
|
@@ -222,11 +222,10 @@
|
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
224
|
function assertArgs$1(ex, n) {
|
|
225
|
-
|
|
226
|
-
if ((n === 0 && ex.args === undefined) || ((_a = ex.args) === null || _a === void 0 ? void 0 : _a.length) === n) {
|
|
225
|
+
if ((n === 0 && ex.args === undefined) || ex.args?.length === n) {
|
|
227
226
|
return true;
|
|
228
227
|
}
|
|
229
|
-
throw new MacroError(ex, `macro ${ex.prim} expects ${n} arguments, was given ${
|
|
228
|
+
throw new MacroError(ex, `macro ${ex.prim} expects ${n} arguments, was given ${ex.args?.length}`);
|
|
230
229
|
}
|
|
231
230
|
function assertNoAnnots(ex) {
|
|
232
231
|
if (ex.annots === undefined) {
|
|
@@ -344,7 +343,11 @@
|
|
|
344
343
|
return { fields, rest };
|
|
345
344
|
}
|
|
346
345
|
function mkPrim({ prim, annots, args }) {
|
|
347
|
-
return
|
|
346
|
+
return {
|
|
347
|
+
prim,
|
|
348
|
+
...(annots && { annots }),
|
|
349
|
+
...(args && { args }),
|
|
350
|
+
};
|
|
348
351
|
}
|
|
349
352
|
const pairRe = /^P[PAI]{3,}R$/;
|
|
350
353
|
const unpairRe = /^UNP[PAI]{2,}R$/;
|
|
@@ -354,7 +357,7 @@
|
|
|
354
357
|
const diipRe = /^DI{2,}P$/;
|
|
355
358
|
const duupRe = /^DU+P$/;
|
|
356
359
|
function expandMacros(ex, opt) {
|
|
357
|
-
const proto =
|
|
360
|
+
const proto = opt?.protocol || DefaultProtocol;
|
|
358
361
|
function mayRename(annots) {
|
|
359
362
|
return annots !== undefined ? [{ prim: 'RENAME', annots }] : [];
|
|
360
363
|
}
|
|
@@ -763,7 +766,7 @@
|
|
|
763
766
|
|
|
764
767
|
/**
|
|
765
768
|
* @category Error
|
|
766
|
-
*
|
|
769
|
+
* Error that indicates a failure when parsing Micheline expressions
|
|
767
770
|
*/
|
|
768
771
|
class MichelineParseError extends core.TaquitoError {
|
|
769
772
|
/**
|
|
@@ -779,7 +782,7 @@
|
|
|
779
782
|
}
|
|
780
783
|
/**
|
|
781
784
|
* @category Error
|
|
782
|
-
*
|
|
785
|
+
* Error indicates a failure when parsing Micheline JSON
|
|
783
786
|
*/
|
|
784
787
|
class JSONParseError extends core.TaquitoError {
|
|
785
788
|
/**
|
|
@@ -836,18 +839,20 @@
|
|
|
836
839
|
this.opt = opt;
|
|
837
840
|
}
|
|
838
841
|
expand(ex) {
|
|
839
|
-
|
|
840
|
-
if (((_a = this.opt) === null || _a === void 0 ? void 0 : _a.expandGlobalConstant) !== undefined && ex.prim === 'constant') {
|
|
842
|
+
if (this.opt?.expandGlobalConstant !== undefined && ex.prim === 'constant') {
|
|
841
843
|
const ret = expandGlobalConstants(ex, this.opt.expandGlobalConstant);
|
|
842
844
|
if (ret !== ex) {
|
|
843
|
-
ret[sourceReference] =
|
|
845
|
+
ret[sourceReference] = {
|
|
846
|
+
...(ex[sourceReference] || { first: 0, last: 0 }),
|
|
847
|
+
globalConstant: ex,
|
|
848
|
+
};
|
|
844
849
|
}
|
|
845
850
|
return ret;
|
|
846
851
|
}
|
|
847
|
-
if (
|
|
852
|
+
if (this.opt?.expandMacros !== undefined ? this.opt?.expandMacros : true) {
|
|
848
853
|
const ret = expandMacros(ex, this.opt);
|
|
849
854
|
if (ret !== ex) {
|
|
850
|
-
ret[sourceReference] =
|
|
855
|
+
ret[sourceReference] = { ...(ex[sourceReference] || { first: 0, last: 0 }), macro: ex };
|
|
851
856
|
}
|
|
852
857
|
return ret;
|
|
853
858
|
}
|
|
@@ -856,7 +861,6 @@
|
|
|
856
861
|
}
|
|
857
862
|
}
|
|
858
863
|
parseListExpr(scanner, start) {
|
|
859
|
-
var _a;
|
|
860
864
|
const ref = {
|
|
861
865
|
first: start.first,
|
|
862
866
|
last: start.last,
|
|
@@ -903,14 +907,13 @@
|
|
|
903
907
|
else {
|
|
904
908
|
ret.args = ret.args || [];
|
|
905
909
|
const arg = this.parseExpr(scanner, tok.value);
|
|
906
|
-
ref.last =
|
|
910
|
+
ref.last = arg[sourceReference]?.last || ref.last;
|
|
907
911
|
ret.args.push(arg);
|
|
908
912
|
}
|
|
909
913
|
}
|
|
910
914
|
return this.expand(ret);
|
|
911
915
|
}
|
|
912
916
|
parseArgs(scanner, start) {
|
|
913
|
-
var _a;
|
|
914
917
|
// Identifier with arguments
|
|
915
918
|
const ref = {
|
|
916
919
|
first: start.first,
|
|
@@ -932,14 +935,13 @@
|
|
|
932
935
|
}
|
|
933
936
|
else {
|
|
934
937
|
const arg = this.parseExpr(scanner, t.value);
|
|
935
|
-
ref.last =
|
|
938
|
+
ref.last = arg[sourceReference]?.last || ref.last;
|
|
936
939
|
p.args = p.args || [];
|
|
937
940
|
p.args.push(arg);
|
|
938
941
|
}
|
|
939
942
|
}
|
|
940
943
|
}
|
|
941
944
|
parseSequenceExpr(scanner, start) {
|
|
942
|
-
var _a, _b;
|
|
943
945
|
const ref = {
|
|
944
946
|
first: start.first,
|
|
945
947
|
last: start.last,
|
|
@@ -974,14 +976,14 @@
|
|
|
974
976
|
else if (tok.value.t === Literal.Ident) {
|
|
975
977
|
// Identifier with arguments
|
|
976
978
|
const [itm, n] = this.parseArgs(scanner, tok.value);
|
|
977
|
-
ref.last =
|
|
979
|
+
ref.last = itm[sourceReference]?.last || ref.last;
|
|
978
980
|
seq.push(this.expand(itm));
|
|
979
981
|
tok = n;
|
|
980
982
|
}
|
|
981
983
|
else {
|
|
982
984
|
// Other
|
|
983
985
|
const ex = this.parseExpr(scanner, tok.value);
|
|
984
|
-
ref.last =
|
|
986
|
+
ref.last = ex[sourceReference]?.last || ref.last;
|
|
985
987
|
seq.push(ex);
|
|
986
988
|
tok = null;
|
|
987
989
|
}
|
|
@@ -1160,9 +1162,8 @@
|
|
|
1160
1162
|
this.lev = lev;
|
|
1161
1163
|
}
|
|
1162
1164
|
indent(n = 0) {
|
|
1163
|
-
var _a;
|
|
1164
1165
|
let ret = '';
|
|
1165
|
-
if (
|
|
1166
|
+
if (this.opt?.indent !== undefined) {
|
|
1166
1167
|
for (let i = this.lev + n; i > 0; i--) {
|
|
1167
1168
|
ret += this.opt.indent;
|
|
1168
1169
|
}
|
|
@@ -1170,12 +1171,10 @@
|
|
|
1170
1171
|
return ret;
|
|
1171
1172
|
}
|
|
1172
1173
|
get lf() {
|
|
1173
|
-
|
|
1174
|
-
return ((_a = this.opt) === null || _a === void 0 ? void 0 : _a.newline) || '';
|
|
1174
|
+
return this.opt?.newline || '';
|
|
1175
1175
|
}
|
|
1176
1176
|
get lfsp() {
|
|
1177
|
-
|
|
1178
|
-
return ((_a = this.opt) === null || _a === void 0 ? void 0 : _a.newline) || ' ';
|
|
1177
|
+
return this.opt?.newline || ' ';
|
|
1179
1178
|
}
|
|
1180
1179
|
down(n) {
|
|
1181
1180
|
return new Formatter(this.opt, this.lev + n);
|
|
@@ -1197,8 +1196,7 @@
|
|
|
1197
1196
|
return false;
|
|
1198
1197
|
}
|
|
1199
1198
|
function emitExpr(node, f, foldMacros) {
|
|
1200
|
-
|
|
1201
|
-
const macro = (_a = node[sourceReference]) === null || _a === void 0 ? void 0 : _a.macro;
|
|
1199
|
+
const macro = node[sourceReference]?.macro;
|
|
1202
1200
|
if (foldMacros && macro) {
|
|
1203
1201
|
return emitExpr(macro, f, foldMacros);
|
|
1204
1202
|
}
|
|
@@ -1361,7 +1359,7 @@
|
|
|
1361
1359
|
];
|
|
1362
1360
|
/**
|
|
1363
1361
|
* @category Error
|
|
1364
|
-
*
|
|
1362
|
+
* Error that indicates a failure when decoding a base58 encoding
|
|
1365
1363
|
*/
|
|
1366
1364
|
class Base58DecodingError extends core.TaquitoError {
|
|
1367
1365
|
constructor(message) {
|
|
@@ -1532,7 +1530,7 @@
|
|
|
1532
1530
|
|
|
1533
1531
|
/**
|
|
1534
1532
|
* @category Error
|
|
1535
|
-
*
|
|
1533
|
+
* Error that indicates an invalid Michelson being passed or used
|
|
1536
1534
|
*/
|
|
1537
1535
|
class InvalidMichelsonError extends core.ParameterValidationError {
|
|
1538
1536
|
constructor(message) {
|
|
@@ -1543,7 +1541,7 @@
|
|
|
1543
1541
|
}
|
|
1544
1542
|
/**
|
|
1545
1543
|
* @category Error
|
|
1546
|
-
*
|
|
1544
|
+
* Error that indicates an invalid type expression being passed or used
|
|
1547
1545
|
*/
|
|
1548
1546
|
class InvalidTypeExpressionError extends core.ParameterValidationError {
|
|
1549
1547
|
constructor(message) {
|
|
@@ -1554,7 +1552,7 @@
|
|
|
1554
1552
|
}
|
|
1555
1553
|
/**
|
|
1556
1554
|
* @category Error
|
|
1557
|
-
*
|
|
1555
|
+
* Error that indicates an invalid data expression being passed or used
|
|
1558
1556
|
*/
|
|
1559
1557
|
class InvalidDataExpressionError extends core.ParameterValidationError {
|
|
1560
1558
|
constructor(message) {
|
|
@@ -1565,7 +1563,7 @@
|
|
|
1565
1563
|
}
|
|
1566
1564
|
/**
|
|
1567
1565
|
* @category Error
|
|
1568
|
-
*
|
|
1566
|
+
* Error that indicates an invalid contract entrypoint being referenced or passed
|
|
1569
1567
|
*/
|
|
1570
1568
|
class InvalidEntrypointError extends core.ParameterValidationError {
|
|
1571
1569
|
constructor(entrypoint) {
|
|
@@ -1577,7 +1575,7 @@
|
|
|
1577
1575
|
}
|
|
1578
1576
|
/**
|
|
1579
1577
|
* @category Error
|
|
1580
|
-
*
|
|
1578
|
+
* Error that indicates a failure happening when trying to encode Tezos ID
|
|
1581
1579
|
*/
|
|
1582
1580
|
class TezosIdEncodeError extends core.ParameterValidationError {
|
|
1583
1581
|
constructor(message) {
|
|
@@ -1588,7 +1586,7 @@
|
|
|
1588
1586
|
}
|
|
1589
1587
|
/**
|
|
1590
1588
|
* @category Error
|
|
1591
|
-
*
|
|
1589
|
+
* Error that indicates a general error happening when trying to create a LongInteger
|
|
1592
1590
|
*/
|
|
1593
1591
|
class LongIntegerError extends core.TaquitoError {
|
|
1594
1592
|
constructor(message) {
|
|
@@ -1599,7 +1597,7 @@
|
|
|
1599
1597
|
}
|
|
1600
1598
|
/**
|
|
1601
1599
|
* @category Error
|
|
1602
|
-
*
|
|
1600
|
+
* Error that indicates a failure occurring when trying to parse a hex byte
|
|
1603
1601
|
*/
|
|
1604
1602
|
class HexParseError extends core.TaquitoError {
|
|
1605
1603
|
constructor(hexByte) {
|
|
@@ -1612,12 +1610,11 @@
|
|
|
1612
1610
|
|
|
1613
1611
|
/**
|
|
1614
1612
|
* @category Error
|
|
1615
|
-
*
|
|
1613
|
+
* Error that indicates a Michelson failure occurring
|
|
1616
1614
|
*/
|
|
1617
1615
|
class MichelsonError extends core.TaquitoError {
|
|
1618
1616
|
/**
|
|
1619
1617
|
* @param val Value of a AST node caused the error
|
|
1620
|
-
* @param path Path to a node caused the error
|
|
1621
1618
|
* @param message An error message
|
|
1622
1619
|
*/
|
|
1623
1620
|
constructor(val, message) {
|
|
@@ -1723,7 +1720,7 @@
|
|
|
1723
1720
|
new LongInteger(x);
|
|
1724
1721
|
return true;
|
|
1725
1722
|
}
|
|
1726
|
-
catch
|
|
1723
|
+
catch {
|
|
1727
1724
|
return false;
|
|
1728
1725
|
}
|
|
1729
1726
|
}
|
|
@@ -1731,7 +1728,7 @@
|
|
|
1731
1728
|
try {
|
|
1732
1729
|
return new LongInteger(x).sign >= 0;
|
|
1733
1730
|
}
|
|
1734
|
-
catch
|
|
1731
|
+
catch {
|
|
1735
1732
|
return false;
|
|
1736
1733
|
}
|
|
1737
1734
|
}
|
|
@@ -1747,13 +1744,13 @@
|
|
|
1747
1744
|
for (const v of p.annots) {
|
|
1748
1745
|
if (v.length !== 0) {
|
|
1749
1746
|
if (!annRe.test(v) ||
|
|
1750
|
-
(!
|
|
1751
|
-
(!
|
|
1747
|
+
(!opt?.specialVar && (v === '@%' || v === '@%%')) ||
|
|
1748
|
+
(!opt?.specialFields && v === '%@')) {
|
|
1752
1749
|
throw new MichelsonError(p, `${p.prim}: unexpected annotation: ${v}`);
|
|
1753
1750
|
}
|
|
1754
1751
|
switch (v[0]) {
|
|
1755
1752
|
case '%':
|
|
1756
|
-
if (
|
|
1753
|
+
if (opt?.emptyFields || v.length > 1) {
|
|
1757
1754
|
field = field || [];
|
|
1758
1755
|
field.push(v);
|
|
1759
1756
|
}
|
|
@@ -1765,7 +1762,7 @@
|
|
|
1765
1762
|
}
|
|
1766
1763
|
break;
|
|
1767
1764
|
case '@':
|
|
1768
|
-
if (
|
|
1765
|
+
if (opt?.emptyVar || v.length > 1) {
|
|
1769
1766
|
vars = vars || [];
|
|
1770
1767
|
vars.push(v);
|
|
1771
1768
|
}
|
|
@@ -1846,13 +1843,16 @@
|
|
|
1846
1843
|
};
|
|
1847
1844
|
return ret;
|
|
1848
1845
|
}
|
|
1849
|
-
return
|
|
1846
|
+
return {
|
|
1847
|
+
...(Array.isArray(vv) ? { prim: id } : vv),
|
|
1848
|
+
args: [
|
|
1850
1849
|
args[0],
|
|
1851
1850
|
{
|
|
1852
1851
|
prim: id,
|
|
1853
1852
|
args: args.slice(1),
|
|
1854
1853
|
},
|
|
1855
|
-
]
|
|
1854
|
+
],
|
|
1855
|
+
};
|
|
1856
1856
|
}
|
|
1857
1857
|
function isPairType(t) {
|
|
1858
1858
|
return Array.isArray(t) || t.prim === 'pair';
|
|
@@ -2108,8 +2108,7 @@
|
|
|
2108
2108
|
throw new MichelsonValidationError(ex, 'string or bytes literal expected');
|
|
2109
2109
|
}
|
|
2110
2110
|
function assertArgs(ex, n) {
|
|
2111
|
-
|
|
2112
|
-
if ((n === 0 && ex.args === undefined) || ((_a = ex.args) === null || _a === void 0 ? void 0 : _a.length) === n) {
|
|
2111
|
+
if ((n === 0 && ex.args === undefined) || ex.args?.length === n) {
|
|
2113
2112
|
return true;
|
|
2114
2113
|
}
|
|
2115
2114
|
throw new MichelsonValidationError(ex, `${n} arguments expected`);
|
|
@@ -2120,7 +2119,6 @@
|
|
|
2120
2119
|
* @param ex An AST node
|
|
2121
2120
|
*/
|
|
2122
2121
|
function assertMichelsonInstruction(ex) {
|
|
2123
|
-
var _a, _b;
|
|
2124
2122
|
if (Array.isArray(ex)) {
|
|
2125
2123
|
for (const n of ex) {
|
|
2126
2124
|
if (!Array.isArray(n) && !isPrim(n)) {
|
|
@@ -2214,7 +2212,7 @@
|
|
|
2214
2212
|
}
|
|
2215
2213
|
break;
|
|
2216
2214
|
case 'DIP':
|
|
2217
|
-
if (
|
|
2215
|
+
if (ex.args?.length === 2) {
|
|
2218
2216
|
/* istanbul ignore else */
|
|
2219
2217
|
if (assertIntLiteral(ex.args[0])) {
|
|
2220
2218
|
assertNatural(ex.args[0]);
|
|
@@ -2224,7 +2222,7 @@
|
|
|
2224
2222
|
assertMichelsonInstruction(ex.args[1]);
|
|
2225
2223
|
}
|
|
2226
2224
|
}
|
|
2227
|
-
else if (
|
|
2225
|
+
else if (ex.args?.length === 1) {
|
|
2228
2226
|
/* istanbul ignore else */
|
|
2229
2227
|
if (assertSeq(ex.args[0])) {
|
|
2230
2228
|
assertMichelsonInstruction(ex.args[0]);
|
|
@@ -2645,7 +2643,7 @@
|
|
|
2645
2643
|
assertMichelsonContract(ex);
|
|
2646
2644
|
return true;
|
|
2647
2645
|
}
|
|
2648
|
-
catch
|
|
2646
|
+
catch {
|
|
2649
2647
|
return false;
|
|
2650
2648
|
}
|
|
2651
2649
|
}
|
|
@@ -2658,7 +2656,7 @@
|
|
|
2658
2656
|
assertMichelsonData(ex);
|
|
2659
2657
|
return true;
|
|
2660
2658
|
}
|
|
2661
|
-
catch
|
|
2659
|
+
catch {
|
|
2662
2660
|
return false;
|
|
2663
2661
|
}
|
|
2664
2662
|
}
|
|
@@ -2671,7 +2669,7 @@
|
|
|
2671
2669
|
assertMichelsonInstruction(ex);
|
|
2672
2670
|
return true;
|
|
2673
2671
|
}
|
|
2674
|
-
catch
|
|
2672
|
+
catch {
|
|
2675
2673
|
return false;
|
|
2676
2674
|
}
|
|
2677
2675
|
}
|
|
@@ -2684,7 +2682,7 @@
|
|
|
2684
2682
|
assertMichelsonType(ex);
|
|
2685
2683
|
return true;
|
|
2686
2684
|
}
|
|
2687
|
-
catch
|
|
2685
|
+
catch {
|
|
2688
2686
|
return false;
|
|
2689
2687
|
}
|
|
2690
2688
|
}
|
|
@@ -2708,40 +2706,6 @@
|
|
|
2708
2706
|
return true;
|
|
2709
2707
|
}
|
|
2710
2708
|
|
|
2711
|
-
/******************************************************************************
|
|
2712
|
-
Copyright (c) Microsoft Corporation.
|
|
2713
|
-
|
|
2714
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
2715
|
-
purpose with or without fee is hereby granted.
|
|
2716
|
-
|
|
2717
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
2718
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
2719
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
2720
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
2721
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
2722
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
2723
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
2724
|
-
***************************************************************************** */
|
|
2725
|
-
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
function __rest(s, e) {
|
|
2729
|
-
var t = {};
|
|
2730
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
2731
|
-
t[p] = s[p];
|
|
2732
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
2733
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
2734
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
2735
|
-
t[p[i]] = s[p[i]];
|
|
2736
|
-
}
|
|
2737
|
-
return t;
|
|
2738
|
-
}
|
|
2739
|
-
|
|
2740
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
2741
|
-
var e = new Error(message);
|
|
2742
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
2743
|
-
};
|
|
2744
|
-
|
|
2745
2709
|
// The order is important!
|
|
2746
2710
|
// The position represent the encoding value.
|
|
2747
2711
|
const primitives = [
|
|
@@ -3172,7 +3136,6 @@
|
|
|
3172
3136
|
w.writeBytes(Array.from(pk.publicKey));
|
|
3173
3137
|
}
|
|
3174
3138
|
function writeExpr(expr, wr, tf) {
|
|
3175
|
-
var _a, _b;
|
|
3176
3139
|
const [e, args] = tf(expr);
|
|
3177
3140
|
if (Array.isArray(e)) {
|
|
3178
3141
|
const w = new Writer();
|
|
@@ -3230,9 +3193,9 @@
|
|
|
3230
3193
|
if (prim === undefined) {
|
|
3231
3194
|
throw new TypeError(`Can't encode primary: ${e.prim}`);
|
|
3232
3195
|
}
|
|
3233
|
-
const tag = (
|
|
3196
|
+
const tag = (e.args?.length || 0) < 3
|
|
3234
3197
|
? Tag.Prim0 +
|
|
3235
|
-
(
|
|
3198
|
+
(e.args?.length || 0) * 2 +
|
|
3236
3199
|
(e.annots === undefined || e.annots.length === 0 ? 0 : 1)
|
|
3237
3200
|
: Tag.Prim;
|
|
3238
3201
|
wr.writeUint8(tag);
|
|
@@ -4077,19 +4040,18 @@
|
|
|
4077
4040
|
}
|
|
4078
4041
|
}
|
|
4079
4042
|
function assertTypeAnnotationsValid(t, field = false) {
|
|
4080
|
-
var _a, _b, _c;
|
|
4081
4043
|
if (!Array.isArray(t)) {
|
|
4082
4044
|
const ann = unpackAnnotations(t);
|
|
4083
|
-
if ((
|
|
4045
|
+
if ((ann.t?.length || 0) > 1) {
|
|
4084
4046
|
throw new MichelsonTypeError(t, `${t.prim}: at most one type annotation allowed: ${t.annots}`, undefined);
|
|
4085
4047
|
}
|
|
4086
4048
|
if (field) {
|
|
4087
|
-
if ((
|
|
4049
|
+
if ((ann.f?.length || 0) > 1) {
|
|
4088
4050
|
throw new MichelsonTypeError(t, `${t.prim}: at most one field annotation allowed: ${t.annots}`, undefined);
|
|
4089
4051
|
}
|
|
4090
4052
|
}
|
|
4091
4053
|
else {
|
|
4092
|
-
if ((
|
|
4054
|
+
if ((ann.f?.length || 0) > 0) {
|
|
4093
4055
|
throw new MichelsonTypeError(t, `${t.prim}: field annotations aren't allowed: ${t.annots}`, undefined);
|
|
4094
4056
|
}
|
|
4095
4057
|
}
|
|
@@ -4363,7 +4325,7 @@
|
|
|
4363
4325
|
i !== inst.length - 1) {
|
|
4364
4326
|
throw new MichelsonInstructionError(inst, ret, 'FAIL must appear in a tail position');
|
|
4365
4327
|
}
|
|
4366
|
-
if (
|
|
4328
|
+
if (ctx?.traceCallback !== undefined) {
|
|
4367
4329
|
const trace = {
|
|
4368
4330
|
op: inst,
|
|
4369
4331
|
in: stack,
|
|
@@ -4374,7 +4336,7 @@
|
|
|
4374
4336
|
return 'failed' in ret ? { failed: ret.failed, level: ret.level + 1 } : ret;
|
|
4375
4337
|
}
|
|
4376
4338
|
function functionTypeInternal(inst, stack, ctx) {
|
|
4377
|
-
const proto =
|
|
4339
|
+
const proto = ctx?.protocol || DefaultProtocol;
|
|
4378
4340
|
if (Array.isArray(inst)) {
|
|
4379
4341
|
return instructionListType(inst, stack, ctx);
|
|
4380
4342
|
}
|
|
@@ -4439,7 +4401,11 @@
|
|
|
4439
4401
|
const ensureBigMapStorableType = rethrowTypeGuard(assertMichelsonBigMapStorableType);
|
|
4440
4402
|
// unpack instruction annotations and assert their maximum number
|
|
4441
4403
|
function instructionAnn(num, opt) {
|
|
4442
|
-
const a = argAnn(instruction,
|
|
4404
|
+
const a = argAnn(instruction, {
|
|
4405
|
+
...opt,
|
|
4406
|
+
emptyFields: num.f !== undefined && num.f > 1,
|
|
4407
|
+
emptyVar: num.v !== undefined && num.v > 1,
|
|
4408
|
+
});
|
|
4443
4409
|
const assertNum = (a, n, type) => {
|
|
4444
4410
|
if (a && a.length > (n || 0)) {
|
|
4445
4411
|
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: at most ${n || 0} ${type} annotations allowed`);
|
|
@@ -4462,8 +4428,8 @@
|
|
|
4462
4428
|
...((a.f === null ? src.f : a.f) || []),
|
|
4463
4429
|
]
|
|
4464
4430
|
: undefined;
|
|
4465
|
-
const { annots: _annots
|
|
4466
|
-
return
|
|
4431
|
+
const { annots: _annots, ...rest } = t;
|
|
4432
|
+
return { ...rest, ...(ann && ann.length !== 0 && { annots: ann }) };
|
|
4467
4433
|
}
|
|
4468
4434
|
// shortcut to copy at most one variable annotation from the instruction to the type
|
|
4469
4435
|
function annotateVar(t, def) {
|
|
@@ -4475,17 +4441,16 @@
|
|
|
4475
4441
|
}
|
|
4476
4442
|
// annotate CAR/CDR/UNPAIR/GET
|
|
4477
4443
|
function annotateField(arg, field, insAnn, n, defField) {
|
|
4478
|
-
|
|
4479
|
-
const
|
|
4480
|
-
const insFieldAnn = (_b = insAnn.f) === null || _b === void 0 ? void 0 : _b[n];
|
|
4444
|
+
const fieldAnn = argAnn(field).f?.[0]; // field's field annotation
|
|
4445
|
+
const insFieldAnn = insAnn.f?.[n];
|
|
4481
4446
|
if (insFieldAnn !== undefined &&
|
|
4482
4447
|
insFieldAnn !== '%' &&
|
|
4483
4448
|
fieldAnn !== undefined &&
|
|
4484
4449
|
insFieldAnn !== fieldAnn) {
|
|
4485
4450
|
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: field names doesn't match: ${insFieldAnn} !== ${fieldAnn}`);
|
|
4486
4451
|
}
|
|
4487
|
-
const insVarAnn =
|
|
4488
|
-
const varAnn =
|
|
4452
|
+
const insVarAnn = insAnn.v?.[n]; // nth instruction's variable annotation
|
|
4453
|
+
const varAnn = argAnn(arg).v?.[0]; // instruction argument's variable annotation
|
|
4489
4454
|
return annotate(field, {
|
|
4490
4455
|
t: null,
|
|
4491
4456
|
v: insVarAnn
|
|
@@ -4543,14 +4508,23 @@
|
|
|
4543
4508
|
}
|
|
4544
4509
|
const p = unpackComb('pair', src);
|
|
4545
4510
|
if (i === 1) {
|
|
4546
|
-
return
|
|
4511
|
+
return {
|
|
4512
|
+
...p,
|
|
4513
|
+
args: [x, p.args[1]],
|
|
4514
|
+
};
|
|
4547
4515
|
}
|
|
4548
4516
|
const right = p.args[1];
|
|
4549
4517
|
if (isPairType(right)) {
|
|
4550
|
-
return
|
|
4518
|
+
return {
|
|
4519
|
+
...p,
|
|
4520
|
+
args: [p.args[0], updateNth(right, x, n, i - 2)],
|
|
4521
|
+
};
|
|
4551
4522
|
}
|
|
4552
4523
|
else if (i === 2) {
|
|
4553
|
-
return
|
|
4524
|
+
return {
|
|
4525
|
+
...p,
|
|
4526
|
+
args: [p.args[0], x],
|
|
4527
|
+
};
|
|
4554
4528
|
}
|
|
4555
4529
|
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: at least ${n + 1} fields are expected`);
|
|
4556
4530
|
}
|
|
@@ -4567,7 +4541,6 @@
|
|
|
4567
4541
|
}
|
|
4568
4542
|
}
|
|
4569
4543
|
const retStack = ((instruction) => {
|
|
4570
|
-
var _a, _b, _c, _d, _e;
|
|
4571
4544
|
switch (instruction.prim) {
|
|
4572
4545
|
case 'DUP': {
|
|
4573
4546
|
const n = instruction.args ? parseInt(instruction.args[0].int, 10) : 1;
|
|
@@ -4604,12 +4577,11 @@
|
|
|
4604
4577
|
return s.slice(i > 0 ? i + 1 : 1);
|
|
4605
4578
|
};
|
|
4606
4579
|
const retArgs = s.map((v, i) => {
|
|
4607
|
-
var _a;
|
|
4608
4580
|
const va = argAnn(v);
|
|
4609
4581
|
const f = ia.f && ia.f.length > i && ia.f[i] !== '%'
|
|
4610
4582
|
? ia.f[i] === '%@'
|
|
4611
4583
|
? va.v
|
|
4612
|
-
? ['%' + trim(
|
|
4584
|
+
? ['%' + trim(va.v?.[0] || '')]
|
|
4613
4585
|
: undefined
|
|
4614
4586
|
: [ia.f[i]]
|
|
4615
4587
|
: undefined;
|
|
@@ -4722,24 +4694,24 @@
|
|
|
4722
4694
|
ensureComparableType(s[0]);
|
|
4723
4695
|
ensureTypesEqual(s[0], s[2].args[0]);
|
|
4724
4696
|
ensureTypesEqual(s[1].args[0], s[2].args[1]);
|
|
4725
|
-
const va =
|
|
4697
|
+
const va = ia.v?.map((v) => (v !== '@' ? [v] : undefined));
|
|
4726
4698
|
if (s[2].prim === 'map') {
|
|
4727
4699
|
return [
|
|
4728
|
-
annotate({ prim: 'option', args: [s[2].args[1]] }, { v: va
|
|
4700
|
+
annotate({ prim: 'option', args: [s[2].args[1]] }, { v: va?.[0] }),
|
|
4729
4701
|
annotate({
|
|
4730
4702
|
prim: 'map',
|
|
4731
4703
|
args: [annotate(s[0], { t: null }), annotate(s[1].args[0], { t: null })],
|
|
4732
|
-
}, { v: va
|
|
4704
|
+
}, { v: va?.[1] }),
|
|
4733
4705
|
...stack.slice(3),
|
|
4734
4706
|
];
|
|
4735
4707
|
}
|
|
4736
4708
|
ensureBigMapStorableType(s[1].args[0]);
|
|
4737
4709
|
return [
|
|
4738
|
-
annotate({ prim: 'option', args: [s[2].args[1]] }, { v: va
|
|
4710
|
+
annotate({ prim: 'option', args: [s[2].args[1]] }, { v: va?.[0] }),
|
|
4739
4711
|
annotate({
|
|
4740
4712
|
prim: 'big_map',
|
|
4741
4713
|
args: [annotate(s[0], { t: null }), annotate(s[1].args[0], { t: null })],
|
|
4742
|
-
}, { v: va
|
|
4714
|
+
}, { v: va?.[1] }),
|
|
4743
4715
|
...stack.slice(3),
|
|
4744
4716
|
];
|
|
4745
4717
|
}
|
|
@@ -4947,11 +4919,11 @@
|
|
|
4947
4919
|
args(0, ['int']);
|
|
4948
4920
|
return [annotateVar({ prim: 'bool' }), ...stack.slice(1)];
|
|
4949
4921
|
case 'SELF': {
|
|
4950
|
-
if (
|
|
4922
|
+
if (ctx?.contract === undefined) {
|
|
4951
4923
|
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: contract required`);
|
|
4952
4924
|
}
|
|
4953
4925
|
const ia = instructionAnn({ f: 1, v: 1 });
|
|
4954
|
-
const ep = contractEntryPoint(ctx.contract,
|
|
4926
|
+
const ep = contractEntryPoint(ctx.contract, ia.f?.[0]);
|
|
4955
4927
|
if (ep === null) {
|
|
4956
4928
|
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: contract has no entrypoint ${ep}`);
|
|
4957
4929
|
}
|
|
@@ -5008,7 +4980,7 @@
|
|
|
5008
4980
|
}
|
|
5009
4981
|
case 'SELF_ADDRESS': {
|
|
5010
4982
|
const addr = { prim: 'address' };
|
|
5011
|
-
if (
|
|
4983
|
+
if (ctx?.contract !== undefined) {
|
|
5012
4984
|
addr[refContract] = {
|
|
5013
4985
|
prim: 'contract',
|
|
5014
4986
|
args: [contractSection(ctx.contract, 'parameter').args[0]],
|
|
@@ -5089,7 +5061,7 @@
|
|
|
5089
5061
|
const ia = instructionAnn({ v: 1, f: 1 });
|
|
5090
5062
|
const contract = s[refContract];
|
|
5091
5063
|
if (contract !== undefined) {
|
|
5092
|
-
const ep = contractEntryPoint(contract,
|
|
5064
|
+
const ep = contractEntryPoint(contract, ia.f?.[0]);
|
|
5093
5065
|
if (ep === null) {
|
|
5094
5066
|
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: contract has no entrypoint ${ep}`);
|
|
5095
5067
|
}
|
|
@@ -5239,22 +5211,25 @@
|
|
|
5239
5211
|
assertContractValid(instruction.args[0]);
|
|
5240
5212
|
assertScalarTypesEqual(contractSection(instruction.args[0], 'storage').args[0], s[2]);
|
|
5241
5213
|
}
|
|
5242
|
-
const va =
|
|
5214
|
+
const va = ia.v?.map((v) => (v !== '@' ? [v] : undefined));
|
|
5243
5215
|
return [
|
|
5244
|
-
annotate({ prim: 'operation' }, { v: va
|
|
5216
|
+
annotate({ prim: 'operation' }, { v: va?.[0] }),
|
|
5245
5217
|
annotate({
|
|
5246
5218
|
prim: 'address',
|
|
5247
5219
|
[refContract]: {
|
|
5248
5220
|
prim: 'contract',
|
|
5249
5221
|
args: [contractSection(instruction.args[0], 'parameter').args[0]],
|
|
5250
5222
|
},
|
|
5251
|
-
}, { v: va
|
|
5223
|
+
}, { v: va?.[1] }),
|
|
5252
5224
|
...stack.slice(3),
|
|
5253
5225
|
];
|
|
5254
5226
|
}
|
|
5255
5227
|
case 'PUSH':
|
|
5256
5228
|
assertTypeAnnotationsValid(instruction.args[0]);
|
|
5257
|
-
assertDataValidInternal(instruction.args[1], instruction.args[0],
|
|
5229
|
+
assertDataValidInternal(instruction.args[1], instruction.args[0], {
|
|
5230
|
+
...ctx,
|
|
5231
|
+
contract: undefined,
|
|
5232
|
+
});
|
|
5258
5233
|
return [annotateVar(instruction.args[0]), ...stack];
|
|
5259
5234
|
case 'EMPTY_SET':
|
|
5260
5235
|
assertTypeAnnotationsValid(instruction.args[0]);
|
|
@@ -5288,7 +5263,10 @@
|
|
|
5288
5263
|
if (instruction.prim === 'LAMBDA_REC') {
|
|
5289
5264
|
s.push({ prim: 'lambda', args: [instruction.args[0], instruction.args[1]] });
|
|
5290
5265
|
}
|
|
5291
|
-
const body = functionTypeInternal(instruction.args[2], s,
|
|
5266
|
+
const body = functionTypeInternal(instruction.args[2], s, {
|
|
5267
|
+
...ctx,
|
|
5268
|
+
contract: undefined,
|
|
5269
|
+
});
|
|
5292
5270
|
if ('failed' in body) {
|
|
5293
5271
|
return { failed: body.failed, level: body.level + 1 };
|
|
5294
5272
|
}
|
|
@@ -5364,13 +5342,13 @@
|
|
|
5364
5342
|
case 'READ_TICKET': {
|
|
5365
5343
|
const ia = instructionAnn({ v: 2 });
|
|
5366
5344
|
const s = args(0, ['ticket'])[0];
|
|
5367
|
-
const va =
|
|
5345
|
+
const va = ia.v?.map((v) => (v !== '@' ? [v] : undefined));
|
|
5368
5346
|
return [
|
|
5369
5347
|
annotate({
|
|
5370
5348
|
prim: 'pair',
|
|
5371
5349
|
args: [{ prim: 'address' }, annotate(s.args[0], { t: null }), { prim: 'nat' }],
|
|
5372
|
-
}, { v: va
|
|
5373
|
-
annotate(s, { v: va
|
|
5350
|
+
}, { v: va?.[0] }),
|
|
5351
|
+
annotate(s, { v: va?.[1], t: null }),
|
|
5374
5352
|
...stack.slice(1),
|
|
5375
5353
|
];
|
|
5376
5354
|
}
|
|
@@ -5465,7 +5443,7 @@
|
|
|
5465
5443
|
throw new MichelsonError(instruction, `unexpected instruction: ${instruction.prim}`);
|
|
5466
5444
|
}
|
|
5467
5445
|
})(instruction);
|
|
5468
|
-
if (
|
|
5446
|
+
if (ctx?.traceCallback !== undefined) {
|
|
5469
5447
|
const trace = {
|
|
5470
5448
|
op: instruction,
|
|
5471
5449
|
in: stack,
|
|
@@ -5545,11 +5523,11 @@
|
|
|
5545
5523
|
const arg = {
|
|
5546
5524
|
prim: 'pair',
|
|
5547
5525
|
args: [
|
|
5548
|
-
|
|
5549
|
-
|
|
5526
|
+
{ ...parameter, ...{ annots: ['@parameter'] } },
|
|
5527
|
+
{ ...storage, ...{ annots: ['@storage'] } },
|
|
5550
5528
|
],
|
|
5551
5529
|
};
|
|
5552
|
-
const out = functionTypeInternal(code, [arg],
|
|
5530
|
+
const out = functionTypeInternal(code, [arg], { ...ctx, ...{ contract } });
|
|
5553
5531
|
if ('failed' in out) {
|
|
5554
5532
|
return out;
|
|
5555
5533
|
}
|
|
@@ -5588,7 +5566,7 @@
|
|
|
5588
5566
|
for (const t of stack) {
|
|
5589
5567
|
assertTypeAnnotationsValid(t);
|
|
5590
5568
|
}
|
|
5591
|
-
if (
|
|
5569
|
+
if (ctx?.contract !== undefined) {
|
|
5592
5570
|
for (const typesec of ['parameter', 'storage']) {
|
|
5593
5571
|
const sec = contractSection(ctx.contract, typesec).args[0];
|
|
5594
5572
|
assertTypeAnnotationsValid(sec);
|
|
@@ -5617,7 +5595,7 @@
|
|
|
5617
5595
|
assertTypeAnnotationsValid(t, field);
|
|
5618
5596
|
return true;
|
|
5619
5597
|
}
|
|
5620
|
-
catch
|
|
5598
|
+
catch {
|
|
5621
5599
|
return false;
|
|
5622
5600
|
}
|
|
5623
5601
|
}
|
|
@@ -5625,7 +5603,7 @@
|
|
|
5625
5603
|
try {
|
|
5626
5604
|
return assertContractValid(contract, ctx);
|
|
5627
5605
|
}
|
|
5628
|
-
catch
|
|
5606
|
+
catch {
|
|
5629
5607
|
return null;
|
|
5630
5608
|
}
|
|
5631
5609
|
}
|
|
@@ -5634,7 +5612,7 @@
|
|
|
5634
5612
|
assertDataValid(d, t, ctx);
|
|
5635
5613
|
return true;
|
|
5636
5614
|
}
|
|
5637
|
-
catch
|
|
5615
|
+
catch {
|
|
5638
5616
|
return false;
|
|
5639
5617
|
}
|
|
5640
5618
|
}
|
|
@@ -5643,7 +5621,7 @@
|
|
|
5643
5621
|
assertTypesEqual(a, b, field);
|
|
5644
5622
|
return true;
|
|
5645
5623
|
}
|
|
5646
|
-
catch
|
|
5624
|
+
catch {
|
|
5647
5625
|
return false;
|
|
5648
5626
|
}
|
|
5649
5627
|
}
|
|
@@ -5651,7 +5629,7 @@
|
|
|
5651
5629
|
class Contract {
|
|
5652
5630
|
constructor(contract, opt) {
|
|
5653
5631
|
this.contract = contract;
|
|
5654
|
-
this.ctx =
|
|
5632
|
+
this.ctx = { contract, ...opt };
|
|
5655
5633
|
this.output = assertContractValid(contract, this.ctx);
|
|
5656
5634
|
}
|
|
5657
5635
|
static parse(src, opt) {
|
|
@@ -5705,7 +5683,7 @@
|
|
|
5705
5683
|
assertParameterValid(ep, d) {
|
|
5706
5684
|
const t = this.entryPoint(ep || undefined);
|
|
5707
5685
|
if (t === null) {
|
|
5708
|
-
throw new InvalidEntrypointError(ep
|
|
5686
|
+
throw new InvalidEntrypointError(ep?.toString());
|
|
5709
5687
|
}
|
|
5710
5688
|
this.assertDataValid(d, t);
|
|
5711
5689
|
}
|
|
@@ -5714,7 +5692,7 @@
|
|
|
5714
5692
|
this.assertParameterValid(ep, d);
|
|
5715
5693
|
return true;
|
|
5716
5694
|
}
|
|
5717
|
-
catch
|
|
5695
|
+
catch {
|
|
5718
5696
|
return false;
|
|
5719
5697
|
}
|
|
5720
5698
|
}
|
|
@@ -5745,11 +5723,10 @@
|
|
|
5745
5723
|
}
|
|
5746
5724
|
function traceDumpFunc(blocks, cb) {
|
|
5747
5725
|
return (v) => {
|
|
5748
|
-
var _a;
|
|
5749
5726
|
if (Array.isArray(v) && !blocks) {
|
|
5750
5727
|
return;
|
|
5751
5728
|
}
|
|
5752
|
-
const macro =
|
|
5729
|
+
const macro = v.op[sourceReference]?.macro;
|
|
5753
5730
|
const msg = `${macro ? 'Macro' : 'Op'}: ${macro ? emitMicheline(macro, undefined, true) + ' / ' : ''}${emitMicheline(v.op)}
|
|
5754
5731
|
Input:
|
|
5755
5732
|
${formatStack(v.in)}
|
|
@@ -5760,9 +5737,8 @@ ${formatStack(v.out)}
|
|
|
5760
5737
|
};
|
|
5761
5738
|
}
|
|
5762
5739
|
function formatError(err) {
|
|
5763
|
-
var _a;
|
|
5764
5740
|
if (err instanceof MichelsonInstructionError) {
|
|
5765
|
-
const macro =
|
|
5741
|
+
const macro = err.val[sourceReference]?.macro;
|
|
5766
5742
|
return `${macro ? 'Macro' : 'Op'}: ${macro ? emitMicheline(macro, undefined, true) + ' / ' : ''}${emitMicheline(err.val)}
|
|
5767
5743
|
Stack:
|
|
5768
5744
|
${formatStack(err.stackState)}
|
|
@@ -5786,8 +5762,8 @@ ${err.data
|
|
|
5786
5762
|
|
|
5787
5763
|
// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT!
|
|
5788
5764
|
const VERSION = {
|
|
5789
|
-
"commitHash": "
|
|
5790
|
-
"version": "24.
|
|
5765
|
+
"commitHash": "27675679db6515e8b092195ef5c58c2c0ea5f5c8",
|
|
5766
|
+
"version": "24.3.0-beta.0"
|
|
5791
5767
|
};
|
|
5792
5768
|
|
|
5793
5769
|
exports.Contract = Contract;
|