UNPKG

@harmoniclabs/plu-ts-onchain

Version:

An embedded DSL for Cardano smart contracts creation coupled with a library for Cardano transactions, all in Typescript

96 lines (95 loc) 3.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.IRForced = void 0; var BasePlutsError_1 = require("../../utils/BasePlutsError.js"); var concatUint8Arr_1 = require("../utils/concatUint8Arr.js"); var isIRTerm_1 = require("../utils/isIRTerm.js"); var isIRParentTerm_1 = require("../utils/isIRParentTerm.js"); var IRHash_1 = require("../IRHash.js"); var equalIRTerm_1 = require("../utils/equalIRTerm.js"); var IRNodeKind_1 = require("../IRNodeKind.js"); var IRForced = /** @class */ (function () { function IRForced(forced, _unsafeHash) { this.meta = {}; this._hash = (0, IRHash_1.isIRHash)(_unsafeHash) ? _unsafeHash : undefined; if (!(0, isIRTerm_1.isIRTerm)(forced)) throw new Error("IRForced argument was not an IRTerm"); this._forced = forced; this._forced.parent = this; this._parent = undefined; } Object.defineProperty(IRForced.prototype, "forced", { get: function () { return this._forced; }, set: function (newForced) { if (!(0, isIRTerm_1.isIRTerm)(newForced)) { throw new BasePlutsError_1.BasePlutsError("invalid IRTerm to be forced"); } if (!(0, equalIRTerm_1.shallowEqualIRTermHash)(this._forced, newForced)) this.markHashAsInvalid(); // keep the parent reference in the old child, useful for compilation // _forced.parent = undefined; this._forced = newForced; this._forced.parent = this; }, enumerable: false, configurable: true }); Object.defineProperty(IRForced.prototype, "hash", { get: function () { if (!(0, IRHash_1.isIRHash)(this._hash)) { this._hash = (0, IRHash_1.hashIrData)((0, concatUint8Arr_1.concatUint8Arr)(IRForced.tag, this._forced.hash)); } return this._hash; }, enumerable: false, configurable: true }); IRForced.prototype.isHashPresent = function () { return (0, IRHash_1.isIRHash)(this._hash); }; IRForced.prototype.markHashAsInvalid = function () { var _a; this._hash = undefined; (_a = this.parent) === null || _a === void 0 ? void 0 : _a.markHashAsInvalid(); }; Object.defineProperty(IRForced.prototype, "parent", { get: function () { return this._parent; }, set: function (newParent) { if (!( // assert // new parent value is different than current this._parent !== newParent && ( // and the new parent value is valid newParent === undefined || (0, isIRParentTerm_1.isIRParentTerm)(newParent)))) return; this._parent = newParent; }, enumerable: false, configurable: true }); Object.defineProperty(IRForced, "kind", { get: function () { return IRNodeKind_1.IRNodeKind.Forced; }, enumerable: false, configurable: true }); Object.defineProperty(IRForced.prototype, "kind", { get: function () { return IRForced.kind; }, enumerable: false, configurable: true }); Object.defineProperty(IRForced, "tag", { get: function () { return new Uint8Array([IRForced.kind]); }, enumerable: false, configurable: true }); IRForced.prototype.clone = function () { return new IRForced(this.forced.clone(), this.isHashPresent() ? this.hash : undefined); }; IRForced.prototype.toJSON = function () { return this.toJson(); }; IRForced.prototype.toJson = function () { return { type: "IRForced", forced: this.forced.toJson() }; }; return IRForced; }()); exports.IRForced = IRForced;