@harmoniclabs/plu-ts-onchain
Version:
An embedded DSL for Cardano smart contracts creation coupled with a library for Cardano transactions, all in Typescript
29 lines (28 loc) • 1.85 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.matchSingleCtorStruct = exports.getFields = void 0;
var IRApp_1 = require("../../../IR/IRNodes/IRApp.js");
var IRFunc_1 = require("../../../IR/IRNodes/IRFunc.js");
var IRHoisted_1 = require("../../../IR/IRNodes/IRHoisted.js");
var IRNative_1 = require("../../../IR/IRNodes/IRNative/index.js");
var IRVar_1 = require("../../../IR/IRNodes/IRVar.js");
var Term_1 = require("../../Term/index.js");
var data_1 = require("../../lib/builtins/data/index.js");
var noUnwrap_1 = require("../../lib/builtins/pair/noUnwrap.js");
var papp_1 = require("../../lib/papp.js");
var pfn_1 = require("../../lib/pfn.js");
var phoist_1 = require("../../lib/phoist.js");
var type_system_1 = require("../../type_system/index.js");
var hoisted_getFields = new IRHoisted_1.IRHoisted(new IRFunc_1.IRFunc(1, // struct
new IRApp_1.IRApp(IRNative_1.IRNative.sndPair, new IRApp_1.IRApp(IRNative_1.IRNative.unConstrData, new IRVar_1.IRVar(0)))));
hoisted_getFields.hash;
exports.getFields = new Term_1.Term((0, type_system_1.lam)(type_system_1.data, (0, type_system_1.list)(type_system_1.data)), function (_dbn) { return hoisted_getFields.clone(); });
exports.matchSingleCtorStruct = (function (returnT) { return (0, phoist_1.phoist)((0, pfn_1.pfn)([
type_system_1.data,
(0, type_system_1.lam)((0, type_system_1.list)(type_system_1.data), returnT)
], returnT)(function (structData, continuation) {
// it makes no sense to extract the ctor index for datatype defined as single ctors
// even from security point of view
// an attacker can always change the data to match the ctor index expected
return (0, papp_1.papp)(continuation, (0, noUnwrap_1.psndPairNoUnwrap)(type_system_1.int, (0, type_system_1.list)(type_system_1.data)).$(data_1.punConstrData.$(structData)));
})); });