@harmoniclabs/plu-ts-onchain
Version:
An embedded DSL for Cardano smart contracts creation coupled with a library for Cardano transactions, all in Typescript
59 lines (58 loc) • 3.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PValue = exports.PValueEntry = exports.PAssetsEntry = void 0;
var palias_1 = require("../../../../PTypes/PAlias/palias.js");
var bool_1 = require("../../../../lib/builtins/bool/index.js");
var pdelay_1 = require("../../../../lib/pdelay.js");
var pfn_1 = require("../../../../lib/pfn.js");
var phoist_1 = require("../../../../lib/phoist.js");
var pInt_1 = require("../../../../lib/std/int/pInt.js");
var minimal_1 = require("../../../../lib/std/list/precursiveList/minimal.js");
var types_1 = require("../../../../type_system/types.js");
var PCurrencySymbol_1 = require("../PCurrencySymbol.js");
var PTokenName_1 = require("../PTokenName.js");
var minimal_common_1 = require("../../../../lib/std/data/conversion/minimal_common.js");
var plam_1 = require("../../../../lib/plam.js");
exports.PAssetsEntry = (0, palias_1.palias)((0, types_1.pair)(PTokenName_1.PTokenName.type, types_1.int), function (self_t) {
return {
tokenName: (0, plam_1.plam)(self_t, PTokenName_1.PTokenName.type)(function (self) { return self.fst; }),
quantity: (0, plam_1.plam)(self_t, types_1.int)(function (self) { return self.snd; }),
};
});
exports.PValueEntry = (0, palias_1.palias)((0, types_1.pair)(PCurrencySymbol_1.PCurrencySymbol.type, (0, types_1.list)(exports.PAssetsEntry.type)), function (self_t) {
return {
policy: (0, plam_1.plam)(self_t, PCurrencySymbol_1.PCurrencySymbol.type)(function (self) { return self.fst; }),
assets: (0, plam_1.plam)(self_t, (0, types_1.list)(exports.PAssetsEntry.type))(function (self) { return self.snd; })
};
});
exports.PValue = (0, palias_1.palias)((0, types_1.list)(exports.PValueEntry.type), function (self_t) {
var pvalueOf = (0, phoist_1.phoist)((0, pfn_1.pfn)([
self_t,
PCurrencySymbol_1.PCurrencySymbol.type,
PTokenName_1.PTokenName.type
], types_1.int)(function (value, currSym, tokenName) {
return (0, minimal_common_1._papp)((0, minimal_common_1._papp)((0, minimal_common_1._papp)((0, minimal_1._precursiveList)(types_1.int, exports.PValueEntry.type), (0, plam_1.plam)((0, types_1.fn)([(0, types_1.list)(exports.PValueEntry.type)], types_1.int), (0, types_1.delayed)(types_1.int))(function (_self) { return (0, pdelay_1.pdelay)((0, pInt_1.pInt)(0)); })), (0, pfn_1.pfn)([
(0, types_1.fn)([(0, types_1.list)(exports.PValueEntry.type)], types_1.int),
exports.PValueEntry.type,
(0, types_1.list)(exports.PValueEntry.type)
], types_1.int)(function (self, head, tail) {
return (0, bool_1.pif)(types_1.int).$(head.policy.eq(currSym))
.then((0, minimal_common_1._papp)((0, minimal_common_1._papp)((0, minimal_common_1._papp)((0, minimal_1._precursiveList)(types_1.int, exports.PAssetsEntry.type), (0, plam_1.plam)((0, types_1.fn)([(0, types_1.list)(exports.PAssetsEntry.type)], types_1.int), (0, types_1.delayed)(types_1.int))(function (_self) { return (0, pdelay_1.pdelay)((0, pInt_1.pInt)(0)); })), (0, pfn_1.pfn)([
(0, types_1.fn)([(0, types_1.list)(exports.PAssetsEntry.type)], types_1.int),
exports.PAssetsEntry.type,
(0, types_1.list)(exports.PAssetsEntry.type)
], types_1.int)(function (self, head, tail) {
return (0, bool_1.pif)(types_1.int).$(head.fst.eq(tokenName))
.then(head.snd)
.else(self.$(tail));
})), head.snd))
.else(self.$(tail));
})), value);
}));
return {
amountOf: pvalueOf,
lovelaces: (0, pfn_1.pfn)([self_t], types_1.int)(function (value) {
return pvalueOf.$(value).$("").$("");
})
};
});