@clarigen/cli 2.1.1 → 2.1.3
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 +196 -163
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +456 -0
- package/dist/index.d.ts +13 -1
- package/dist/index.js +187 -165
- package/dist/index.js.map +1 -1
- package/dist/run-cli.cjs +252 -211
- package/dist/run-cli.cjs.map +1 -1
- package/dist/run-cli.d.cts +1 -0
- package/dist/run-cli.js +243 -212
- package/dist/run-cli.js.map +1 -1
- package/package.json +5 -6
package/dist/index.js
CHANGED
|
@@ -1,35 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __objRest = (source, exclude) => {
|
|
21
|
-
var target = {};
|
|
22
|
-
for (var prop in source)
|
|
23
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
-
target[prop] = source[prop];
|
|
25
|
-
if (source != null && __getOwnPropSymbols)
|
|
26
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
}
|
|
30
|
-
return target;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
1
|
// src/docs/markdown.ts
|
|
34
2
|
import { getContractName as getContractName2, getTypeString } from "@clarigen/core";
|
|
35
3
|
|
|
@@ -37,12 +5,14 @@ import { getContractName as getContractName2, getTypeString } from "@clarigen/co
|
|
|
37
5
|
import { pino } from "pino";
|
|
38
6
|
import pinoPretty from "pino-pretty";
|
|
39
7
|
var colorizedClarigen = `\x1B[33m[Clarigen]\x1B[0m`;
|
|
40
|
-
var logger = pino(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
8
|
+
var logger = pino(
|
|
9
|
+
pinoPretty({
|
|
10
|
+
colorize: true,
|
|
11
|
+
ignore: "pid,hostname,time",
|
|
12
|
+
messageFormat: `${colorizedClarigen} {msg}`,
|
|
13
|
+
minimumLevel: "debug"
|
|
14
|
+
})
|
|
15
|
+
);
|
|
46
16
|
logger.level = "info";
|
|
47
17
|
var log = logger;
|
|
48
18
|
|
|
@@ -138,8 +108,7 @@ function findItemNameFromLine(line) {
|
|
|
138
108
|
}
|
|
139
109
|
for (const type of VAR_TYPES) {
|
|
140
110
|
const prefix = `(define-${type} `;
|
|
141
|
-
if (!line.startsWith(prefix))
|
|
142
|
-
continue;
|
|
111
|
+
if (!line.startsWith(prefix)) continue;
|
|
143
112
|
const startString = line.slice(prefix.length);
|
|
144
113
|
const match = clarityNameMatcher(startString);
|
|
145
114
|
if (!match) {
|
|
@@ -155,11 +124,9 @@ function findAbiItemByName(abi, name) {
|
|
|
155
124
|
const fn = abi.functions.find((fn2) => {
|
|
156
125
|
return fn2.name === name;
|
|
157
126
|
});
|
|
158
|
-
if (fn)
|
|
159
|
-
return fn;
|
|
127
|
+
if (fn) return fn;
|
|
160
128
|
const map = abi.maps.find((m) => m.name === name);
|
|
161
|
-
if (map)
|
|
162
|
-
return map;
|
|
129
|
+
if (map) return map;
|
|
163
130
|
const v = abi.variables.find((v2) => v2.name === name);
|
|
164
131
|
return v;
|
|
165
132
|
}
|
|
@@ -170,8 +137,7 @@ function getFnName(line) {
|
|
|
170
137
|
const fnType = FN_TYPES.find((type) => {
|
|
171
138
|
return line.startsWith(`(define-${type}`);
|
|
172
139
|
});
|
|
173
|
-
if (typeof fnType === "undefined")
|
|
174
|
-
return;
|
|
140
|
+
if (typeof fnType === "undefined") return;
|
|
175
141
|
const prefix = `(define-${fnType} (`;
|
|
176
142
|
const startString = line.slice(prefix.length);
|
|
177
143
|
const match = clarityNameMatcher(startString);
|
|
@@ -185,10 +151,8 @@ function getFnName(line) {
|
|
|
185
151
|
function traceParens(line, count) {
|
|
186
152
|
let newCount = count;
|
|
187
153
|
line.split("").forEach((char) => {
|
|
188
|
-
if (char === "(")
|
|
189
|
-
|
|
190
|
-
if (char === ")")
|
|
191
|
-
newCount--;
|
|
154
|
+
if (char === "(") newCount++;
|
|
155
|
+
if (char === ")") newCount--;
|
|
192
156
|
});
|
|
193
157
|
return newCount;
|
|
194
158
|
}
|
|
@@ -209,8 +173,7 @@ function parseComments(comments, abi) {
|
|
|
209
173
|
}
|
|
210
174
|
return;
|
|
211
175
|
}
|
|
212
|
-
if (!("args" in abi))
|
|
213
|
-
return;
|
|
176
|
+
if (!("args" in abi)) return;
|
|
214
177
|
const [_full, name, _separator, rest] = paramMatches;
|
|
215
178
|
const arg = abi.args.find((arg2) => arg2.name === name);
|
|
216
179
|
if (!arg) {
|
|
@@ -238,8 +201,7 @@ function parseComments(comments, abi) {
|
|
|
238
201
|
async function afterDocs(config) {
|
|
239
202
|
var _a;
|
|
240
203
|
const command = (_a = config.docs) == null ? void 0 : _a.after;
|
|
241
|
-
if (!command)
|
|
242
|
-
return;
|
|
204
|
+
if (!command) return;
|
|
243
205
|
logger.debug(`Running after docs command: ${command}`);
|
|
244
206
|
const parts = command.split(" ");
|
|
245
207
|
const [cmd, ...args] = parts;
|
|
@@ -267,8 +229,7 @@ import { getContractName, toCamelCase } from "@clarigen/core";
|
|
|
267
229
|
import { stat, mkdir, writeFile as fsWriteFile } from "fs/promises";
|
|
268
230
|
import { dirname, relative } from "path";
|
|
269
231
|
function encodeVariableName(name) {
|
|
270
|
-
if (/^[A-Z\-_]*$/.test(name))
|
|
271
|
-
return name.replaceAll("-", "_");
|
|
232
|
+
if (/^[A-Z\-_]*$/.test(name)) return name.replaceAll("-", "_");
|
|
272
233
|
return toCamelCase(name);
|
|
273
234
|
}
|
|
274
235
|
async function fileExists(filename) {
|
|
@@ -363,7 +324,9 @@ ${fn.source.join("\n")}
|
|
|
363
324
|
\`\`\`
|
|
364
325
|
</details>
|
|
365
326
|
`;
|
|
366
|
-
const sig = `(define-${fn.abi.access.replace("_", "-")} (${fn.abi.name} (${paramSigs.join(
|
|
327
|
+
const sig = `(define-${fn.abi.access.replace("_", "-")} (${fn.abi.name} (${paramSigs.join(
|
|
328
|
+
" "
|
|
329
|
+
)}) ${returnType})`;
|
|
367
330
|
return `### ${fn.abi.name}
|
|
368
331
|
|
|
369
332
|
${link}
|
|
@@ -377,8 +340,7 @@ ${source}
|
|
|
377
340
|
${params}`;
|
|
378
341
|
}
|
|
379
342
|
function mdParams(fn) {
|
|
380
|
-
if (fn.abi.args.length === 0)
|
|
381
|
-
return "";
|
|
343
|
+
if (fn.abi.args.length === 0) return "";
|
|
382
344
|
const hasDescription = Object.values(fn.comments.params).some((p) => p.comments.length > 0);
|
|
383
345
|
const params = Object.values(fn.comments.params).map((p) => markdownParam(p, hasDescription));
|
|
384
346
|
return `**Parameters:**
|
|
@@ -390,8 +352,7 @@ ${params.join("\n")}`;
|
|
|
390
352
|
function markdownParam(param, withDescription) {
|
|
391
353
|
const typeString = getTypeString(param.abi.type);
|
|
392
354
|
const base = `| ${param.abi.name} | ${typeString} |`;
|
|
393
|
-
if (!withDescription)
|
|
394
|
-
return base;
|
|
355
|
+
if (!withDescription) return base;
|
|
395
356
|
return `${base} ${param.comments.join(" ")} |`;
|
|
396
357
|
}
|
|
397
358
|
function markdownMap(map, contractFile) {
|
|
@@ -469,8 +430,7 @@ function generateReadme(session, excluded) {
|
|
|
469
430
|
const contractLines = [];
|
|
470
431
|
sortContracts(session.contracts).forEach((contract) => {
|
|
471
432
|
const name = getContractName2(contract.contract_id, false);
|
|
472
|
-
if (excluded[name])
|
|
473
|
-
return;
|
|
433
|
+
if (excluded[name]) return;
|
|
474
434
|
const fileName = `${name}.md`;
|
|
475
435
|
const line = `- [\`${name}\`](${fileName})`;
|
|
476
436
|
contractLines.push(line);
|
|
@@ -518,7 +478,8 @@ var typesSchema = z2.object({
|
|
|
518
478
|
outputs: z2.array(z2.string()).optional(),
|
|
519
479
|
include_accounts: z2.boolean().optional(),
|
|
520
480
|
after: z2.string().optional(),
|
|
521
|
-
include_boot_contracts: z2.boolean().optional()
|
|
481
|
+
include_boot_contracts: z2.boolean().optional(),
|
|
482
|
+
watch_folders: z2.array(z2.string()).optional()
|
|
522
483
|
}).optional();
|
|
523
484
|
var ConfigFileSchema = z2.object({
|
|
524
485
|
clarinet: z2.string(),
|
|
@@ -556,26 +517,25 @@ var Config = class {
|
|
|
556
517
|
var _a, _b;
|
|
557
518
|
const singlePath = (_a = this.configFile[type]) == null ? void 0 : _a.output;
|
|
558
519
|
const multiPath = ((_b = this.configFile[type]) == null ? void 0 : _b.outputs) || [];
|
|
559
|
-
if (singlePath !== void 0)
|
|
560
|
-
return [singlePath];
|
|
520
|
+
if (singlePath !== void 0) return [singlePath];
|
|
561
521
|
return multiPath;
|
|
562
522
|
}
|
|
563
523
|
outputResolve(type, filePath) {
|
|
564
524
|
const outputs = this.getOutputs(type);
|
|
565
|
-
if (!this.supports(type))
|
|
566
|
-
return null;
|
|
525
|
+
if (!this.supports(type)) return null;
|
|
567
526
|
return outputs.map((path) => {
|
|
568
527
|
return resolve2(this.cwd, path, filePath || "");
|
|
569
528
|
});
|
|
570
529
|
}
|
|
571
530
|
async writeOutput(type, contents, filePath) {
|
|
572
531
|
const paths = this.outputResolve(type, filePath);
|
|
573
|
-
if (paths === null)
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
532
|
+
if (paths === null) return null;
|
|
533
|
+
await Promise.all(
|
|
534
|
+
paths.map(async (path) => {
|
|
535
|
+
await writeFile(path, contents);
|
|
536
|
+
log.debug(`Generated ${type} file at ${relative2(this.cwd, path)}`);
|
|
537
|
+
})
|
|
538
|
+
);
|
|
579
539
|
return paths;
|
|
580
540
|
}
|
|
581
541
|
supports(type) {
|
|
@@ -602,13 +562,12 @@ function configFilePath(cwd) {
|
|
|
602
562
|
return resolve2(cwd ?? process.cwd(), CONFIG_FILE);
|
|
603
563
|
}
|
|
604
564
|
async function saveConfig(config) {
|
|
605
|
-
const configToml = stringify(
|
|
565
|
+
const configToml = stringify({ ...config });
|
|
606
566
|
await writeFile(configFilePath(), configToml);
|
|
607
567
|
}
|
|
608
568
|
var sessionConfig;
|
|
609
569
|
async function getConfig(cwd) {
|
|
610
|
-
if (typeof sessionConfig !== "undefined")
|
|
611
|
-
return sessionConfig;
|
|
570
|
+
if (typeof sessionConfig !== "undefined") return sessionConfig;
|
|
612
571
|
const path = configFilePath(cwd);
|
|
613
572
|
if (await fileExists(path)) {
|
|
614
573
|
const toml = await readFile2(path, "utf-8");
|
|
@@ -646,42 +605,47 @@ async function generateDocs({
|
|
|
646
605
|
if (docsPathExt) {
|
|
647
606
|
log.warn(`Docs output path ('${docsBase}') looks like a file - it needs to be a directory.`);
|
|
648
607
|
}
|
|
649
|
-
const excluded = Object.fromEntries(
|
|
650
|
-
|
|
651
|
-
|
|
608
|
+
const excluded = Object.fromEntries(
|
|
609
|
+
(docs.exclude || []).map((e) => {
|
|
610
|
+
return [e, true];
|
|
611
|
+
})
|
|
612
|
+
);
|
|
652
613
|
log.debug(`Generating docs at path \`${docsBase}\``);
|
|
653
614
|
const docsBaseFolder = config.outputResolve("docs" /* Docs */, "./")[0];
|
|
654
|
-
const paths = await Promise.all(
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
return null;
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
615
|
+
const paths = await Promise.all(
|
|
616
|
+
session.contracts.map(async (contract) => {
|
|
617
|
+
var _a, _b;
|
|
618
|
+
const name = getContractName3(contract.contract_id, false);
|
|
619
|
+
if (excluded[name]) return null;
|
|
620
|
+
const docFile = `${name}.md`;
|
|
621
|
+
const contractPathDef = (_b = (_a = config.clarinet.contracts) == null ? void 0 : _a[name]) == null ? void 0 : _b.path;
|
|
622
|
+
let contractFile;
|
|
623
|
+
if (contractPathDef) {
|
|
624
|
+
const contractPathFull = config.joinFromClarinet(contractPathDef);
|
|
625
|
+
contractFile = relative3(docsBaseFolder, contractPathFull);
|
|
626
|
+
} else {
|
|
627
|
+
log.debug(`Couldn't find contract file from Clarinet.toml for contract ${name}`);
|
|
628
|
+
}
|
|
629
|
+
const md = generateMarkdown({ contract, contractFile });
|
|
630
|
+
const path = await config.writeOutput("docs" /* Docs */, md, docFile);
|
|
631
|
+
return path[0];
|
|
632
|
+
})
|
|
633
|
+
);
|
|
672
634
|
const readme = generateReadme(session, excluded);
|
|
673
635
|
paths.push((await config.writeOutput("docs" /* Docs */, readme, "README.md"))[0]);
|
|
674
636
|
await afterDocs(config);
|
|
675
637
|
}
|
|
676
638
|
function warnNoDocs() {
|
|
677
|
-
log.warn(
|
|
639
|
+
log.warn(
|
|
640
|
+
`
|
|
678
641
|
Clarigen config file doesn't include an output directory for docs.
|
|
679
642
|
|
|
680
643
|
To generate docs, specify 'docs.output' in your config file:
|
|
681
644
|
|
|
682
645
|
[docs]
|
|
683
646
|
output = "docs/"
|
|
684
|
-
`.trimEnd()
|
|
647
|
+
`.trimEnd()
|
|
648
|
+
);
|
|
685
649
|
}
|
|
686
650
|
|
|
687
651
|
// src/files/variables.ts
|
|
@@ -706,12 +670,10 @@ import { toCamelCase as toCamelCase2 } from "@clarigen/core";
|
|
|
706
670
|
var jsTypeFromAbiType = (val, isArgument = false) => {
|
|
707
671
|
if (isClarityAbiPrimitive(val)) {
|
|
708
672
|
if (val === "uint128") {
|
|
709
|
-
if (isArgument)
|
|
710
|
-
return "number | bigint";
|
|
673
|
+
if (isArgument) return "number | bigint";
|
|
711
674
|
return "bigint";
|
|
712
675
|
} else if (val === "int128") {
|
|
713
|
-
if (isArgument)
|
|
714
|
-
return "number | bigint";
|
|
676
|
+
if (isArgument) return "number | bigint";
|
|
715
677
|
return "bigint";
|
|
716
678
|
} else if (val === "bool") {
|
|
717
679
|
return "boolean";
|
|
@@ -779,7 +741,50 @@ function _hash(...words) {
|
|
|
779
741
|
}
|
|
780
742
|
return h;
|
|
781
743
|
}
|
|
782
|
-
var RESERVED = _hash(
|
|
744
|
+
var RESERVED = _hash(
|
|
745
|
+
// Keywords, ES6 11.6.2.1, http://www.ecma-international.org/ecma-262/6.0/index.html#sec-keywords
|
|
746
|
+
"break",
|
|
747
|
+
"do",
|
|
748
|
+
"in",
|
|
749
|
+
"typeof",
|
|
750
|
+
"case",
|
|
751
|
+
"else",
|
|
752
|
+
"instanceof",
|
|
753
|
+
"var",
|
|
754
|
+
"catch",
|
|
755
|
+
"export",
|
|
756
|
+
"new",
|
|
757
|
+
"void",
|
|
758
|
+
"class",
|
|
759
|
+
"extends",
|
|
760
|
+
"return",
|
|
761
|
+
"while",
|
|
762
|
+
"const",
|
|
763
|
+
"finally",
|
|
764
|
+
"super",
|
|
765
|
+
"with",
|
|
766
|
+
"continue",
|
|
767
|
+
"for",
|
|
768
|
+
"switch",
|
|
769
|
+
"yield",
|
|
770
|
+
"debugger",
|
|
771
|
+
"function",
|
|
772
|
+
"this",
|
|
773
|
+
"default",
|
|
774
|
+
"if",
|
|
775
|
+
"throw",
|
|
776
|
+
"delete",
|
|
777
|
+
"import",
|
|
778
|
+
"try",
|
|
779
|
+
// Future Reserved Words, ES6 11.6.2.2
|
|
780
|
+
// http://www.ecma-international.org/ecma-262/6.0/index.html#sec-future-reserved-words
|
|
781
|
+
"enum",
|
|
782
|
+
"await",
|
|
783
|
+
// NullLiteral & BooleanLiteral
|
|
784
|
+
"null",
|
|
785
|
+
"true",
|
|
786
|
+
"false"
|
|
787
|
+
);
|
|
783
788
|
|
|
784
789
|
// src/files/base.ts
|
|
785
790
|
import { toCamelCase as toCamelCase3 } from "@clarigen/core";
|
|
@@ -787,10 +792,12 @@ import { toCamelCase as toCamelCase3 } from "@clarigen/core";
|
|
|
787
792
|
// src/files/accounts.ts
|
|
788
793
|
function generateAccountsCode(accounts) {
|
|
789
794
|
const sortedAccounts = sortAccounts(accounts);
|
|
790
|
-
const namedAccounts = Object.fromEntries(
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
795
|
+
const namedAccounts = Object.fromEntries(
|
|
796
|
+
sortedAccounts.map((a) => {
|
|
797
|
+
const { name, ...rest } = a;
|
|
798
|
+
return [name, rest];
|
|
799
|
+
})
|
|
800
|
+
);
|
|
794
801
|
return JSON.stringify(namedAccounts);
|
|
795
802
|
}
|
|
796
803
|
function sortAccounts(accounts) {
|
|
@@ -806,10 +813,12 @@ function sortAccounts(accounts) {
|
|
|
806
813
|
// src/files/identifiers.ts
|
|
807
814
|
import { getContractName as getContractName4 } from "@clarigen/core";
|
|
808
815
|
function generateIdentifiers(session) {
|
|
809
|
-
const identifiers = Object.fromEntries(
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
816
|
+
const identifiers = Object.fromEntries(
|
|
817
|
+
sortContracts(session.contracts).map((c) => {
|
|
818
|
+
const contractName = getContractName4(c.contract_id);
|
|
819
|
+
return [contractName, c.contract_id];
|
|
820
|
+
})
|
|
821
|
+
);
|
|
813
822
|
return identifiers;
|
|
814
823
|
}
|
|
815
824
|
function generateIdentifiersCode(session) {
|
|
@@ -822,7 +831,7 @@ import { inspect } from "util";
|
|
|
822
831
|
function generateContractMeta(contract, constants) {
|
|
823
832
|
const abi = contract.contract_interface;
|
|
824
833
|
const functionLines = [];
|
|
825
|
-
const
|
|
834
|
+
const { functions, maps, variables, non_fungible_tokens, ...rest } = abi;
|
|
826
835
|
functions.forEach((func) => {
|
|
827
836
|
let functionLine = `${toCamelCase3(func.name)}: `;
|
|
828
837
|
const funcDef = JSON.stringify(func);
|
|
@@ -857,7 +866,8 @@ function generateContractMeta(contract, constants) {
|
|
|
857
866
|
}
|
|
858
867
|
var TYPE_IMPORTS = `import type { TypedAbiArg, TypedAbiFunction, TypedAbiMap, TypedAbiVariable, Response } from '@clarigen/core';`;
|
|
859
868
|
function generateBaseFile(session) {
|
|
860
|
-
const combined = session.contracts.map((c, i) =>
|
|
869
|
+
const combined = session.contracts.map((c, i) => ({
|
|
870
|
+
...c,
|
|
861
871
|
constants: session.variables[i]
|
|
862
872
|
}));
|
|
863
873
|
const contractDefs = sortContracts(combined).map((contract) => {
|
|
@@ -900,14 +910,20 @@ Uint8Array.prototype[inspect.custom] = function(depth, options) {
|
|
|
900
910
|
};
|
|
901
911
|
function serialize(obj) {
|
|
902
912
|
return inspect(obj, {
|
|
913
|
+
// showHidden: false,
|
|
914
|
+
// depth: 100,
|
|
915
|
+
// colors: false,
|
|
903
916
|
showHidden: false,
|
|
917
|
+
// iterableLimit: 100000,
|
|
904
918
|
compact: false,
|
|
919
|
+
// trailingComma: true,
|
|
905
920
|
depth: 100,
|
|
906
921
|
colors: false,
|
|
907
922
|
maxArrayLength: Infinity,
|
|
908
923
|
maxStringLength: Infinity,
|
|
909
924
|
breakLength: Infinity,
|
|
910
925
|
numericSeparator: true
|
|
926
|
+
// strAbbreviateSize: 100000,
|
|
911
927
|
});
|
|
912
928
|
}
|
|
913
929
|
function serializeLines(key, lines) {
|
|
@@ -927,7 +943,9 @@ function getVariablesV2(contract, simnet, verbose) {
|
|
|
927
943
|
const fakeId = `${getContractName5(contract.contract_id)}-vars`;
|
|
928
944
|
logger.debug(`Deploying ${contract.contract_id} for variables.`);
|
|
929
945
|
if (!contract.source) {
|
|
930
|
-
logger.debug(
|
|
946
|
+
logger.debug(
|
|
947
|
+
`Contract ${getContractName5(contract.contract_id)} has no source. Skipping variables.`
|
|
948
|
+
);
|
|
931
949
|
return {};
|
|
932
950
|
}
|
|
933
951
|
if (contract.contract_interface.variables.length === 0) {
|
|
@@ -951,9 +969,14 @@ function getVariablesV2(contract, simnet, verbose) {
|
|
|
951
969
|
|
|
952
970
|
${varFn}`;
|
|
953
971
|
try {
|
|
954
|
-
const receipt = simnet.deployContract(
|
|
955
|
-
|
|
956
|
-
|
|
972
|
+
const receipt = simnet.deployContract(
|
|
973
|
+
fakeId,
|
|
974
|
+
fullSrc,
|
|
975
|
+
{
|
|
976
|
+
clarityVersion: 3
|
|
977
|
+
},
|
|
978
|
+
deployer
|
|
979
|
+
);
|
|
957
980
|
const result = receipt.result;
|
|
958
981
|
const varsAbi = {
|
|
959
982
|
tuple: []
|
|
@@ -970,10 +993,10 @@ ${varFn}`;
|
|
|
970
993
|
}
|
|
971
994
|
return cvToValue(result, true);
|
|
972
995
|
} catch (error) {
|
|
973
|
-
logger.
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
996
|
+
logger.warn(
|
|
997
|
+
{ err: error },
|
|
998
|
+
`Error getting variables for ${getContractName5(contract.contract_id, false)}`
|
|
999
|
+
);
|
|
977
1000
|
return {};
|
|
978
1001
|
}
|
|
979
1002
|
}
|
|
@@ -1002,8 +1025,7 @@ function getContractTxs(batches) {
|
|
|
1002
1025
|
function getDeploymentContract(contractName, deployment) {
|
|
1003
1026
|
const txs = flatBatch(deployment.plan.batches);
|
|
1004
1027
|
for (const tx of txs) {
|
|
1005
|
-
if (!isContractTx(tx))
|
|
1006
|
-
continue;
|
|
1028
|
+
if (!isContractTx(tx)) continue;
|
|
1007
1029
|
if ("requirement-publish" in tx) {
|
|
1008
1030
|
const [_, name] = tx["requirement-publish"]["contract-id"].split(".");
|
|
1009
1031
|
if (name === contractName) {
|
|
@@ -1055,12 +1077,9 @@ function getIdentifier(tx) {
|
|
|
1055
1077
|
throw new Error(`Unable to find ID for contract.`);
|
|
1056
1078
|
}
|
|
1057
1079
|
function isContractTx(tx) {
|
|
1058
|
-
if ("contract-call" in tx)
|
|
1059
|
-
|
|
1060
|
-
if ("
|
|
1061
|
-
return false;
|
|
1062
|
-
if ("emulated-contract-call" in tx)
|
|
1063
|
-
return false;
|
|
1080
|
+
if ("contract-call" in tx) return false;
|
|
1081
|
+
if ("btc-transfer" in tx) return false;
|
|
1082
|
+
if ("emulated-contract-call" in tx) return false;
|
|
1064
1083
|
return true;
|
|
1065
1084
|
}
|
|
1066
1085
|
|
|
@@ -1074,16 +1093,18 @@ async function parseDeployment(path) {
|
|
|
1074
1093
|
}
|
|
1075
1094
|
var DEPLOYMENT_NETWORKS = ["devnet", "simnet", "testnet", "mainnet"];
|
|
1076
1095
|
async function getDeployments(config) {
|
|
1077
|
-
const entries = await Promise.all(
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1096
|
+
const entries = await Promise.all(
|
|
1097
|
+
DEPLOYMENT_NETWORKS.map(async (network) => {
|
|
1098
|
+
const file = `default.${network}-plan.yaml`;
|
|
1099
|
+
const path = join2(dirname3(config.clarinetFile()), "deployments", file);
|
|
1100
|
+
let plan;
|
|
1101
|
+
try {
|
|
1102
|
+
plan = await parseDeployment(path);
|
|
1103
|
+
} catch (_) {
|
|
1104
|
+
}
|
|
1105
|
+
return [network, plan];
|
|
1106
|
+
})
|
|
1107
|
+
);
|
|
1087
1108
|
return Object.fromEntries(entries);
|
|
1088
1109
|
}
|
|
1089
1110
|
async function generateESMFile({
|
|
@@ -1114,24 +1135,28 @@ function insertNetworkId(deployments, identifier, network) {
|
|
|
1114
1135
|
}
|
|
1115
1136
|
function collectContractDeployments(session, deployments, config) {
|
|
1116
1137
|
var _a;
|
|
1117
|
-
const full = Object.fromEntries(
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
const
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1138
|
+
const full = Object.fromEntries(
|
|
1139
|
+
sortContracts(session.contracts).map((contract) => {
|
|
1140
|
+
const contractName = getContractName6(contract.contract_id);
|
|
1141
|
+
const contractDeployments = Object.fromEntries(
|
|
1142
|
+
DEPLOYMENT_NETWORKS.map((network) => {
|
|
1143
|
+
const deployment = deployments[network];
|
|
1144
|
+
if (typeof deployment === "undefined") {
|
|
1145
|
+
return [network, null];
|
|
1146
|
+
}
|
|
1147
|
+
try {
|
|
1148
|
+
const contractName2 = contract.contract_id.split(".")[1];
|
|
1149
|
+
const tx = getDeploymentContract(contractName2, deployment);
|
|
1150
|
+
const id = getIdentifier(tx);
|
|
1151
|
+
return [network, id];
|
|
1152
|
+
} catch (_) {
|
|
1153
|
+
return [network, null];
|
|
1154
|
+
}
|
|
1155
|
+
})
|
|
1156
|
+
);
|
|
1157
|
+
return [contractName, contractDeployments];
|
|
1158
|
+
})
|
|
1159
|
+
);
|
|
1135
1160
|
const deployer = session.accounts.find((a) => a.name === "deployer");
|
|
1136
1161
|
(_a = config.clarinet.project.requirements) == null ? void 0 : _a.forEach(({ contract_id }) => {
|
|
1137
1162
|
insertNetworkId(full, contract_id, "mainnet");
|
|
@@ -1148,8 +1173,7 @@ function collectContractDeployments(session, deployments, config) {
|
|
|
1148
1173
|
return full;
|
|
1149
1174
|
}
|
|
1150
1175
|
function collectDeploymentFiles(deployments, clarinetFolder, cwd) {
|
|
1151
|
-
if (!deployments.simnet)
|
|
1152
|
-
return [];
|
|
1176
|
+
if (!deployments.simnet) return [];
|
|
1153
1177
|
const simnet = deployments.simnet;
|
|
1154
1178
|
const txs = getContractTxs(simnet.plan.batches);
|
|
1155
1179
|
const entries = txs.map((tx) => {
|
|
@@ -1164,8 +1188,7 @@ function collectDeploymentFiles(deployments, clarinetFolder, cwd) {
|
|
|
1164
1188
|
}
|
|
1165
1189
|
function generateSimnetCode(config, deployments, _session) {
|
|
1166
1190
|
var _a;
|
|
1167
|
-
if (!((_a = config.esm) == null ? void 0 : _a.include_accounts))
|
|
1168
|
-
return "";
|
|
1191
|
+
if (!((_a = config.esm) == null ? void 0 : _a.include_accounts)) return "";
|
|
1169
1192
|
const clarinetFolder = dirname3(config.clarinetFile());
|
|
1170
1193
|
const files = collectDeploymentFiles(deployments, clarinetFolder, config.cwd);
|
|
1171
1194
|
return `
|
|
@@ -1175,8 +1198,7 @@ export const simnetDeployment = ${JSON.stringify(files)};
|
|
|
1175
1198
|
async function afterESM(config) {
|
|
1176
1199
|
var _a;
|
|
1177
1200
|
const command = (_a = config.esm) == null ? void 0 : _a.after;
|
|
1178
|
-
if (!command)
|
|
1179
|
-
return;
|
|
1201
|
+
if (!command) return;
|
|
1180
1202
|
logger.debug(`Running after ESM command: ${command}`);
|
|
1181
1203
|
const parts = command.split(" ");
|
|
1182
1204
|
const [cmd, ...args] = parts;
|