UNPKG

clvm

Version:

Javascript implementation of chia lisp

54 lines (53 loc) 1.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isCons = exports.isAtom = exports.CLVMObject = void 0; const __python_types__1 = require("./__python_types__"); const __type_compatibility__1 = require("./__type_compatibility__"); const EvalError_1 = require("./EvalError"); /* This class implements the CLVM Object protocol in the simplest possible way, by just having an "atom" and a "pair" field */ class CLVMObject { get atom() { return this._atom; } get pair() { return this._pair; } constructor(v) { this._atom = __python_types__1.None; this._pair = __python_types__1.None; if (v instanceof CLVMObject) { this._atom = v.atom; this._pair = v.pair; } else if (v && (typeof v === "object" || typeof v === "function") && "atom" in v && "pair" in v) { this._atom = v.atom; this._pair = v.pair; } else if ((0, __type_compatibility__1.isTuple)(v)) { this._pair = v; this._atom = __python_types__1.None; } else { this._atom = v; this._pair = __python_types__1.None; } } } exports.CLVMObject = CLVMObject; function isAtom(obj) { if ((obj.atom && obj.pair) || (!obj.atom && !obj.pair)) { throw new EvalError_1.EvalError("Invalid clvm", obj); } return Boolean(obj.atom && !obj.pair); } exports.isAtom = isAtom; function isCons(obj) { if ((obj.atom && obj.pair) || (!obj.atom && !obj.pair)) { throw new EvalError_1.EvalError("Invalid clvm", obj); } return Boolean((!obj.atom && obj.pair)); } exports.isCons = isCons;