@harmoniclabs/plu-ts-onchain
Version:
An embedded DSL for Cardano smart contracts creation coupled with a library for Cardano transactions, all in Typescript
28 lines (27 loc) • 995 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isClosedAtDbn = void 0;
var iterTree_1 = require("../../toUPLC/_internal/iterTree.js");
var IRSelfCall_1 = require("../IRSelfCall.js");
var IRVar_1 = require("../IRVar.js");
function isClosedAtDbn(term, dbn) {
if (dbn === void 0) { dbn = 0; }
var isClosed = true;
(0, iterTree_1.iterTree)(term, function (node, diff) {
var realDbn = dbn + diff;
if (node instanceof IRVar_1.IRVar ||
node instanceof IRSelfCall_1.IRSelfCall) {
// realDbn === 0 implies no variables are in scope
// so if node.dbn === 0 and realDbn === 0 then the variable is open
// and is pointing outside of the scope
isClosed = isClosed || node.dbn < realDbn;
}
},
// shouldSkipNode
undefined,
// shouldStop
function () { return !isClosed; } // exit early
);
return isClosed;
}
exports.isClosedAtDbn = isClosedAtDbn;