@hyperionbt/helios-cli
Advanced tools
Comparing version 0.15.2 to 0.15.3
@@ -1,2 +0,2 @@ | ||
import { writeFileSync } from "node:fs"; | ||
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; | ||
import { Writer, parseOption, assertNoMoreOptions } from "./common/utils.js"; | ||
@@ -14,13 +14,34 @@ import { Bundle } from "./common/Bundle.js"; | ||
const bundle = await Bundle.initHere(options); | ||
{ | ||
const w = new Writer(); | ||
bundle.writeDecls(w); | ||
writeFileSync("dist/index.d.ts", w.toString()); | ||
const config = existsSync("./helios.config.json") ? | ||
JSON.parse(readFileSync("./helios.config.json").toString()) : | ||
{ stages: { main: {} } }; | ||
for (let key in config.stages) { | ||
const include = new Set(config.stages[key].include ?? []); | ||
const exclude = new Set(config.stages[key].exclude ?? []); | ||
if (include.size > 0 && exclude.size > 0) { | ||
throw new Error(`can't defined both include and exclude (see config for stage ${name})`); | ||
} | ||
const isIncluded = (name) => { | ||
if (include.size > 0) { | ||
return include.has(name) && !exclude.has(name); | ||
} | ||
else { | ||
return !exclude.has(name); | ||
} | ||
}; | ||
if (!existsSync(`dist/${key}`)) { | ||
mkdirSync(`dist/${key}`); | ||
} | ||
{ | ||
const w = new Writer(); | ||
bundle.writeDecls(w, isIncluded); | ||
writeFileSync(`dist/${key}/index.d.ts`, w.toString()); | ||
} | ||
{ | ||
const w = new Writer(); | ||
bundle.writeDefs(w, isIncluded); | ||
writeFileSync(`dist/${key}/index.js`, w.toString()); | ||
} | ||
} | ||
{ | ||
const w = new Writer(); | ||
bundle.writeDefs(w); | ||
writeFileSync("dist/index.js", w.toString()); | ||
} | ||
} | ||
//# sourceMappingURL=bundle.js.map |
@@ -111,5 +111,2 @@ import process from "node:process"; | ||
}); | ||
validators.registerCodeMapFileIndices(codeMapFileIndices); | ||
endpoints.registerCodeMapFileIndices(codeMapFileIndices); | ||
modules.registerCodeMapFileIndices(codeMapFileIndices); | ||
return new Bundle(sources, validators, modules, endpoints, options); | ||
@@ -127,3 +124,3 @@ } | ||
*/ | ||
writeDecls(w) { | ||
writeDecls(w, isIncluded) { | ||
w.write(`import * as helios from "@hyperionbt/helios"; | ||
@@ -135,3 +132,7 @@ | ||
w.indent(); | ||
this.#endpoints.writeDecls(w); | ||
this.#endpoints.forEach(item => { | ||
if (isIncluded(item.name)) { | ||
item.writeDecl(w); | ||
} | ||
}); | ||
w.undent(); | ||
@@ -150,14 +151,16 @@ w.write("\n}"); | ||
} | ||
writeValidatorDefs(w) { | ||
writeValidatorDefs(w, isIncluded) { | ||
w.write(`\nconst validators = {`); | ||
w.indent(); | ||
this.#validators.forEach(v => { | ||
const uplcProgram = v.compile([], true, this.#options.dumpIR.findIndex(d => d == v.name) != -1); | ||
if (v.purpose == "spending") { | ||
console.log(`validator ${v.name}: ${uplcProgram.validatorHash.hex}`); | ||
if (isIncluded(v.name)) { | ||
const uplcProgram = v.compile([], true, this.#options.dumpIR.findIndex(d => d == v.name) != -1); | ||
if (v.purpose == "spending") { | ||
console.log(`validator ${v.name}: ${uplcProgram.validatorHash.hex}`); | ||
} | ||
else if (v.purpose == "minting") { | ||
console.log(`policy ${v.name}: ${uplcProgram.mintingPolicyHash.hex}`); | ||
} | ||
w.write(`\n${v.name}: {cborHex: "${bytesToHex(uplcProgram.toCbor())}", hash: "${bytesToHex(uplcProgram.hash())}", properties: ${JSON.stringify({ ...uplcProgram.properties, name: v.name })}},`); | ||
} | ||
else if (v.purpose == "minting") { | ||
console.log(`policy ${v.name}: ${uplcProgram.mintingPolicyHash.hex}`); | ||
} | ||
w.write(`\n${v.name}: {cborHex: "${bytesToHex(uplcProgram.toCbor())}", properties: ${JSON.stringify({ ...uplcProgram.properties, name: v.name })}},`); | ||
}); | ||
@@ -167,16 +170,22 @@ w.undent(); | ||
} | ||
genCodeMapFileIndices() { | ||
genCodeMapFileIndices(isIncluded) { | ||
const codeMapFileIndices = new Map(); | ||
this.#sources.forEach((src, i) => { | ||
codeMapFileIndices.set(src.name, i); | ||
let i = 0; | ||
this.#sources.forEach(src => { | ||
if (isIncluded(src.name) || this.#modules.has(src.name)) { | ||
codeMapFileIndices.set(src.name, i); | ||
i += 1; | ||
} | ||
}); | ||
return codeMapFileIndices; | ||
} | ||
writeUnsimplifiedValidatorDefs(w) { | ||
writeUnsimplifiedValidatorDefs(w, isIncluded) { | ||
w.write(`\nconst origValidators = {`); | ||
w.indent(); | ||
const codeMapFileIndices = this.genCodeMapFileIndices(); | ||
const codeMapFileIndices = this.genCodeMapFileIndices(isIncluded); | ||
this.#validators.forEach(v => { | ||
const uplcProgram = v.compile([], false, false); | ||
w.write(`\n${v.name}: {cborHex: "${bytesToHex(uplcProgram.toCborWithMapping(codeMapFileIndices))}", properties: ${JSON.stringify({ ...uplcProgram.properties, name: v.name })}},`); | ||
if (isIncluded(v.name)) { | ||
const uplcProgram = v.compile([], false, false); | ||
w.write(`\n${v.name}: {cborHex: "${bytesToHex(uplcProgram.toCborWithMapping(codeMapFileIndices))}", properties: ${JSON.stringify({ ...uplcProgram.properties, name: v.name })}},`); | ||
} | ||
}); | ||
@@ -186,7 +195,9 @@ w.undent(); | ||
} | ||
writeCodeMapSource(w) { | ||
writeCodeMapSource(w, isIncluded) { | ||
w.write(`\nconst rawSources = [`); | ||
w.indent(); | ||
this.#sources.forEach(s => { | ||
w.write(`\n{name: "${s.name}", lines: [${s.raw.split("\n").map(l => l.length.toString()).join(",")}]},`); | ||
if (isIncluded(s.name) || this.#modules.has(s.name)) { | ||
w.write(`\n{name: "${s.name}", lines: [${s.raw.split("\n").map(l => l.length.toString()).join(",")}]},`); | ||
} | ||
}); | ||
@@ -196,3 +207,3 @@ w.undent(); | ||
} | ||
writeContractDefs(w) { | ||
writeContractDefs(w, isIncluded) { | ||
w.write(`\nexport default class Contract {`); | ||
@@ -279,9 +290,11 @@ w.indent(); | ||
const uplcProgram = helios.UplcProgram.fromCbor(raw.cborHex, raw.properties).apply(args); | ||
if (raw.hash in cache) { | ||
return new helios.UplcByteArray(site, helios.hexToBytes(raw.hash)); | ||
} else { | ||
const uplcProgram = helios.UplcProgram.fromCbor(raw.cborHex, raw.properties).apply(args); | ||
const scriptHash = uplcProgram.hash(); | ||
cache[raw.hash] = uplcProgram; | ||
cache[helios.bytesToHex(scriptHash)] = uplcProgram; | ||
return new helios.UplcByteArray(site, scriptHash); | ||
return new helios.UplcByteArray(site, helios.hexToBytes(raw.hash)); | ||
} | ||
}, | ||
@@ -379,8 +392,10 @@ now: async (rte, args) => { | ||
const raw = validators[key]; | ||
validators_[raw.hash] = () => { | ||
const uplcProgram = helios.UplcProgram.fromCbor(raw.cborHex, raw.properties); | ||
const uplcProgram = helios.UplcProgram.fromCbor(raw.cborHex, raw.properties); | ||
const scriptHash = uplcProgram.hash(); | ||
validators_[helios.bytesToHex(scriptHash)] = uplcProgram; | ||
validators_[raw.hash] = uplcProgram; | ||
return uplcProgram; | ||
} | ||
} | ||
@@ -485,15 +500,19 @@ | ||
`); | ||
const codeMapFileIndices = this.genCodeMapFileIndices(); | ||
this.#endpoints.forEach(e => e.writeDef(w, codeMapFileIndices)); | ||
const codeMapFileIndices = this.genCodeMapFileIndices(isIncluded); | ||
this.#endpoints.forEach(e => { | ||
if (isIncluded(e.name)) { | ||
e.writeDef(w, codeMapFileIndices); | ||
} | ||
}); | ||
w.undent(); | ||
w.write("\n}"); | ||
} | ||
writeDefs(w) { | ||
writeDefs(w, isIncluded) { | ||
this.writePreamble(w); | ||
this.writeValidatorDefs(w); | ||
this.writeUnsimplifiedValidatorDefs(w); | ||
this.writeCodeMapSource(w); | ||
this.writeContractDefs(w); | ||
this.writeValidatorDefs(w, isIncluded); | ||
this.writeUnsimplifiedValidatorDefs(w, isIncluded); | ||
this.writeCodeMapSource(w, isIncluded); | ||
this.writeContractDefs(w, isIncluded); | ||
} | ||
} | ||
//# sourceMappingURL=Bundle.js.map |
@@ -22,9 +22,9 @@ export class Collection { | ||
} | ||
has(name) { | ||
return this.#collection.some(item => item.name == name); | ||
} | ||
registerModules(modules) { | ||
this.#collection.forEach(s => s.registerModules(modules.items)); | ||
} | ||
registerCodeMapFileIndices(codeMapFileIndices) { | ||
this.#collection.forEach(s => s.registerCodeMapFileIndices(codeMapFileIndices)); | ||
} | ||
} | ||
//# sourceMappingURL=Collection.js.map |
@@ -22,43 +22,4 @@ import { Script } from "./Script.js"; | ||
this.#modules = modules; | ||
// also in-place change of path import statements | ||
/*let statement = this.src.match(IMPORT_RE); | ||
while (statement) { | ||
const hlPath = statement[1] | ||
const hlPathInner = hlPath.slice(1, hlPath.length - 1) | ||
let depPath = join(dirname(this.path), hlPathInner) | ||
if (existsSync(depPath) && statSync(depPath).isDirectory()) { | ||
if (existsSync(join(depPath, "index.hl"))) { | ||
depPath = join(depPath, "index.hl") | ||
} else if (existsSync(join(depPath, "index.helios"))) { | ||
depPath = join(depPath, "index.helios") | ||
} | ||
} else if (!extname(depPath)) { | ||
if (existsSync(depPath + ".hl")) { | ||
depPath += ".hl" | ||
} else if (existsSync(depPath + ".helios")) { | ||
depPath += ".helios" | ||
} | ||
} | ||
const depModule = this.#modules.find(m => m.path == depPath) | ||
if (!depModule) { | ||
throw new Error(`dependency ${depPath} of ${this.name} not found`) | ||
} | ||
const depName = depModule.name | ||
if (statement.index == undefined) { | ||
throw new Error("unexpected") | ||
} | ||
// change the path by the name of the module | ||
this.src = this.src.slice(0, statement.index) + statement[0].slice(0, statement[0].length - statement[1].length) + depName + this.src.slice(statement.index + statement[0].length) | ||
statement = this.src.match(IMPORT_RE); | ||
}*/ | ||
} | ||
} | ||
//# sourceMappingURL=ModuleScript.js.map |
@@ -24,9 +24,3 @@ export class Script { | ||
} | ||
get codeMapFileIndices() { | ||
return this.#codeMapFileIndices; | ||
} | ||
registerCodeMapFileIndices(m) { | ||
this.#codeMapFileIndices = m; | ||
} | ||
} | ||
//# sourceMappingURL=Script.js.map |
@@ -11,3 +11,3 @@ #!/usr/bin/env node | ||
import inspectError from "./inspectError.js"; | ||
const VERSION = "0.15.2"; | ||
const VERSION = "0.15.3"; | ||
const USAGE = `Usage: | ||
@@ -14,0 +14,0 @@ helios [-h|--help] <command> <command-options> |
import * as fs from "fs"; | ||
import * as path from "path"; | ||
import { assert, assertDefined, assertNoMoreOptions } from "./common/utils.js"; | ||
import { ByteArrayData, ConstrData, IntData, ListData, MapData, Site, UplcDataValue } from "helios"; | ||
import { BitWriter, ByteArrayData, ConstrData, IntData, ListData, MapData, Site, UplcConst, UplcDataValue, UplcByteArray, UplcProgram, bytesToHex } from "helios"; | ||
function parseDagOptions(args) { | ||
@@ -9,2 +9,3 @@ assertNoMoreOptions(args); | ||
} | ||
let argCount = 0; | ||
function unstring(str) { | ||
@@ -410,3 +411,16 @@ let n = str.length; | ||
if (d) { | ||
return (new UplcDataValue(Site.dummy(), d)).toString(); | ||
const value = (new UplcDataValue(Site.dummy(), d)); | ||
const ct = new UplcConst(value); | ||
const bw = new BitWriter(); | ||
ct.toFlat(bw); | ||
UplcByteArray.writeBytes(bw, d.toCbor(), false); | ||
const by = bw.finalize(false); | ||
const pr = new UplcProgram(ct); | ||
const pb = pr.serializeBytes(); | ||
fs.writeFileSync(`./arg-${argCount}-as-program.flat`, new Uint8Array(pb)); | ||
fs.writeFileSync(`./arg-${argCount}.flat`, new Uint8Array(by)); | ||
fs.writeFileSync(`./arg-${argCount}-as-program.cborHex`, bytesToHex(pr.toCbor())); | ||
const s = `${argCount}=${value.toString()}`; | ||
argCount++; | ||
return s; | ||
} | ||
@@ -413,0 +427,0 @@ const w = this.eatWord(); |
{ | ||
"name": "@hyperionbt/helios-cli", | ||
"version": "0.15.2", | ||
"version": "0.15.3", | ||
"description": "CLI tool for compiling Cardano smart contracts written in Helios, and building Cardano transactions.", | ||
@@ -22,3 +22,3 @@ "main": "./dist/index.js", | ||
"dependencies": { | ||
"helios": "npm:@hyperionbt/helios@^0.15.2" | ||
"helios": "npm:@hyperionbt/helios@^0.15.3" | ||
}, | ||
@@ -25,0 +25,0 @@ "keywords": [], |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
112864
1713