pha-deploy 0.2.3 → 0.4.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/README.md +228 -249
- package/config/config.example.toml +12 -7
- package/dist/actions/createSeries.d.ts.map +1 -1
- package/dist/actions/createSeries.js +1 -1
- package/dist/actions/createSeries.js.map +1 -1
- package/dist/actions/mintNftToken.d.ts +2 -2
- package/dist/actions/mintNftToken.d.ts.map +1 -1
- package/dist/actions/mintNftToken.js +26 -10
- package/dist/actions/mintNftToken.js.map +1 -1
- package/dist/cli-contract.d.ts +2 -0
- package/dist/cli-contract.d.ts.map +1 -0
- package/dist/cli-contract.js +247 -0
- package/dist/cli-contract.js.map +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +18 -4
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +2 -0
- package/dist/config.js.map +1 -1
- package/dist/contract/artifacts.d.ts +30 -0
- package/dist/contract/artifacts.d.ts.map +1 -0
- package/dist/contract/artifacts.js +142 -0
- package/dist/contract/artifacts.js.map +1 -0
- package/dist/contract/compiler.d.ts +43 -0
- package/dist/contract/compiler.d.ts.map +1 -0
- package/dist/contract/compiler.js +202 -0
- package/dist/contract/compiler.js.map +1 -0
- package/dist/contract/deploy.d.ts +34 -0
- package/dist/contract/deploy.d.ts.map +1 -0
- package/dist/contract/deploy.js +69 -0
- package/dist/contract/deploy.js.map +1 -0
- package/dist/version.d.ts +9 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +52 -0
- package/dist/version.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.MIN_SUPPORTED_PHA_TOMB_VERSION = exports.CONTRACT_COMPILER_NAME = void 0;
|
|
7
|
+
exports.isSemverGte = isSemverGte;
|
|
8
|
+
exports.findExecutableInPath = findExecutableInPath;
|
|
9
|
+
exports.queryCompilerVersion = queryCompilerVersion;
|
|
10
|
+
exports.findInstalledCompiler = findInstalledCompiler;
|
|
11
|
+
exports.resolveSupportedCompiler = resolveSupportedCompiler;
|
|
12
|
+
exports.buildCompileArgs = buildCompileArgs;
|
|
13
|
+
exports.runCompiler = runCompiler;
|
|
14
|
+
exports.selectCompiledContractArtifacts = selectCompiledContractArtifacts;
|
|
15
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
16
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
17
|
+
const node_child_process_1 = require("node:child_process");
|
|
18
|
+
exports.CONTRACT_COMPILER_NAME = "pha-tomb";
|
|
19
|
+
exports.MIN_SUPPORTED_PHA_TOMB_VERSION = "2.0.0";
|
|
20
|
+
function parseSemver(version) {
|
|
21
|
+
const match = version.trim().match(/^(\d+)\.(\d+)\.(\d+)/);
|
|
22
|
+
if (!match) {
|
|
23
|
+
throw new Error(`Unsupported semantic version: ${version}`);
|
|
24
|
+
}
|
|
25
|
+
return [
|
|
26
|
+
Number(match[1]),
|
|
27
|
+
Number(match[2]),
|
|
28
|
+
Number(match[3]),
|
|
29
|
+
];
|
|
30
|
+
}
|
|
31
|
+
function isSemverGte(actual, minimum) {
|
|
32
|
+
const actualParts = parseSemver(actual);
|
|
33
|
+
const minimumParts = parseSemver(minimum);
|
|
34
|
+
for (let i = 0; i < actualParts.length; i += 1) {
|
|
35
|
+
const a = actualParts[i] ?? 0;
|
|
36
|
+
const b = minimumParts[i] ?? 0;
|
|
37
|
+
if (a > b) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
if (a < b) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
function findExecutableInPath(executableName, envPath = process.env.PATH ?? "", platform = process.platform) {
|
|
47
|
+
const pathEntries = envPath.split(node_path_1.default.delimiter).filter(Boolean);
|
|
48
|
+
const candidateNames = platform === "win32"
|
|
49
|
+
? [executableName, `${executableName}.exe`, `${executableName}.cmd`, `${executableName}.bat`]
|
|
50
|
+
: [executableName];
|
|
51
|
+
for (const entry of pathEntries) {
|
|
52
|
+
for (const candidateName of candidateNames) {
|
|
53
|
+
const candidatePath = node_path_1.default.join(entry, candidateName);
|
|
54
|
+
try {
|
|
55
|
+
node_fs_1.default.accessSync(candidatePath, node_fs_1.default.constants.X_OK);
|
|
56
|
+
return candidatePath;
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
async function runCommandCapture(command, args, cwd) {
|
|
66
|
+
return await new Promise((resolve, reject) => {
|
|
67
|
+
const child = (0, node_child_process_1.spawn)(command, args, {
|
|
68
|
+
cwd,
|
|
69
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
70
|
+
});
|
|
71
|
+
let stdout = "";
|
|
72
|
+
let stderr = "";
|
|
73
|
+
child.stdout.setEncoding("utf8");
|
|
74
|
+
child.stderr.setEncoding("utf8");
|
|
75
|
+
child.stdout.on("data", (chunk) => {
|
|
76
|
+
stdout += chunk;
|
|
77
|
+
});
|
|
78
|
+
child.stderr.on("data", (chunk) => {
|
|
79
|
+
stderr += chunk;
|
|
80
|
+
});
|
|
81
|
+
child.on("error", reject);
|
|
82
|
+
child.on("close", (code) => {
|
|
83
|
+
resolve({
|
|
84
|
+
command,
|
|
85
|
+
args,
|
|
86
|
+
cwd,
|
|
87
|
+
stdout,
|
|
88
|
+
stderr,
|
|
89
|
+
exitCode: code ?? -1,
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async function queryCompilerVersion(executablePath) {
|
|
95
|
+
const result = await runCommandCapture(executablePath, ["--version"], process.cwd());
|
|
96
|
+
if (result.exitCode !== 0) {
|
|
97
|
+
throw new Error(`${exports.CONTRACT_COMPILER_NAME} --version exited with code ${result.exitCode}: ${result.stderr.trim() || result.stdout.trim() || "no diagnostics"}`);
|
|
98
|
+
}
|
|
99
|
+
const versionLine = result.stdout
|
|
100
|
+
.split(/\r?\n/)
|
|
101
|
+
.map((line) => line.trim())
|
|
102
|
+
.find((line) => line.length > 0);
|
|
103
|
+
if (!versionLine) {
|
|
104
|
+
throw new Error(`${exports.CONTRACT_COMPILER_NAME} --version returned no output`);
|
|
105
|
+
}
|
|
106
|
+
return versionLine;
|
|
107
|
+
}
|
|
108
|
+
async function findInstalledCompiler(envPath = process.env.PATH ?? "") {
|
|
109
|
+
const executablePath = findExecutableInPath(exports.CONTRACT_COMPILER_NAME, envPath);
|
|
110
|
+
if (!executablePath) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
executableName: exports.CONTRACT_COMPILER_NAME,
|
|
115
|
+
executablePath,
|
|
116
|
+
version: await queryCompilerVersion(executablePath),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
async function resolveSupportedCompiler(minimumVersion = exports.MIN_SUPPORTED_PHA_TOMB_VERSION, envPath = process.env.PATH ?? "") {
|
|
120
|
+
const compiler = await findInstalledCompiler(envPath);
|
|
121
|
+
if (!compiler) {
|
|
122
|
+
throw new Error(`${exports.CONTRACT_COMPILER_NAME} was not found in PATH`);
|
|
123
|
+
}
|
|
124
|
+
if (!isSemverGte(compiler.version, minimumVersion)) {
|
|
125
|
+
throw new Error(`${exports.CONTRACT_COMPILER_NAME} ${compiler.version} is below the minimum supported version ${minimumVersion}`);
|
|
126
|
+
}
|
|
127
|
+
return compiler;
|
|
128
|
+
}
|
|
129
|
+
function buildCompileArgs(options) {
|
|
130
|
+
const args = [
|
|
131
|
+
`output:${node_path_1.default.resolve(options.outputRoot)}`,
|
|
132
|
+
];
|
|
133
|
+
if (options.protocol !== undefined) {
|
|
134
|
+
args.push(`protocol:${options.protocol}`);
|
|
135
|
+
}
|
|
136
|
+
for (const libPath of options.libPaths ?? []) {
|
|
137
|
+
args.push(`libpath:${node_path_1.default.resolve(libPath)}`);
|
|
138
|
+
}
|
|
139
|
+
if (options.debug) {
|
|
140
|
+
args.push("debug");
|
|
141
|
+
}
|
|
142
|
+
if (options.nativeCheck) {
|
|
143
|
+
args.push(`nativecheck:${options.nativeCheck}`);
|
|
144
|
+
}
|
|
145
|
+
args.push(node_path_1.default.resolve(options.sourcePath));
|
|
146
|
+
return args;
|
|
147
|
+
}
|
|
148
|
+
async function runCompiler(executablePath, args, cwd) {
|
|
149
|
+
return await runCommandCapture(executablePath, args, cwd);
|
|
150
|
+
}
|
|
151
|
+
function selectCompiledContractArtifacts(compilerOutputDir, requestedContractName) {
|
|
152
|
+
const normalizedOutputDir = node_path_1.default.resolve(compilerOutputDir);
|
|
153
|
+
if (!node_fs_1.default.existsSync(normalizedOutputDir)) {
|
|
154
|
+
throw new Error(`Compiler output directory does not exist: ${normalizedOutputDir}`);
|
|
155
|
+
}
|
|
156
|
+
const entries = node_fs_1.default.readdirSync(normalizedOutputDir, { withFileTypes: true });
|
|
157
|
+
const pvmFiles = entries
|
|
158
|
+
.filter((entry) => entry.isFile() && entry.name.endsWith(".pvm"))
|
|
159
|
+
.map((entry) => entry.name)
|
|
160
|
+
.sort();
|
|
161
|
+
if (pvmFiles.length === 0) {
|
|
162
|
+
throw new Error(`No .pvm artifacts were produced in ${normalizedOutputDir}`);
|
|
163
|
+
}
|
|
164
|
+
const requestedName = requestedContractName?.trim();
|
|
165
|
+
let selectedBaseName = null;
|
|
166
|
+
if (requestedName) {
|
|
167
|
+
const requestedFile = `${requestedName}.pvm`;
|
|
168
|
+
if (pvmFiles.includes(requestedFile)) {
|
|
169
|
+
selectedBaseName = requestedName;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (!selectedBaseName && pvmFiles.length === 1) {
|
|
173
|
+
selectedBaseName = node_path_1.default.basename(pvmFiles[0], ".pvm");
|
|
174
|
+
}
|
|
175
|
+
if (!selectedBaseName) {
|
|
176
|
+
const candidates = pvmFiles.map((file) => node_path_1.default.basename(file, ".pvm")).join(", ");
|
|
177
|
+
if (requestedName) {
|
|
178
|
+
throw new Error(`Requested contract '${requestedName}' was not found in compiler output. Available artifacts: ${candidates}`);
|
|
179
|
+
}
|
|
180
|
+
throw new Error(`Compiler produced multiple .pvm artifacts. Use --contract-name to select one of: ${candidates}`);
|
|
181
|
+
}
|
|
182
|
+
const scriptPath = node_path_1.default.join(normalizedOutputDir, `${selectedBaseName}.pvm`);
|
|
183
|
+
const abiPath = node_path_1.default.join(normalizedOutputDir, `${selectedBaseName}.abi`);
|
|
184
|
+
if (!node_fs_1.default.existsSync(abiPath)) {
|
|
185
|
+
throw new Error(`ABI artifact is missing for contract '${selectedBaseName}': ${abiPath}`);
|
|
186
|
+
}
|
|
187
|
+
const optionalFile = (suffix) => {
|
|
188
|
+
const candidate = node_path_1.default.join(normalizedOutputDir, `${selectedBaseName}${suffix}`);
|
|
189
|
+
return node_fs_1.default.existsSync(candidate) ? candidate : undefined;
|
|
190
|
+
};
|
|
191
|
+
return {
|
|
192
|
+
contractName: selectedBaseName,
|
|
193
|
+
compilerOutputDir: normalizedOutputDir,
|
|
194
|
+
scriptPath,
|
|
195
|
+
abiPath,
|
|
196
|
+
debugPath: optionalFile(".debug"),
|
|
197
|
+
asmPath: optionalFile(".asm"),
|
|
198
|
+
scriptHexPath: optionalFile(".pvm.hex"),
|
|
199
|
+
abiHexPath: optionalFile(".abi.hex"),
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
//# sourceMappingURL=compiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler.js","sourceRoot":"","sources":["../../src/contract/compiler.ts"],"names":[],"mappings":";;;;;;AAyDA,kCAg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,CAAC;IACJ,CAAC;IAED,MAAM,UAAU,GAAG,mBAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE,GAAG,gBAAgB,MAAM,CAAC,CAAC;IAC7E,MAAM,OAAO,GAAG,mBAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE,GAAG,gBAAgB,MAAM,CAAC,CAAC;IAC1E,IAAI,CAAC,iBAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,yCAAyC,gBAAgB,MAAM,OAAO,EAAE,CAAC,CAAC;IAC5F,CAAC;IAED,MAAM,YAAY,GAAG,CAAC,MAAc,EAAsB,EAAE;QAC1D,MAAM,SAAS,GAAG,mBAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE,GAAG,gBAAgB,GAAG,MAAM,EAAE,CAAC,CAAC;QACjF,OAAO,iBAAE,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;IAC1D,CAAC,CAAC;IAEF,OAAO;QACL,YAAY,EAAE,gBAAgB;QAC9B,iBAAiB,EAAE,mBAAmB;QACtC,UAAU;QACV,OAAO;QACP,SAAS,EAAE,YAAY,CAAC,QAAQ,CAAC;QACjC,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC;QAC7B,aAAa,EAAE,YAAY,CAAC,UAAU,CAAC;QACvC,UAAU,EAAE,YAAY,CAAC,UAAU,CAAC;KACrC,CAAC;AACJ,CAAC","sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { spawn } from \"node:child_process\";\n\nexport const CONTRACT_COMPILER_NAME = \"pha-tomb\";\nexport const MIN_SUPPORTED_PHA_TOMB_VERSION = \"2.0.0\";\n\nexport type NativeCheckMode = \"off\" | \"warn\" | \"error\";\n\nexport interface InstalledCompiler {\n executableName: string;\n executablePath: string;\n version: string;\n}\n\nexport interface CompileProcessResult {\n command: string;\n args: string[];\n cwd: string;\n stdout: string;\n stderr: string;\n exitCode: number;\n}\n\nexport interface CompileArgsOptions {\n sourcePath: string;\n outputRoot: string;\n libPaths?: string[];\n protocol?: number;\n debug?: boolean;\n nativeCheck?: NativeCheckMode;\n}\n\nexport interface CompiledContractArtifacts {\n contractName: string;\n compilerOutputDir: string;\n scriptPath: string;\n abiPath: string;\n debugPath?: string;\n asmPath?: string;\n scriptHexPath?: string;\n abiHexPath?: string;\n}\n\nfunction parseSemver(version: string): [number, number, number] {\n const match = version.trim().match(/^(\\d+)\\.(\\d+)\\.(\\d+)/);\n if (!match) {\n throw new Error(`Unsupported semantic version: ${version}`);\n }\n\n return [\n Number(match[1]),\n Number(match[2]),\n Number(match[3]),\n ];\n}\n\nexport function isSemverGte(actual: string, minimum: string): boolean {\n const actualParts = parseSemver(actual);\n const minimumParts = parseSemver(minimum);\n\n for (let i = 0; i < actualParts.length; i += 1) {\n const a = actualParts[i] ?? 0;\n const b = minimumParts[i] ?? 0;\n if (a > b) {\n return true;\n }\n if (a < b) {\n return false;\n }\n }\n\n return true;\n}\n\nexport function findExecutableInPath(\n executableName: string,\n envPath: string = process.env.PATH ?? \"\",\n platform: NodeJS.Platform = process.platform,\n): string | null {\n const pathEntries = envPath.split(path.delimiter).filter(Boolean);\n const candidateNames =\n platform === \"win32\"\n ? [executableName, `${executableName}.exe`, `${executableName}.cmd`, `${executableName}.bat`]\n : [executableName];\n\n for (const entry of pathEntries) {\n for (const candidateName of candidateNames) {\n const candidatePath = path.join(entry, candidateName);\n try {\n fs.accessSync(candidatePath, fs.constants.X_OK);\n return candidatePath;\n } catch {\n continue;\n }\n }\n }\n\n return null;\n}\n\nasync function runCommandCapture(\n command: string,\n args: string[],\n cwd: string,\n): Promise<CompileProcessResult> {\n return await new Promise<CompileProcessResult>((resolve, reject) => {\n const child = spawn(command, args, {\n cwd,\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n });\n\n let stdout = \"\";\n let stderr = \"\";\n\n child.stdout.setEncoding(\"utf8\");\n child.stderr.setEncoding(\"utf8\");\n child.stdout.on(\"data\", (chunk: string) => {\n stdout += chunk;\n });\n child.stderr.on(\"data\", (chunk: string) => {\n stderr += chunk;\n });\n child.on(\"error\", reject);\n child.on(\"close\", (code) => {\n resolve({\n command,\n args,\n cwd,\n stdout,\n stderr,\n exitCode: code ?? -1,\n });\n });\n });\n}\n\nexport async function queryCompilerVersion(executablePath: string): Promise<string> {\n const result = await runCommandCapture(executablePath, [\"--version\"], process.cwd());\n if (result.exitCode !== 0) {\n throw new Error(\n `${CONTRACT_COMPILER_NAME} --version exited with code ${result.exitCode}: ${result.stderr.trim() || result.stdout.trim() || \"no diagnostics\"}`,\n );\n }\n\n const versionLine = result.stdout\n .split(/\\r?\\n/)\n .map((line) => line.trim())\n .find((line) => line.length > 0);\n\n if (!versionLine) {\n throw new Error(`${CONTRACT_COMPILER_NAME} --version returned no output`);\n }\n\n return versionLine;\n}\n\nexport async function findInstalledCompiler(\n envPath: string = process.env.PATH ?? \"\",\n): Promise<InstalledCompiler | null> {\n const executablePath = findExecutableInPath(CONTRACT_COMPILER_NAME, envPath);\n if (!executablePath) {\n return null;\n }\n\n return {\n executableName: CONTRACT_COMPILER_NAME,\n executablePath,\n version: await queryCompilerVersion(executablePath),\n };\n}\n\nexport async function resolveSupportedCompiler(\n minimumVersion: string = MIN_SUPPORTED_PHA_TOMB_VERSION,\n envPath: string = process.env.PATH ?? \"\",\n): Promise<InstalledCompiler> {\n const compiler = await findInstalledCompiler(envPath);\n if (!compiler) {\n throw new Error(`${CONTRACT_COMPILER_NAME} was not found in PATH`);\n }\n\n if (!isSemverGte(compiler.version, minimumVersion)) {\n throw new Error(\n `${CONTRACT_COMPILER_NAME} ${compiler.version} is below the minimum supported version ${minimumVersion}`,\n );\n }\n\n return compiler;\n}\n\nexport function buildCompileArgs(options: CompileArgsOptions): string[] {\n const args: string[] = [\n `output:${path.resolve(options.outputRoot)}`,\n ];\n\n if (options.protocol !== undefined) {\n args.push(`protocol:${options.protocol}`);\n }\n for (const libPath of options.libPaths ?? []) {\n args.push(`libpath:${path.resolve(libPath)}`);\n }\n if (options.debug) {\n args.push(\"debug\");\n }\n if (options.nativeCheck) {\n args.push(`nativecheck:${options.nativeCheck}`);\n }\n\n args.push(path.resolve(options.sourcePath));\n return args;\n}\n\nexport async function runCompiler(\n executablePath: string,\n args: string[],\n cwd: string,\n): Promise<CompileProcessResult> {\n return await runCommandCapture(executablePath, args, cwd);\n}\n\nexport function selectCompiledContractArtifacts(\n compilerOutputDir: string,\n requestedContractName?: string,\n): CompiledContractArtifacts {\n const normalizedOutputDir = path.resolve(compilerOutputDir);\n if (!fs.existsSync(normalizedOutputDir)) {\n throw new Error(`Compiler output directory does not exist: ${normalizedOutputDir}`);\n }\n\n const entries = fs.readdirSync(normalizedOutputDir, { withFileTypes: true });\n const pvmFiles = entries\n .filter((entry) => entry.isFile() && entry.name.endsWith(\".pvm\"))\n .map((entry) => entry.name)\n .sort();\n\n if (pvmFiles.length === 0) {\n throw new Error(`No .pvm artifacts were produced in ${normalizedOutputDir}`);\n }\n\n const requestedName = requestedContractName?.trim();\n let selectedBaseName: string | null = null;\n if (requestedName) {\n const requestedFile = `${requestedName}.pvm`;\n if (pvmFiles.includes(requestedFile)) {\n selectedBaseName = requestedName;\n }\n }\n\n if (!selectedBaseName && pvmFiles.length === 1) {\n selectedBaseName = path.basename(pvmFiles[0], \".pvm\");\n }\n\n if (!selectedBaseName) {\n const candidates = pvmFiles.map((file) => path.basename(file, \".pvm\")).join(\", \");\n if (requestedName) {\n throw new Error(\n `Requested contract '${requestedName}' was not found in compiler output. Available artifacts: ${candidates}`,\n );\n }\n throw new Error(\n `Compiler produced multiple .pvm artifacts. Use --contract-name to select one of: ${candidates}`,\n );\n }\n\n const scriptPath = path.join(normalizedOutputDir, `${selectedBaseName}.pvm`);\n const abiPath = path.join(normalizedOutputDir, `${selectedBaseName}.abi`);\n if (!fs.existsSync(abiPath)) {\n throw new Error(`ABI artifact is missing for contract '${selectedBaseName}': ${abiPath}`);\n }\n\n const optionalFile = (suffix: string): string | undefined => {\n const candidate = path.join(normalizedOutputDir, `${selectedBaseName}${suffix}`);\n return fs.existsSync(candidate) ? candidate : undefined;\n };\n\n return {\n contractName: selectedBaseName,\n compilerOutputDir: normalizedOutputDir,\n scriptPath,\n abiPath,\n debugPath: optionalFile(\".debug\"),\n asmPath: optionalFile(\".asm\"),\n scriptHexPath: optionalFile(\".pvm.hex\"),\n abiHexPath: optionalFile(\".abi.hex\"),\n };\n}\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ContractArtifactBundle } from "phantasma-sdk-ts";
|
|
2
|
+
export type ContractOperation = "deploy" | "upgrade";
|
|
3
|
+
export interface PreparedContractTransaction {
|
|
4
|
+
operation: ContractOperation;
|
|
5
|
+
contractName: string;
|
|
6
|
+
fromAddress: string;
|
|
7
|
+
scriptHex: string;
|
|
8
|
+
txHex: string;
|
|
9
|
+
scriptBytes: number;
|
|
10
|
+
abiBytes: number;
|
|
11
|
+
}
|
|
12
|
+
export interface ExecuteContractTransactionOptions {
|
|
13
|
+
operation: ContractOperation;
|
|
14
|
+
rpc: string;
|
|
15
|
+
nexus: string;
|
|
16
|
+
chain?: string;
|
|
17
|
+
wif: string;
|
|
18
|
+
bundle: ContractArtifactBundle;
|
|
19
|
+
gasPrice?: number;
|
|
20
|
+
gasLimit?: number;
|
|
21
|
+
proofOfWork?: number;
|
|
22
|
+
payloadHex?: string;
|
|
23
|
+
dryRun?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface ExecuteContractTransactionResult {
|
|
26
|
+
prepared: PreparedContractTransaction;
|
|
27
|
+
dryRun: boolean;
|
|
28
|
+
txHash?: string;
|
|
29
|
+
success?: boolean;
|
|
30
|
+
result?: string;
|
|
31
|
+
}
|
|
32
|
+
export declare function prepareContractTransaction(options: ExecuteContractTransactionOptions): PreparedContractTransaction;
|
|
33
|
+
export declare function executeContractTransaction(options: ExecuteContractTransactionOptions): Promise<ExecuteContractTransactionResult>;
|
|
34
|
+
//# sourceMappingURL=deploy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/contract/deploy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EAIvB,MAAM,kBAAkB,CAAC;AAG1B,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,SAAS,CAAC;AAErD,MAAM,WAAW,2BAA2B;IAC1C,SAAS,EAAE,iBAAiB,CAAC;IAC7B,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,iCAAiC;IAChD,SAAS,EAAE,iBAAiB,CAAC;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,sBAAsB,CAAC;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,gCAAgC;IAC/C,QAAQ,EAAE,2BAA2B,CAAC;IACtC,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,iCAAiC,GACzC,2BAA2B,CAyD7B;AAED,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE,iCAAiC,GACzC,OAAO,CAAC,gCAAgC,CAAC,CAoB3C"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepareContractTransaction = prepareContractTransaction;
|
|
4
|
+
exports.executeContractTransaction = executeContractTransaction;
|
|
5
|
+
const phantasma_sdk_ts_1 = require("phantasma-sdk-ts");
|
|
6
|
+
const waitForTx_1 = require("../actions/waitForTx");
|
|
7
|
+
function prepareContractTransaction(options) {
|
|
8
|
+
const keys = phantasma_sdk_ts_1.PhantasmaKeys.fromWIF(options.wif);
|
|
9
|
+
const fromAddress = keys.Address.Text;
|
|
10
|
+
const scriptHex = options.operation === "deploy"
|
|
11
|
+
? phantasma_sdk_ts_1.ContractTxHelper.buildDeployScriptFromBundle(options.bundle, fromAddress, options.gasPrice, options.gasLimit)
|
|
12
|
+
: phantasma_sdk_ts_1.ContractTxHelper.buildUpgradeScriptFromBundle(options.bundle, fromAddress, options.gasPrice, options.gasLimit);
|
|
13
|
+
const txHex = options.operation === "deploy"
|
|
14
|
+
? phantasma_sdk_ts_1.ContractTxHelper.buildDeployTransactionAndEncode({
|
|
15
|
+
nexus: options.nexus,
|
|
16
|
+
chain: options.chain,
|
|
17
|
+
signer: keys,
|
|
18
|
+
from: fromAddress,
|
|
19
|
+
contractName: options.bundle.contractName,
|
|
20
|
+
script: options.bundle.script,
|
|
21
|
+
abi: options.bundle.abi,
|
|
22
|
+
gasPrice: options.gasPrice,
|
|
23
|
+
gasLimit: options.gasLimit,
|
|
24
|
+
proofOfWork: options.proofOfWork,
|
|
25
|
+
payloadHex: options.payloadHex,
|
|
26
|
+
})
|
|
27
|
+
: phantasma_sdk_ts_1.ContractTxHelper.buildUpgradeTransactionAndEncode({
|
|
28
|
+
nexus: options.nexus,
|
|
29
|
+
chain: options.chain,
|
|
30
|
+
signer: keys,
|
|
31
|
+
from: fromAddress,
|
|
32
|
+
contractName: options.bundle.contractName,
|
|
33
|
+
script: options.bundle.script,
|
|
34
|
+
abi: options.bundle.abi,
|
|
35
|
+
gasPrice: options.gasPrice,
|
|
36
|
+
gasLimit: options.gasLimit,
|
|
37
|
+
proofOfWork: options.proofOfWork,
|
|
38
|
+
payloadHex: options.payloadHex,
|
|
39
|
+
});
|
|
40
|
+
return {
|
|
41
|
+
operation: options.operation,
|
|
42
|
+
contractName: options.bundle.contractName,
|
|
43
|
+
fromAddress,
|
|
44
|
+
scriptHex,
|
|
45
|
+
txHex,
|
|
46
|
+
scriptBytes: options.bundle.script.length,
|
|
47
|
+
abiBytes: options.bundle.abi.length,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
async function executeContractTransaction(options) {
|
|
51
|
+
const prepared = prepareContractTransaction(options);
|
|
52
|
+
if (options.dryRun) {
|
|
53
|
+
return {
|
|
54
|
+
prepared,
|
|
55
|
+
dryRun: true,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const rpc = new phantasma_sdk_ts_1.PhantasmaAPI(options.rpc, null, options.nexus);
|
|
59
|
+
const txHash = await rpc.sendRawTransaction(prepared.txHex);
|
|
60
|
+
const waitResult = await (0, waitForTx_1.waitForTx)(rpc, txHash);
|
|
61
|
+
return {
|
|
62
|
+
prepared,
|
|
63
|
+
dryRun: false,
|
|
64
|
+
txHash,
|
|
65
|
+
success: waitResult.success,
|
|
66
|
+
result: waitResult.result,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=deploy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deploy.js","sourceRoot":"","sources":["../../src/contract/deploy.ts"],"names":[],"mappings":";;AA0CA,gEA2DC;AAED,gEAsBC;AA7HD,uDAK0B;AAC1B,oDAAiD;AAoCjD,SAAgB,0BAA0B,CACxC,OAA0C;IAE1C,MAAM,IAAI,GAAG,gCAAa,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IA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vB,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,UAAU,EAAE,OAAO,CAAC,UAAU;SAC/B,CAAC,CAAC;IAET,OAAO;QACL,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,YAAY,EAAE,OAAO,CAAC,MAAM,CAAC,YAAY;QACzC,WAAW;QACX,SAAS;QACT,KAAK;QACL,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM;QACzC,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM;KACpC,CAAC;AACJ,CAAC;AAEM,KAAK,UAAU,0BAA0B,CAC9C,OAA0C;IAE1C,MAAM,QAAQ,GAAG,0BAA0B,CAAC,OAAO,CAAC,CAAC;IACrD,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QACnB,OAAO;YACL,QAAQ;YACR,MAAM,EAAE,IAAI;SACb,CAAC;IACJ,CAAC;IAED,MAAM,GAAG,GAAG,IAAI,+BAAY,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IAC/D,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,kBAAkB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC5D,MAAM,UAAU,GAAG,MAAM,IAAA,qBAAS,EAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAEhD,OAAO;QACL,QAAQ;QACR,MAAM,EAAE,KAAK;QACb,MAAM;QACN,OAAO,EAAE,UAAU,CAAC,OAAO;QAC3B,MAAM,EAAE,UAAU,CAAC,MAAM;KAC1B,CAAC;AACJ,CAAC","sourcesContent":["import {\n ContractArtifactBundle,\n ContractTxHelper,\n PhantasmaAPI,\n PhantasmaKeys,\n} from \"phantasma-sdk-ts\";\nimport { waitForTx } from \"../actions/waitForTx\";\n\nexport type ContractOperation = \"deploy\" | \"upgrade\";\n\nexport interface PreparedContractTransaction {\n operation: ContractOperation;\n contractName: string;\n fromAddress: string;\n scriptHex: string;\n txHex: string;\n scriptBytes: number;\n abiBytes: number;\n}\n\nexport interface ExecuteContractTransactionOptions {\n operation: ContractOperation;\n rpc: string;\n nexus: string;\n chain?: string;\n wif: string;\n bundle: ContractArtifactBundle;\n gasPrice?: number;\n gasLimit?: number;\n proofOfWork?: number;\n payloadHex?: string;\n dryRun?: boolean;\n}\n\nexport interface ExecuteContractTransactionResult {\n prepared: PreparedContractTransaction;\n dryRun: boolean;\n txHash?: string;\n success?: boolean;\n result?: string;\n}\n\nexport function prepareContractTransaction(\n options: ExecuteContractTransactionOptions,\n): PreparedContractTransaction {\n const keys = PhantasmaKeys.fromWIF(options.wif);\n const fromAddress = keys.Address.Text;\n\n const scriptHex =\n options.operation === \"deploy\"\n ? ContractTxHelper.buildDeployScriptFromBundle(\n options.bundle,\n fromAddress,\n options.gasPrice,\n options.gasLimit,\n )\n : ContractTxHelper.buildUpgradeScriptFromBundle(\n options.bundle,\n fromAddress,\n options.gasPrice,\n options.gasLimit,\n );\n\n const txHex =\n options.operation === \"deploy\"\n ? ContractTxHelper.buildDeployTransactionAndEncode({\n nexus: options.nexus,\n chain: options.chain,\n signer: keys,\n from: fromAddress,\n contractName: options.bundle.contractName,\n script: options.bundle.script,\n abi: options.bundle.abi,\n gasPrice: options.gasPrice,\n gasLimit: options.gasLimit,\n proofOfWork: options.proofOfWork,\n payloadHex: options.payloadHex,\n })\n : ContractTxHelper.buildUpgradeTransactionAndEncode({\n nexus: options.nexus,\n chain: options.chain,\n signer: keys,\n from: fromAddress,\n contractName: options.bundle.contractName,\n script: options.bundle.script,\n abi: options.bundle.abi,\n gasPrice: options.gasPrice,\n gasLimit: options.gasLimit,\n proofOfWork: options.proofOfWork,\n payloadHex: options.payloadHex,\n });\n\n return {\n operation: options.operation,\n contractName: options.bundle.contractName,\n fromAddress,\n scriptHex,\n txHex,\n scriptBytes: options.bundle.script.length,\n abiBytes: options.bundle.abi.length,\n };\n}\n\nexport async function executeContractTransaction(\n options: ExecuteContractTransactionOptions,\n): Promise<ExecuteContractTransactionResult> {\n const prepared = prepareContractTransaction(options);\n if (options.dryRun) {\n return {\n prepared,\n dryRun: true,\n };\n }\n\n const rpc = new PhantasmaAPI(options.rpc, null, options.nexus);\n const txHash = await rpc.sendRawTransaction(prepared.txHex);\n const waitResult = await waitForTx(rpc, txHash);\n\n return {\n prepared,\n dryRun: false,\n txHash,\n success: waitResult.success,\n result: waitResult.result,\n };\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface VersionReport {
|
|
2
|
+
phaDeployVersion: string;
|
|
3
|
+
tombVersion: string;
|
|
4
|
+
tombPath: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function readRequiredPackageVersion(packageJsonPath?: string): string;
|
|
7
|
+
export declare function buildVersionReport(envPath?: string, packageJsonPath?: string): Promise<VersionReport>;
|
|
8
|
+
export declare function renderVersionReport(report: VersionReport): string;
|
|
9
|
+
//# sourceMappingURL=version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,aAAa;IAC5B,gBAAgB,EAAE,MAAM,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,0BAA0B,CACxC,eAAe,GAAE,MAAsD,GACtE,MAAM,CASR;AAED,wBAAsB,kBAAkB,CACtC,OAAO,GAAE,MAA+B,EACxC,eAAe,CAAC,EAAE,MAAM,GACvB,OAAO,CAAC,aAAa,CAAC,CAwBxB;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAMjE"}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.readRequiredPackageVersion = readRequiredPackageVersion;
|
|
7
|
+
exports.buildVersionReport = buildVersionReport;
|
|
8
|
+
exports.renderVersionReport = renderVersionReport;
|
|
9
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
10
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
+
const compiler_1 = require("./contract/compiler");
|
|
12
|
+
function readRequiredPackageVersion(packageJsonPath = node_path_1.default.resolve(__dirname, "..", "package.json")) {
|
|
13
|
+
const packageJson = JSON.parse(node_fs_1.default.readFileSync(packageJsonPath, "utf8"));
|
|
14
|
+
const version = packageJson.version?.trim();
|
|
15
|
+
if (!version) {
|
|
16
|
+
throw new Error(`Missing package version in ${packageJsonPath}`);
|
|
17
|
+
}
|
|
18
|
+
return version;
|
|
19
|
+
}
|
|
20
|
+
async function buildVersionReport(envPath = process.env.PATH ?? "", packageJsonPath) {
|
|
21
|
+
const phaDeployVersion = readRequiredPackageVersion(packageJsonPath);
|
|
22
|
+
const tombPath = (0, compiler_1.findExecutableInPath)(compiler_1.CONTRACT_COMPILER_NAME, envPath);
|
|
23
|
+
if (!tombPath) {
|
|
24
|
+
return {
|
|
25
|
+
phaDeployVersion,
|
|
26
|
+
tombVersion: "not found",
|
|
27
|
+
tombPath: "not found",
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
return {
|
|
32
|
+
phaDeployVersion,
|
|
33
|
+
tombVersion: await (0, compiler_1.queryCompilerVersion)(tombPath),
|
|
34
|
+
tombPath,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
return {
|
|
39
|
+
phaDeployVersion,
|
|
40
|
+
tombVersion: `unavailable (${error instanceof Error ? error.message : String(error)})`,
|
|
41
|
+
tombPath,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function renderVersionReport(report) {
|
|
46
|
+
return [
|
|
47
|
+
`pha-deploy ${report.phaDeployVersion}`,
|
|
48
|
+
`pha-tomb version ${report.tombVersion}`,
|
|
49
|
+
`pha-tomb path ${report.tombPath}`,
|
|
50
|
+
].join("\n");
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;;;;AAcA,gEAWC;AAED,gDA2BC;AAED,kDAMC;AA9DD,sDAAyB;AACzB,0DAA6B;AAC7B,kDAI6B;AAQ7B,SAAgB,0BAA0B,CACxC,kBAA0B,mBAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,cAAc,CAAC;IAEvE,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,iBAAE,CAAC,YAAY,CAAC,eAAe,EAAE,MAAM,CAAC,CAEtE,CAAC;IACF,MAAM,OAAO,GAAG,WAAW,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC;IAC5C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,8BAA8B,eAAe,EAAE,CAAC,CAAC;IACnE,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAEM,KAAK,UAAU,kBAAkB,CACtC,UAAkB,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,EACxC,eAAwB;IAExB,MAAM,gBAAgB,GAAG,0BAA0B,CAAC,eAAe,CAAC,CAAC;IACrE,MAAM,QAAQ,GAAG,IAAA,+BAAoB,EAAC,iCAAsB,EAAE,OAAO,CAAC,CAAC;IACvE,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO;YACL,gBAAgB;YAChB,WAAW,EAAE,WAAW;YACxB,QAAQ,EAAE,WAAW;SACtB,CAAC;IACJ,CAAC;IAED,IAAI,CAAC;QACH,OAAO;YACL,gBAAgB;YAChB,WAAW,EAAE,MAAM,IAAA,+BAAoB,EAAC,QAAQ,CAAC;YACjD,QAAQ;SACT,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO;YACL,gBAAgB;YAChB,WAAW,EAAE,gBAAgB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG;YACtF,QAAQ;SACT,CAAC;IACJ,CAAC;AACH,CAAC;AAED,SAAgB,mBAAmB,CAAC,MAAqB;IACvD,OAAO;QACL,cAAc,MAAM,CAAC,gBAAgB,EAAE;QACvC,oBAAoB,MAAM,CAAC,WAAW,EAAE;QACxC,iBAAiB,MAAM,CAAC,QAAQ,EAAE;KACnC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC","sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport {\n CONTRACT_COMPILER_NAME,\n findExecutableInPath,\n queryCompilerVersion,\n} from \"./contract/compiler\";\n\nexport interface VersionReport {\n phaDeployVersion: string;\n tombVersion: string;\n tombPath: string;\n}\n\nexport function readRequiredPackageVersion(\n packageJsonPath: string = path.resolve(__dirname, \"..\", \"package.json\"),\n): string {\n const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, \"utf8\")) as {\n version?: string;\n };\n const version = packageJson.version?.trim();\n if (!version) {\n throw new Error(`Missing package version in ${packageJsonPath}`);\n }\n return version;\n}\n\nexport async function buildVersionReport(\n envPath: string = process.env.PATH ?? \"\",\n packageJsonPath?: string,\n): Promise<VersionReport> {\n const phaDeployVersion = readRequiredPackageVersion(packageJsonPath);\n const tombPath = findExecutableInPath(CONTRACT_COMPILER_NAME, envPath);\n if (!tombPath) {\n return {\n phaDeployVersion,\n tombVersion: \"not found\",\n tombPath: \"not found\",\n };\n }\n\n try {\n return {\n phaDeployVersion,\n tombVersion: await queryCompilerVersion(tombPath),\n tombPath,\n };\n } catch (error) {\n return {\n phaDeployVersion,\n tombVersion: `unavailable (${error instanceof Error ? error.message : String(error)})`,\n tombPath,\n };\n }\n}\n\nexport function renderVersionReport(report: VersionReport): string {\n return [\n `pha-deploy ${report.phaDeployVersion}`,\n `pha-tomb version ${report.tombVersion}`,\n `pha-tomb path ${report.tombPath}`,\n ].join(\"\\n\");\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pha-deploy",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "CLI token
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "CLI for Phantasma token and contract lifecycle workflows",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"start": "node --enable-source-maps dist/cli.js",
|
|
29
29
|
"cli": "npm run build && node dist/cli.js",
|
|
30
30
|
"lint": "eslint \"src/**/*.{ts,js}\" --fix || true",
|
|
31
|
-
"test": "
|
|
31
|
+
"test": "node --test -r ts-node/register test/**/*.test.ts",
|
|
32
32
|
"prepare": "npm run build"
|
|
33
33
|
},
|
|
34
34
|
"keywords": [
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"license": "MIT",
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@iarna/toml": "*",
|
|
44
|
-
"phantasma-sdk-ts": "^0.2
|
|
44
|
+
"phantasma-sdk-ts": "^0.5.2",
|
|
45
45
|
"yargs": "*"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|