@harmoniclabs/plu-ts-onchain
Version:
An embedded DSL for Cardano smart contracts creation coupled with a library for Cardano transactions, all in Typescript
87 lines (85 loc) • 8.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.pserialiseData = exports.pnilPairData = exports.pnilData = exports.peqData = exports.punBData = exports.punIData = exports.punListData = exports.punMapData = exports.punConstrData = exports.pBSToData = exports.pIntToData = exports.pListToData = exports.pMapToData = exports.pConstrToData = exports.pchooseData = exports.pstrictChooseData = void 0;
var obj_utils_1 = require("@harmoniclabs/obj-utils");
var Term_1 = require("../../../Term/index.js");
var type_system_1 = require("../../../type_system/index.js");
var papp_1 = require("../../papp.js");
var pdelay_1 = require("../../pdelay.js");
var minimal_1 = require("../../pforce/minimal.js");
var addApplications_1 = require("../addApplications.js");
var IRNative_1 = require("../../../../IR/IRNodes/IRNative/index.js");
var IRHoisted_1 = require("../../../../IR/IRNodes/IRHoisted.js");
var IRApp_1 = require("../../../../IR/IRNodes/IRApp.js");
var IRConst_1 = require("../../../../IR/IRNodes/IRConst.js");
/**
* in theory 'chooseData' has 5 type parameters (1 per data constructor)
* and this means any of those types can be returned
*
* plu-ts wont support that in favor of type determinism
*/
function pstrictChooseData(returnT) {
return (0, addApplications_1.addApplications)(new Term_1.Term((0, type_system_1.fn)([type_system_1.data, returnT, returnT, returnT, returnT, returnT], returnT), function (_dbn) { return IRNative_1.IRNative.chooseData; }));
}
exports.pstrictChooseData = pstrictChooseData;
/*
@todo implement a recursive utility function to
automatically add delays to all alrguments except the first;
add aliases for the applications except the first;
force the last application (once provided argument and delayed)
*/
function pchooseData(returnT) {
// new term identical to the strict one in order to define new (different) "$" properties
var _chooseData = new Term_1.Term((0, type_system_1.fn)([type_system_1.data, (0, type_system_1.delayed)(returnT), (0, type_system_1.delayed)(returnT), (0, type_system_1.delayed)(returnT), (0, type_system_1.delayed)(returnT), (0, type_system_1.delayed)(returnT)], (0, type_system_1.delayed)(returnT)), function (_dbn) { return IRNative_1.IRNative.chooseData; });
return (0, obj_utils_1.defineReadOnlyProperty)(_chooseData, "$", function (data) {
// @ts-ignore Type instantiation is excessively deep and possibly infinite.
var _cDWithData = (0, papp_1.papp)(_chooseData, data);
var _cDWithDataApp = (0, obj_utils_1.defineReadOnlyProperty)(_cDWithData, "$", function (caseConstr) {
var _cDDWithConstr = (0, papp_1.papp)(_cDWithData, (0, pdelay_1.pdelay)(caseConstr));
var _cDDWithConstrApp = (0, obj_utils_1.defineReadOnlyProperty)(_cDDWithConstr, "$", function (mapCase) {
var _cDDCWithMap = (0, papp_1.papp)(_cDDWithConstr, (0, pdelay_1.pdelay)(mapCase));
var _cDDCWithMapApp = (0, obj_utils_1.defineReadOnlyProperty)(_cDDCWithMap, "$", function (listCase) {
var _cDDCMWithList = (0, papp_1.papp)(_cDDCWithMap, (0, pdelay_1.pdelay)(listCase));
var _cDDCMWithListApp = (0, obj_utils_1.defineReadOnlyProperty)(_cDDCMWithList, "$", function (iCase) {
var _cDDCMLWithInt = (0, papp_1.papp)(_cDDCMWithList, (0, pdelay_1.pdelay)(iCase));
var _cDDCMLWithIntApp = (0, obj_utils_1.defineReadOnlyProperty)(_cDDCMLWithInt, "$", function (bCase) {
return (0, minimal_1.pforce_minimal)((0, papp_1.papp)(_cDDCMLWithInt, (0, pdelay_1.pdelay)(bCase)));
});
return (0, obj_utils_1.defineReadOnlyProperty)(_cDDCMLWithIntApp, "caseB", _cDDCMLWithIntApp.$);
});
return (0, obj_utils_1.defineReadOnlyProperty)(_cDDCMWithListApp, "caseI", _cDDCMWithListApp.$);
});
return (0, obj_utils_1.defineReadOnlyProperty)(_cDDCWithMapApp, "caseList", _cDDCWithMapApp.$);
});
return (0, obj_utils_1.defineReadOnlyProperty)(_cDDWithConstrApp, "caseMap", _cDDWithConstrApp.$);
});
return (0, obj_utils_1.defineReadOnlyProperty)(_cDWithDataApp, "caseConstr", _cDWithDataApp.$);
});
}
exports.pchooseData = pchooseData;
exports.pConstrToData = (0, addApplications_1.addApplications)(new Term_1.Term((0, type_system_1.fn)([type_system_1.int, (0, type_system_1.list)(type_system_1.data)], type_system_1.data), function (_dbn) { return IRNative_1.IRNative.constrData; }));
exports.pMapToData = (0, addApplications_1.addApplications)(new Term_1.Term((0, type_system_1.lam)((0, type_system_1.list)((0, type_system_1.pair)(type_system_1.data, type_system_1.data)), type_system_1.data), function (_dbn) { return IRNative_1.IRNative.mapData; }));
exports.pListToData = (0, addApplications_1.addApplications)(new Term_1.Term((0, type_system_1.lam)((0, type_system_1.list)(type_system_1.data), type_system_1.data), function (_dbn) { return IRNative_1.IRNative.listData; }));
exports.pIntToData = (0, addApplications_1.addApplications)(new Term_1.Term((0, type_system_1.lam)(type_system_1.int, (0, type_system_1.asData)(type_system_1.int)), function (_dbn) { return IRNative_1.IRNative.iData; }));
exports.pBSToData = (0, addApplications_1.addApplications)(new Term_1.Term((0, type_system_1.lam)(type_system_1.bs, (0, type_system_1.asData)(type_system_1.bs)), function (_dbn) { return IRNative_1.IRNative.bData; }));
exports.punConstrData = (0, addApplications_1.addApplications)(new Term_1.Term(
// MUST be `_pair` and NOT `pair` because elements aren't data
(0, type_system_1.lam)(type_system_1.data, (0, type_system_1._pair)(type_system_1.int, (0, type_system_1.list)(type_system_1.data))), function (_dbn) { return IRNative_1.IRNative.unConstrData; }));
exports.punMapData = (0, addApplications_1.addApplications)(new Term_1.Term((0, type_system_1.lam)(type_system_1.data, (0, type_system_1.list)((0, type_system_1.pair)(type_system_1.data, type_system_1.data))), function (_dbn) { return IRNative_1.IRNative.unMapData; }));
exports.punListData = (0, addApplications_1.addApplications)(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 IRNative_1.IRNative.unListData; }));
exports.punIData = (0, addApplications_1.addApplications)(new Term_1.Term((0, type_system_1.lam)(type_system_1.data, type_system_1.int), function (_dbn) { return IRNative_1.IRNative.unIData; })
//, addPIntMethods
);
exports.punBData = (function () {
var unBData = new Term_1.Term((0, type_system_1.lam)(type_system_1.data, type_system_1.bs), function (_dbn) { return IRNative_1.IRNative.unBData; });
return (0, obj_utils_1.defineReadOnlyProperty)(unBData, "$", function (dataBS) {
return (0, papp_1.papp)(unBData, dataBS);
});
})();
exports.peqData = (0, addApplications_1.addApplications)(new Term_1.Term((0, type_system_1.fn)([type_system_1.data, type_system_1.data], type_system_1.bool), function (_dbn) { return IRNative_1.IRNative.equalsData; }));
exports.pnilData = new Term_1.Term((0, type_system_1.list)(type_system_1.data), function (_dbn) { return new IRHoisted_1.IRHoisted(new IRApp_1.IRApp(IRNative_1.IRNative.mkNilData, IRConst_1.IRConst.unit)); });
exports.pnilPairData = new Term_1.Term((0, type_system_1.list)((0, type_system_1.pair)(type_system_1.data, type_system_1.data)), function (_dbn) { return new IRHoisted_1.IRHoisted(new IRApp_1.IRApp(IRNative_1.IRNative.mkNilPairData, IRConst_1.IRConst.unit)); });
// --------------------------------------------------------------------------------------------------------------------- //
// ----------------------------------------------- [ VASIL (Plutus V2) ] ----------------------------------------------- //
// --------------------------------------------------------------------------------------------------------------------- //
exports.pserialiseData = (0, addApplications_1.addApplications)(new Term_1.Term((0, type_system_1.lam)(type_system_1.data, type_system_1.bs), function (_dbn) { return IRNative_1.IRNative.serialiseData; }));