@harmoniclabs/plu-ts-onchain
Version:
An embedded DSL for Cardano smart contracts creation coupled with a library for Cardano transactions, all in Typescript
120 lines (119 loc) • 4.61 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.IRRecursive = void 0;
var BasePlutsError_1 = require("../../utils/BasePlutsError.js");
var IRHash_1 = require("../IRHash.js");
var IRNodeKind_1 = require("../IRNodeKind.js");
var utils_1 = require("../utils/index.js");
var concatUint8Arr_1 = require("../utils/concatUint8Arr.js");
var equalIRTerm_1 = require("../utils/equalIRTerm.js");
var isIRParentTerm_1 = require("../utils/isIRParentTerm.js");
var IRRecursive = /** @class */ (function () {
function IRRecursive(body, func_name, _unsafeHash) {
if (!(0, utils_1.isIRTerm)(body))
throw new Error("IRRecursive body argument was not an IRTerm");
Object.defineProperties(this, {
arity: {
value: 1,
writable: false,
enumerable: true,
configurable: false
},
meta: {
value: {
name: typeof func_name === "string" ? func_name : (void 0)
},
writable: true,
enumerable: true,
configurable: false
}
});
this._body = body;
this._body.parent = this;
this._hash = (0, IRHash_1.isIRHash)(_unsafeHash) ? _unsafeHash : undefined;
this._parent = undefined;
}
Object.defineProperty(IRRecursive, "kind", {
get: function () { return IRNodeKind_1.IRNodeKind.Recursive; },
enumerable: false,
configurable: true
});
Object.defineProperty(IRRecursive.prototype, "kind", {
get: function () { return IRRecursive.kind; },
enumerable: false,
configurable: true
});
Object.defineProperty(IRRecursive, "tag", {
get: function () { return new Uint8Array([IRRecursive.kind]); },
enumerable: false,
configurable: true
});
Object.defineProperty(IRRecursive.prototype, "body", {
get: function () { return this._body; },
set: function (newBody) {
if (!(0, utils_1.isIRTerm)(newBody)) {
throw new BasePlutsError_1.BasePlutsError("invalid IRTerm to be a function body");
}
if (!(0, equalIRTerm_1.shallowEqualIRTermHash)(this._body, newBody))
this.markHashAsInvalid();
// keep the parent reference in the old child, useful for compilation
// _body.parent = undefined;
this._body = newBody;
this._body.parent = this;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IRRecursive.prototype, "hash", {
get: function () {
if (!(0, IRHash_1.isIRHash)(this._hash)) {
this._hash = (0, IRHash_1.hashIrData)((0, concatUint8Arr_1.concatUint8Arr)(IRRecursive.tag,
// positiveIntAsBytes( this.arity ),
this._body.hash));
}
return this._hash;
},
enumerable: false,
configurable: true
});
IRRecursive.prototype.isHashPresent = function () { return (0, IRHash_1.isIRHash)(this._hash); };
IRRecursive.prototype.markHashAsInvalid = function () {
var _a;
this._hash = undefined;
(_a = this.parent) === null || _a === void 0 ? void 0 : _a.markHashAsInvalid();
};
Object.defineProperty(IRRecursive.prototype, "name", {
get: function () { return this.meta.name; },
enumerable: false,
configurable: true
});
;
Object.defineProperty(IRRecursive.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
});
IRRecursive.prototype.clone = function () {
return new IRRecursive(this._body.clone(), this.meta.name, this.isHashPresent() ? this.hash : undefined);
};
IRRecursive.prototype.toJSON = function () { return this.toJson(); };
IRRecursive.prototype.toJson = function () {
return {
type: "IRRecursive",
arity: this.arity,
body: this._body.toJson()
};
};
return IRRecursive;
}());
exports.IRRecursive = IRRecursive;