clvm_tools
Version:
Javascript implementation of clvm_tools
83 lines (82 loc) • 3.44 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.initialize = exports.setPrintFunction = exports.go = void 0;
const cmds_1 = require("./clvm_tools/cmds");
__exportStar(require("./clvm_tools/binutils"), exports);
__exportStar(require("./clvm_tools/clvmc"), exports);
__exportStar(require("./clvm_tools/cmds"), exports);
__exportStar(require("./clvm_tools/curry"), exports);
__exportStar(require("./clvm_tools/debug"), exports);
__exportStar(require("./clvm_tools/NodePath"), exports);
__exportStar(require("./clvm_tools/pattern_match"), exports);
__exportStar(require("./clvm_tools/sha256tree"), exports);
const print_1 = require("./platform/print");
const clvm_1 = require("clvm");
const clvm_rs_1 = require("./platform/clvm_rs");
const COMMANDS = {
read_ir: cmds_1.read_ir,
opc: cmds_1.opc,
opd: cmds_1.opd,
run: cmds_1.run,
brun: cmds_1.brun,
};
/**
* Dispatch cli command.
* - `go("run", "(mod ARGUMENT (+ ARGUMENT 3))")`
* - `go("brun", "(+ 1 (q . 3))", "--time")`
*
* @param {...string[]} args
*/
function go(...args) {
if (!args || args.length < 1) {
const errMsg = "You need specify command";
// printError(`Error: ${errMsg}`);
throw new Error(errMsg);
}
const commandName = args[0];
const command = COMMANDS[commandName];
if (!command) {
const errMsg = `Unknown command: ${commandName}`;
// printError(`Error: ${errMsg}`);
throw new Error(errMsg);
}
return command(args);
}
exports.go = go;
/**
* Change print function. Default is `console.log`.
* If you want to print messages to file, variable or something, you need to change printer function by this function.
* @param {(...msg: string[]) => void} printer
*/
function setPrintFunction(printer) {
print_1.setStdout(printer);
}
exports.setPrintFunction = setPrintFunction;
/**
* Wait wasm files to be loaded before you call any of `clvm_tools` functions.
*/
function initialize(option) {
return __awaiter(this, void 0, void 0, function* () {
yield Promise.all([clvm_1.initialize(), clvm_rs_1.initialize(option === null || option === void 0 ? void 0 : option.initClvmRsOption)]);
});
}
exports.initialize = initialize;