@clarigen/cli 2.1.0 → 2.1.2
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/index.cjs +190 -158
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +444 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +181 -160
- package/dist/index.js.map +1 -1
- package/dist/run-cli.cjs +239 -202
- package/dist/run-cli.cjs.map +1 -1
- package/dist/run-cli.d.cts +1 -0
- package/dist/run-cli.js +230 -203
- package/dist/run-cli.js.map +1 -1
- package/package.json +3 -4
package/dist/index.cjs
CHANGED
|
@@ -1,38 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
9
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
-
var __spreadValues = (a, b) => {
|
|
13
|
-
for (var prop in b || (b = {}))
|
|
14
|
-
if (__hasOwnProp.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
if (__getOwnPropSymbols)
|
|
17
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
-
if (__propIsEnum.call(b, prop))
|
|
19
|
-
__defNormalProp(a, prop, b[prop]);
|
|
20
|
-
}
|
|
21
|
-
return a;
|
|
22
|
-
};
|
|
23
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
-
var __objRest = (source, exclude) => {
|
|
25
|
-
var target = {};
|
|
26
|
-
for (var prop in source)
|
|
27
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
if (source != null && __getOwnPropSymbols)
|
|
30
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
31
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
32
|
-
target[prop] = source[prop];
|
|
33
|
-
}
|
|
34
|
-
return target;
|
|
35
|
-
};
|
|
36
8
|
var __export = (target, all) => {
|
|
37
9
|
for (var name in all)
|
|
38
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -45,7 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
45
17
|
}
|
|
46
18
|
return to;
|
|
47
19
|
};
|
|
48
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
49
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
50
29
|
|
|
51
30
|
// src/index.ts
|
|
@@ -112,12 +91,14 @@ var import_core2 = require("@clarigen/core");
|
|
|
112
91
|
var import_pino = require("pino");
|
|
113
92
|
var import_pino_pretty = __toESM(require("pino-pretty"), 1);
|
|
114
93
|
var colorizedClarigen = `\x1B[33m[Clarigen]\x1B[0m`;
|
|
115
|
-
var logger = (0, import_pino.pino)(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
94
|
+
var logger = (0, import_pino.pino)(
|
|
95
|
+
(0, import_pino_pretty.default)({
|
|
96
|
+
colorize: true,
|
|
97
|
+
ignore: "pid,hostname,time",
|
|
98
|
+
messageFormat: `${colorizedClarigen} {msg}`,
|
|
99
|
+
minimumLevel: "debug"
|
|
100
|
+
})
|
|
101
|
+
);
|
|
121
102
|
logger.level = "info";
|
|
122
103
|
var log = logger;
|
|
123
104
|
|
|
@@ -213,8 +194,7 @@ function findItemNameFromLine(line) {
|
|
|
213
194
|
}
|
|
214
195
|
for (const type of VAR_TYPES) {
|
|
215
196
|
const prefix = `(define-${type} `;
|
|
216
|
-
if (!line.startsWith(prefix))
|
|
217
|
-
continue;
|
|
197
|
+
if (!line.startsWith(prefix)) continue;
|
|
218
198
|
const startString = line.slice(prefix.length);
|
|
219
199
|
const match = clarityNameMatcher(startString);
|
|
220
200
|
if (!match) {
|
|
@@ -230,11 +210,9 @@ function findAbiItemByName(abi, name) {
|
|
|
230
210
|
const fn = abi.functions.find((fn2) => {
|
|
231
211
|
return fn2.name === name;
|
|
232
212
|
});
|
|
233
|
-
if (fn)
|
|
234
|
-
return fn;
|
|
213
|
+
if (fn) return fn;
|
|
235
214
|
const map = abi.maps.find((m) => m.name === name);
|
|
236
|
-
if (map)
|
|
237
|
-
return map;
|
|
215
|
+
if (map) return map;
|
|
238
216
|
const v = abi.variables.find((v2) => v2.name === name);
|
|
239
217
|
return v;
|
|
240
218
|
}
|
|
@@ -245,8 +223,7 @@ function getFnName(line) {
|
|
|
245
223
|
const fnType = FN_TYPES.find((type) => {
|
|
246
224
|
return line.startsWith(`(define-${type}`);
|
|
247
225
|
});
|
|
248
|
-
if (typeof fnType === "undefined")
|
|
249
|
-
return;
|
|
226
|
+
if (typeof fnType === "undefined") return;
|
|
250
227
|
const prefix = `(define-${fnType} (`;
|
|
251
228
|
const startString = line.slice(prefix.length);
|
|
252
229
|
const match = clarityNameMatcher(startString);
|
|
@@ -260,10 +237,8 @@ function getFnName(line) {
|
|
|
260
237
|
function traceParens(line, count) {
|
|
261
238
|
let newCount = count;
|
|
262
239
|
line.split("").forEach((char) => {
|
|
263
|
-
if (char === "(")
|
|
264
|
-
|
|
265
|
-
if (char === ")")
|
|
266
|
-
newCount--;
|
|
240
|
+
if (char === "(") newCount++;
|
|
241
|
+
if (char === ")") newCount--;
|
|
267
242
|
});
|
|
268
243
|
return newCount;
|
|
269
244
|
}
|
|
@@ -284,8 +259,7 @@ function parseComments(comments, abi) {
|
|
|
284
259
|
}
|
|
285
260
|
return;
|
|
286
261
|
}
|
|
287
|
-
if (!("args" in abi))
|
|
288
|
-
return;
|
|
262
|
+
if (!("args" in abi)) return;
|
|
289
263
|
const [_full, name, _separator, rest] = paramMatches;
|
|
290
264
|
const arg = abi.args.find((arg2) => arg2.name === name);
|
|
291
265
|
if (!arg) {
|
|
@@ -313,8 +287,7 @@ function parseComments(comments, abi) {
|
|
|
313
287
|
async function afterDocs(config) {
|
|
314
288
|
var _a;
|
|
315
289
|
const command = (_a = config.docs) == null ? void 0 : _a.after;
|
|
316
|
-
if (!command)
|
|
317
|
-
return;
|
|
290
|
+
if (!command) return;
|
|
318
291
|
logger.debug(`Running after docs command: ${command}`);
|
|
319
292
|
const parts = command.split(" ");
|
|
320
293
|
const [cmd, ...args] = parts;
|
|
@@ -342,8 +315,7 @@ var import_core = require("@clarigen/core");
|
|
|
342
315
|
var import_promises = require("fs/promises");
|
|
343
316
|
var import_path = require("path");
|
|
344
317
|
function encodeVariableName(name) {
|
|
345
|
-
if (/^[A-Z\-_]*$/.test(name))
|
|
346
|
-
return name.replaceAll("-", "_");
|
|
318
|
+
if (/^[A-Z\-_]*$/.test(name)) return name.replaceAll("-", "_");
|
|
347
319
|
return (0, import_core.toCamelCase)(name);
|
|
348
320
|
}
|
|
349
321
|
async function fileExists(filename) {
|
|
@@ -438,7 +410,9 @@ ${fn.source.join("\n")}
|
|
|
438
410
|
\`\`\`
|
|
439
411
|
</details>
|
|
440
412
|
`;
|
|
441
|
-
const sig = `(define-${fn.abi.access.replace("_", "-")} (${fn.abi.name} (${paramSigs.join(
|
|
413
|
+
const sig = `(define-${fn.abi.access.replace("_", "-")} (${fn.abi.name} (${paramSigs.join(
|
|
414
|
+
" "
|
|
415
|
+
)}) ${returnType})`;
|
|
442
416
|
return `### ${fn.abi.name}
|
|
443
417
|
|
|
444
418
|
${link}
|
|
@@ -452,8 +426,7 @@ ${source}
|
|
|
452
426
|
${params}`;
|
|
453
427
|
}
|
|
454
428
|
function mdParams(fn) {
|
|
455
|
-
if (fn.abi.args.length === 0)
|
|
456
|
-
return "";
|
|
429
|
+
if (fn.abi.args.length === 0) return "";
|
|
457
430
|
const hasDescription = Object.values(fn.comments.params).some((p) => p.comments.length > 0);
|
|
458
431
|
const params = Object.values(fn.comments.params).map((p) => markdownParam(p, hasDescription));
|
|
459
432
|
return `**Parameters:**
|
|
@@ -465,8 +438,7 @@ ${params.join("\n")}`;
|
|
|
465
438
|
function markdownParam(param, withDescription) {
|
|
466
439
|
const typeString = (0, import_core2.getTypeString)(param.abi.type);
|
|
467
440
|
const base = `| ${param.abi.name} | ${typeString} |`;
|
|
468
|
-
if (!withDescription)
|
|
469
|
-
return base;
|
|
441
|
+
if (!withDescription) return base;
|
|
470
442
|
return `${base} ${param.comments.join(" ")} |`;
|
|
471
443
|
}
|
|
472
444
|
function markdownMap(map, contractFile) {
|
|
@@ -544,8 +516,7 @@ function generateReadme(session, excluded) {
|
|
|
544
516
|
const contractLines = [];
|
|
545
517
|
sortContracts(session.contracts).forEach((contract) => {
|
|
546
518
|
const name = (0, import_core2.getContractName)(contract.contract_id, false);
|
|
547
|
-
if (excluded[name])
|
|
548
|
-
return;
|
|
519
|
+
if (excluded[name]) return;
|
|
549
520
|
const fileName = `${name}.md`;
|
|
550
521
|
const line = `- [\`${name}\`](${fileName})`;
|
|
551
522
|
contractLines.push(line);
|
|
@@ -631,26 +602,25 @@ var Config = class {
|
|
|
631
602
|
var _a, _b;
|
|
632
603
|
const singlePath = (_a = this.configFile[type]) == null ? void 0 : _a.output;
|
|
633
604
|
const multiPath = ((_b = this.configFile[type]) == null ? void 0 : _b.outputs) || [];
|
|
634
|
-
if (singlePath !== void 0)
|
|
635
|
-
return [singlePath];
|
|
605
|
+
if (singlePath !== void 0) return [singlePath];
|
|
636
606
|
return multiPath;
|
|
637
607
|
}
|
|
638
608
|
outputResolve(type, filePath) {
|
|
639
609
|
const outputs = this.getOutputs(type);
|
|
640
|
-
if (!this.supports(type))
|
|
641
|
-
return null;
|
|
610
|
+
if (!this.supports(type)) return null;
|
|
642
611
|
return outputs.map((path) => {
|
|
643
612
|
return (0, import_path3.resolve)(this.cwd, path, filePath || "");
|
|
644
613
|
});
|
|
645
614
|
}
|
|
646
615
|
async writeOutput(type, contents, filePath) {
|
|
647
616
|
const paths = this.outputResolve(type, filePath);
|
|
648
|
-
if (paths === null)
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
617
|
+
if (paths === null) return null;
|
|
618
|
+
await Promise.all(
|
|
619
|
+
paths.map(async (path) => {
|
|
620
|
+
await writeFile(path, contents);
|
|
621
|
+
log.debug(`Generated ${type} file at ${(0, import_path3.relative)(this.cwd, path)}`);
|
|
622
|
+
})
|
|
623
|
+
);
|
|
654
624
|
return paths;
|
|
655
625
|
}
|
|
656
626
|
supports(type) {
|
|
@@ -677,13 +647,12 @@ function configFilePath(cwd) {
|
|
|
677
647
|
return (0, import_path3.resolve)(cwd ?? process.cwd(), CONFIG_FILE);
|
|
678
648
|
}
|
|
679
649
|
async function saveConfig(config) {
|
|
680
|
-
const configToml = (0, import_toml2.stringify)(
|
|
650
|
+
const configToml = (0, import_toml2.stringify)({ ...config });
|
|
681
651
|
await writeFile(configFilePath(), configToml);
|
|
682
652
|
}
|
|
683
653
|
var sessionConfig;
|
|
684
654
|
async function getConfig(cwd) {
|
|
685
|
-
if (typeof sessionConfig !== "undefined")
|
|
686
|
-
return sessionConfig;
|
|
655
|
+
if (typeof sessionConfig !== "undefined") return sessionConfig;
|
|
687
656
|
const path = configFilePath(cwd);
|
|
688
657
|
if (await fileExists(path)) {
|
|
689
658
|
const toml = await (0, import_promises3.readFile)(path, "utf-8");
|
|
@@ -721,42 +690,47 @@ async function generateDocs({
|
|
|
721
690
|
if (docsPathExt) {
|
|
722
691
|
log.warn(`Docs output path ('${docsBase}') looks like a file - it needs to be a directory.`);
|
|
723
692
|
}
|
|
724
|
-
const excluded = Object.fromEntries(
|
|
725
|
-
|
|
726
|
-
|
|
693
|
+
const excluded = Object.fromEntries(
|
|
694
|
+
(docs.exclude || []).map((e) => {
|
|
695
|
+
return [e, true];
|
|
696
|
+
})
|
|
697
|
+
);
|
|
727
698
|
log.debug(`Generating docs at path \`${docsBase}\``);
|
|
728
699
|
const docsBaseFolder = config.outputResolve("docs" /* Docs */, "./")[0];
|
|
729
|
-
const paths = await Promise.all(
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
return null;
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
700
|
+
const paths = await Promise.all(
|
|
701
|
+
session.contracts.map(async (contract) => {
|
|
702
|
+
var _a, _b;
|
|
703
|
+
const name = (0, import_core3.getContractName)(contract.contract_id, false);
|
|
704
|
+
if (excluded[name]) return null;
|
|
705
|
+
const docFile = `${name}.md`;
|
|
706
|
+
const contractPathDef = (_b = (_a = config.clarinet.contracts) == null ? void 0 : _a[name]) == null ? void 0 : _b.path;
|
|
707
|
+
let contractFile;
|
|
708
|
+
if (contractPathDef) {
|
|
709
|
+
const contractPathFull = config.joinFromClarinet(contractPathDef);
|
|
710
|
+
contractFile = (0, import_path4.relative)(docsBaseFolder, contractPathFull);
|
|
711
|
+
} else {
|
|
712
|
+
log.debug(`Couldn't find contract file from Clarinet.toml for contract ${name}`);
|
|
713
|
+
}
|
|
714
|
+
const md = generateMarkdown({ contract, contractFile });
|
|
715
|
+
const path = await config.writeOutput("docs" /* Docs */, md, docFile);
|
|
716
|
+
return path[0];
|
|
717
|
+
})
|
|
718
|
+
);
|
|
747
719
|
const readme = generateReadme(session, excluded);
|
|
748
720
|
paths.push((await config.writeOutput("docs" /* Docs */, readme, "README.md"))[0]);
|
|
749
721
|
await afterDocs(config);
|
|
750
722
|
}
|
|
751
723
|
function warnNoDocs() {
|
|
752
|
-
log.warn(
|
|
724
|
+
log.warn(
|
|
725
|
+
`
|
|
753
726
|
Clarigen config file doesn't include an output directory for docs.
|
|
754
727
|
|
|
755
728
|
To generate docs, specify 'docs.output' in your config file:
|
|
756
729
|
|
|
757
730
|
[docs]
|
|
758
731
|
output = "docs/"
|
|
759
|
-
`.trimEnd()
|
|
732
|
+
`.trimEnd()
|
|
733
|
+
);
|
|
760
734
|
}
|
|
761
735
|
|
|
762
736
|
// src/files/variables.ts
|
|
@@ -768,12 +742,10 @@ var import_core5 = require("@clarigen/core");
|
|
|
768
742
|
var jsTypeFromAbiType = (val, isArgument = false) => {
|
|
769
743
|
if ((0, import_core4.isClarityAbiPrimitive)(val)) {
|
|
770
744
|
if (val === "uint128") {
|
|
771
|
-
if (isArgument)
|
|
772
|
-
return "number | bigint";
|
|
745
|
+
if (isArgument) return "number | bigint";
|
|
773
746
|
return "bigint";
|
|
774
747
|
} else if (val === "int128") {
|
|
775
|
-
if (isArgument)
|
|
776
|
-
return "number | bigint";
|
|
748
|
+
if (isArgument) return "number | bigint";
|
|
777
749
|
return "bigint";
|
|
778
750
|
} else if (val === "bool") {
|
|
779
751
|
return "boolean";
|
|
@@ -841,7 +813,50 @@ function _hash(...words) {
|
|
|
841
813
|
}
|
|
842
814
|
return h;
|
|
843
815
|
}
|
|
844
|
-
var RESERVED = _hash(
|
|
816
|
+
var RESERVED = _hash(
|
|
817
|
+
// Keywords, ES6 11.6.2.1, http://www.ecma-international.org/ecma-262/6.0/index.html#sec-keywords
|
|
818
|
+
"break",
|
|
819
|
+
"do",
|
|
820
|
+
"in",
|
|
821
|
+
"typeof",
|
|
822
|
+
"case",
|
|
823
|
+
"else",
|
|
824
|
+
"instanceof",
|
|
825
|
+
"var",
|
|
826
|
+
"catch",
|
|
827
|
+
"export",
|
|
828
|
+
"new",
|
|
829
|
+
"void",
|
|
830
|
+
"class",
|
|
831
|
+
"extends",
|
|
832
|
+
"return",
|
|
833
|
+
"while",
|
|
834
|
+
"const",
|
|
835
|
+
"finally",
|
|
836
|
+
"super",
|
|
837
|
+
"with",
|
|
838
|
+
"continue",
|
|
839
|
+
"for",
|
|
840
|
+
"switch",
|
|
841
|
+
"yield",
|
|
842
|
+
"debugger",
|
|
843
|
+
"function",
|
|
844
|
+
"this",
|
|
845
|
+
"default",
|
|
846
|
+
"if",
|
|
847
|
+
"throw",
|
|
848
|
+
"delete",
|
|
849
|
+
"import",
|
|
850
|
+
"try",
|
|
851
|
+
// Future Reserved Words, ES6 11.6.2.2
|
|
852
|
+
// http://www.ecma-international.org/ecma-262/6.0/index.html#sec-future-reserved-words
|
|
853
|
+
"enum",
|
|
854
|
+
"await",
|
|
855
|
+
// NullLiteral & BooleanLiteral
|
|
856
|
+
"null",
|
|
857
|
+
"true",
|
|
858
|
+
"false"
|
|
859
|
+
);
|
|
845
860
|
|
|
846
861
|
// src/files/base.ts
|
|
847
862
|
var import_core7 = require("@clarigen/core");
|
|
@@ -849,10 +864,12 @@ var import_core7 = require("@clarigen/core");
|
|
|
849
864
|
// src/files/accounts.ts
|
|
850
865
|
function generateAccountsCode(accounts) {
|
|
851
866
|
const sortedAccounts = sortAccounts(accounts);
|
|
852
|
-
const namedAccounts = Object.fromEntries(
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
867
|
+
const namedAccounts = Object.fromEntries(
|
|
868
|
+
sortedAccounts.map((a) => {
|
|
869
|
+
const { name, ...rest } = a;
|
|
870
|
+
return [name, rest];
|
|
871
|
+
})
|
|
872
|
+
);
|
|
856
873
|
return JSON.stringify(namedAccounts);
|
|
857
874
|
}
|
|
858
875
|
function sortAccounts(accounts) {
|
|
@@ -868,10 +885,12 @@ function sortAccounts(accounts) {
|
|
|
868
885
|
// src/files/identifiers.ts
|
|
869
886
|
var import_core6 = require("@clarigen/core");
|
|
870
887
|
function generateIdentifiers(session) {
|
|
871
|
-
const identifiers = Object.fromEntries(
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
888
|
+
const identifiers = Object.fromEntries(
|
|
889
|
+
sortContracts(session.contracts).map((c) => {
|
|
890
|
+
const contractName = (0, import_core6.getContractName)(c.contract_id);
|
|
891
|
+
return [contractName, c.contract_id];
|
|
892
|
+
})
|
|
893
|
+
);
|
|
875
894
|
return identifiers;
|
|
876
895
|
}
|
|
877
896
|
function generateIdentifiersCode(session) {
|
|
@@ -884,7 +903,7 @@ var import_util = require("util");
|
|
|
884
903
|
function generateContractMeta(contract, constants) {
|
|
885
904
|
const abi = contract.contract_interface;
|
|
886
905
|
const functionLines = [];
|
|
887
|
-
const
|
|
906
|
+
const { functions, maps, variables, non_fungible_tokens, ...rest } = abi;
|
|
888
907
|
functions.forEach((func) => {
|
|
889
908
|
let functionLine = `${(0, import_core7.toCamelCase)(func.name)}: `;
|
|
890
909
|
const funcDef = JSON.stringify(func);
|
|
@@ -919,7 +938,8 @@ function generateContractMeta(contract, constants) {
|
|
|
919
938
|
}
|
|
920
939
|
var TYPE_IMPORTS = `import type { TypedAbiArg, TypedAbiFunction, TypedAbiMap, TypedAbiVariable, Response } from '@clarigen/core';`;
|
|
921
940
|
function generateBaseFile(session) {
|
|
922
|
-
const combined = session.contracts.map((c, i) =>
|
|
941
|
+
const combined = session.contracts.map((c, i) => ({
|
|
942
|
+
...c,
|
|
923
943
|
constants: session.variables[i]
|
|
924
944
|
}));
|
|
925
945
|
const contractDefs = sortContracts(combined).map((contract) => {
|
|
@@ -962,14 +982,20 @@ Uint8Array.prototype[import_util.inspect.custom] = function(depth, options) {
|
|
|
962
982
|
};
|
|
963
983
|
function serialize(obj) {
|
|
964
984
|
return (0, import_util.inspect)(obj, {
|
|
985
|
+
// showHidden: false,
|
|
986
|
+
// depth: 100,
|
|
987
|
+
// colors: false,
|
|
965
988
|
showHidden: false,
|
|
989
|
+
// iterableLimit: 100000,
|
|
966
990
|
compact: false,
|
|
991
|
+
// trailingComma: true,
|
|
967
992
|
depth: 100,
|
|
968
993
|
colors: false,
|
|
969
994
|
maxArrayLength: Infinity,
|
|
970
995
|
maxStringLength: Infinity,
|
|
971
996
|
breakLength: Infinity,
|
|
972
997
|
numericSeparator: true
|
|
998
|
+
// strAbbreviateSize: 100000,
|
|
973
999
|
});
|
|
974
1000
|
}
|
|
975
1001
|
function serializeLines(key, lines) {
|
|
@@ -989,7 +1015,9 @@ function getVariablesV2(contract, simnet, verbose) {
|
|
|
989
1015
|
const fakeId = `${(0, import_core8.getContractName)(contract.contract_id)}-vars`;
|
|
990
1016
|
logger.debug(`Deploying ${contract.contract_id} for variables.`);
|
|
991
1017
|
if (!contract.source) {
|
|
992
|
-
logger.debug(
|
|
1018
|
+
logger.debug(
|
|
1019
|
+
`Contract ${(0, import_core8.getContractName)(contract.contract_id)} has no source. Skipping variables.`
|
|
1020
|
+
);
|
|
993
1021
|
return {};
|
|
994
1022
|
}
|
|
995
1023
|
if (contract.contract_interface.variables.length === 0) {
|
|
@@ -1013,9 +1041,14 @@ function getVariablesV2(contract, simnet, verbose) {
|
|
|
1013
1041
|
|
|
1014
1042
|
${varFn}`;
|
|
1015
1043
|
try {
|
|
1016
|
-
const receipt = simnet.deployContract(
|
|
1017
|
-
|
|
1018
|
-
|
|
1044
|
+
const receipt = simnet.deployContract(
|
|
1045
|
+
fakeId,
|
|
1046
|
+
fullSrc,
|
|
1047
|
+
{
|
|
1048
|
+
clarityVersion: 3
|
|
1049
|
+
},
|
|
1050
|
+
deployer
|
|
1051
|
+
);
|
|
1019
1052
|
const result = receipt.result;
|
|
1020
1053
|
const varsAbi = {
|
|
1021
1054
|
tuple: []
|
|
@@ -1064,8 +1097,7 @@ function getContractTxs(batches) {
|
|
|
1064
1097
|
function getDeploymentContract(contractName, deployment) {
|
|
1065
1098
|
const txs = flatBatch(deployment.plan.batches);
|
|
1066
1099
|
for (const tx of txs) {
|
|
1067
|
-
if (!isContractTx(tx))
|
|
1068
|
-
continue;
|
|
1100
|
+
if (!isContractTx(tx)) continue;
|
|
1069
1101
|
if ("requirement-publish" in tx) {
|
|
1070
1102
|
const [_, name] = tx["requirement-publish"]["contract-id"].split(".");
|
|
1071
1103
|
if (name === contractName) {
|
|
@@ -1117,12 +1149,9 @@ function getIdentifier(tx) {
|
|
|
1117
1149
|
throw new Error(`Unable to find ID for contract.`);
|
|
1118
1150
|
}
|
|
1119
1151
|
function isContractTx(tx) {
|
|
1120
|
-
if ("contract-call" in tx)
|
|
1121
|
-
|
|
1122
|
-
if ("
|
|
1123
|
-
return false;
|
|
1124
|
-
if ("emulated-contract-call" in tx)
|
|
1125
|
-
return false;
|
|
1152
|
+
if ("contract-call" in tx) return false;
|
|
1153
|
+
if ("btc-transfer" in tx) return false;
|
|
1154
|
+
if ("emulated-contract-call" in tx) return false;
|
|
1126
1155
|
return true;
|
|
1127
1156
|
}
|
|
1128
1157
|
|
|
@@ -1136,16 +1165,18 @@ async function parseDeployment(path) {
|
|
|
1136
1165
|
}
|
|
1137
1166
|
var DEPLOYMENT_NETWORKS = ["devnet", "simnet", "testnet", "mainnet"];
|
|
1138
1167
|
async function getDeployments(config) {
|
|
1139
|
-
const entries = await Promise.all(
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1168
|
+
const entries = await Promise.all(
|
|
1169
|
+
DEPLOYMENT_NETWORKS.map(async (network) => {
|
|
1170
|
+
const file = `default.${network}-plan.yaml`;
|
|
1171
|
+
const path = (0, import_path5.join)((0, import_path5.dirname)(config.clarinetFile()), "deployments", file);
|
|
1172
|
+
let plan;
|
|
1173
|
+
try {
|
|
1174
|
+
plan = await parseDeployment(path);
|
|
1175
|
+
} catch (_) {
|
|
1176
|
+
}
|
|
1177
|
+
return [network, plan];
|
|
1178
|
+
})
|
|
1179
|
+
);
|
|
1149
1180
|
return Object.fromEntries(entries);
|
|
1150
1181
|
}
|
|
1151
1182
|
async function generateESMFile({
|
|
@@ -1176,24 +1207,28 @@ function insertNetworkId(deployments, identifier, network) {
|
|
|
1176
1207
|
}
|
|
1177
1208
|
function collectContractDeployments(session, deployments, config) {
|
|
1178
1209
|
var _a;
|
|
1179
|
-
const full = Object.fromEntries(
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
const
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1210
|
+
const full = Object.fromEntries(
|
|
1211
|
+
sortContracts(session.contracts).map((contract) => {
|
|
1212
|
+
const contractName = (0, import_core9.getContractName)(contract.contract_id);
|
|
1213
|
+
const contractDeployments = Object.fromEntries(
|
|
1214
|
+
DEPLOYMENT_NETWORKS.map((network) => {
|
|
1215
|
+
const deployment = deployments[network];
|
|
1216
|
+
if (typeof deployment === "undefined") {
|
|
1217
|
+
return [network, null];
|
|
1218
|
+
}
|
|
1219
|
+
try {
|
|
1220
|
+
const contractName2 = contract.contract_id.split(".")[1];
|
|
1221
|
+
const tx = getDeploymentContract(contractName2, deployment);
|
|
1222
|
+
const id = getIdentifier(tx);
|
|
1223
|
+
return [network, id];
|
|
1224
|
+
} catch (_) {
|
|
1225
|
+
return [network, null];
|
|
1226
|
+
}
|
|
1227
|
+
})
|
|
1228
|
+
);
|
|
1229
|
+
return [contractName, contractDeployments];
|
|
1230
|
+
})
|
|
1231
|
+
);
|
|
1197
1232
|
const deployer = session.accounts.find((a) => a.name === "deployer");
|
|
1198
1233
|
(_a = config.clarinet.project.requirements) == null ? void 0 : _a.forEach(({ contract_id }) => {
|
|
1199
1234
|
insertNetworkId(full, contract_id, "mainnet");
|
|
@@ -1210,8 +1245,7 @@ function collectContractDeployments(session, deployments, config) {
|
|
|
1210
1245
|
return full;
|
|
1211
1246
|
}
|
|
1212
1247
|
function collectDeploymentFiles(deployments, clarinetFolder, cwd) {
|
|
1213
|
-
if (!deployments.simnet)
|
|
1214
|
-
return [];
|
|
1248
|
+
if (!deployments.simnet) return [];
|
|
1215
1249
|
const simnet = deployments.simnet;
|
|
1216
1250
|
const txs = getContractTxs(simnet.plan.batches);
|
|
1217
1251
|
const entries = txs.map((tx) => {
|
|
@@ -1226,8 +1260,7 @@ function collectDeploymentFiles(deployments, clarinetFolder, cwd) {
|
|
|
1226
1260
|
}
|
|
1227
1261
|
function generateSimnetCode(config, deployments, _session) {
|
|
1228
1262
|
var _a;
|
|
1229
|
-
if (!((_a = config.esm) == null ? void 0 : _a.include_accounts))
|
|
1230
|
-
return "";
|
|
1263
|
+
if (!((_a = config.esm) == null ? void 0 : _a.include_accounts)) return "";
|
|
1231
1264
|
const clarinetFolder = (0, import_path5.dirname)(config.clarinetFile());
|
|
1232
1265
|
const files = collectDeploymentFiles(deployments, clarinetFolder, config.cwd);
|
|
1233
1266
|
return `
|
|
@@ -1237,8 +1270,7 @@ export const simnetDeployment = ${JSON.stringify(files)};
|
|
|
1237
1270
|
async function afterESM(config) {
|
|
1238
1271
|
var _a;
|
|
1239
1272
|
const command = (_a = config.esm) == null ? void 0 : _a.after;
|
|
1240
|
-
if (!command)
|
|
1241
|
-
return;
|
|
1273
|
+
if (!command) return;
|
|
1242
1274
|
logger.debug(`Running after ESM command: ${command}`);
|
|
1243
1275
|
const parts = command.split(" ");
|
|
1244
1276
|
const [cmd, ...args] = parts;
|