@harmoniclabs/plu-ts-onchain
Version:
An embedded DSL for Cardano smart contracts creation coupled with a library for Cardano transactions, all in Typescript
147 lines (146 loc) • 5.92 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.IRConstr = void 0;
var ints_1 = require("../../utils/ints.js");
var concatUint8Arr_1 = require("../utils/concatUint8Arr.js");
var isIRParentTerm_1 = require("../utils/isIRParentTerm.js");
var positiveIntAsBytes_1 = require("../utils/positiveIntAsBytes.js");
var mapArrayLike_1 = require("./utils/mapArrayLike.js");
var utils_1 = require("../utils/index.js");
var makeArrayLikeProxy_1 = require("./utils/makeArrayLikeProxy.js");
var IRHash_1 = require("../IRHash.js");
var equalIRTerm_1 = require("../utils/equalIRTerm.js");
var IRNodeKind_1 = require("../IRNodeKind.js");
var IRConstr = /** @class */ (function () {
function IRConstr(index, fields, meta, _unsafeHash) {
if (meta === void 0) { meta = {}; }
var self = this;
this.meta = meta;
this._parent = undefined;
Object.defineProperty(this, "index", {
value: (0, ints_1.forceBigUInt)(index),
writable: false,
enumerable: true,
configurable: false
});
Object.defineProperty(this, "fields", {
value: (0, makeArrayLikeProxy_1.makeArrayLikeProxy)(fields, utils_1.isIRTerm,
// initModifyElem
function (newElem) {
// newElem = newElem.clone();
newElem.parent = self;
// self.markHashAsInvalid()
return newElem;
},
// modifyElem
// called before setting the new value
// the return value is the value that will be set
function (newElem, oldElem) {
if (!(0, equalIRTerm_1.shallowEqualIRTermHash)(oldElem, newElem))
self.markHashAsInvalid();
newElem.parent = self;
return newElem;
}),
writable: false,
enumerable: true,
configurable: false
});
this._hash = (0, IRHash_1.isIRHash)(_unsafeHash) ? _unsafeHash : undefined;
}
Object.defineProperty(IRConstr, "kind", {
get: function () { return IRNodeKind_1.IRNodeKind.Constr; },
enumerable: false,
configurable: true
});
Object.defineProperty(IRConstr.prototype, "kind", {
get: function () { return IRConstr.kind; },
enumerable: false,
configurable: true
});
Object.defineProperty(IRConstr, "tag", {
get: function () { return new Uint8Array([IRNodeKind_1.IRNodeKind.Constr]); },
enumerable: false,
configurable: true
});
Object.defineProperty(IRConstr.prototype, "hash", {
get: function () {
if (!(0, IRHash_1.isIRHash)(this._hash)) {
// basically a merkle tree
this._hash = (0, IRHash_1.hashIrData)(concatUint8Arr_1.concatUint8Arr.apply(void 0, __spreadArray([IRConstr.tag,
(0, positiveIntAsBytes_1.positiveIntAsBytes)(this.index)], __read((0, mapArrayLike_1.mapArrayLike)(this.fields, function (f) { return f.hash; })), false)));
}
return this._hash;
},
enumerable: false,
configurable: true
});
IRConstr.prototype.markHashAsInvalid = function () {
var _a;
this._hash = undefined;
(_a = this.parent) === null || _a === void 0 ? void 0 : _a.markHashAsInvalid();
};
IRConstr.prototype.isHashPresent = function () { return (0, IRHash_1.isIRHash)(this._hash); };
Object.defineProperty(IRConstr.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
});
IRConstr.prototype.clone = function () {
return new IRConstr(this.index, (0, mapArrayLike_1.mapArrayLike)(this.fields, function (f) { return f.clone(); }), __assign({}, this.meta), this.isHashPresent() ? this.hash : undefined);
};
IRConstr.prototype.toJSON = function () { return this.toJson(); };
IRConstr.prototype.toJson = function () {
return {
index: this.index.toString(),
fields: (0, mapArrayLike_1.mapArrayLike)(this.fields, function (f) { return f.toJson(); })
};
};
return IRConstr;
}());
exports.IRConstr = IRConstr;