@harmoniclabs/plu-ts-offchain
Advanced tools
Comparing version 0.1.13-dev4 to 0.1.13-dev5
import { TxBody, TxRedeemer } from "@harmoniclabs/cardano-ledger-ts"; | ||
import type { ToDataVersion } from "@harmoniclabs/cardano-ledger-ts/dist/toData/defaultToDataVersion"; | ||
import { DataConstr } from "@harmoniclabs/plutus-data"; | ||
import { Data, DataConstr } from "@harmoniclabs/plutus-data"; | ||
export declare function getSpendingPurposeData(rdmr: TxRedeemer, tx: TxBody, version: ToDataVersion): DataConstr; | ||
export declare function getScriptInfoData(rdmr: TxRedeemer, tx: TxBody, version: ToDataVersion, datum?: Data | undefined): DataConstr; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getSpendingPurposeData = void 0; | ||
exports.getScriptInfoData = exports.getSpendingPurposeData = void 0; | ||
var cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts"); | ||
@@ -8,7 +8,16 @@ var plutus_data_1 = require("@harmoniclabs/plutus-data"); | ||
function getSpendingPurposeData(rdmr, tx, version) { | ||
var _a, _b, _c, _d, _e; | ||
version = version !== null && version !== void 0 ? version : "v2"; | ||
var scriptInfos = getScriptInfoData(rdmr, tx, version); | ||
// for all versions, purpose has never the datum, | ||
// only script info has the datum | ||
if (rdmr.tag === cardano_ledger_ts_1.TxRedeemerTag.Spend) | ||
return new plutus_data_1.DataConstr(scriptInfos.constr, [scriptInfos.fields[0]]); | ||
return scriptInfos; | ||
} | ||
exports.getSpendingPurposeData = getSpendingPurposeData; | ||
function getScriptInfoData(rdmr, tx, version, datum) { | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
version = version !== null && version !== void 0 ? version : "v3"; | ||
var tag = rdmr.tag; | ||
var ctorIdx; | ||
var purposeArgData; | ||
var purposeArgs; | ||
if (tag === cardano_ledger_ts_1.TxRedeemerTag.Mint) { | ||
@@ -19,3 +28,3 @@ ctorIdx = 0; | ||
throw new Error("invalid minting policy for minting redeemer " + rdmr.index.toString()); | ||
purposeArgData = new plutus_data_1.DataB(policy.toBuffer()); | ||
purposeArgs = [new plutus_data_1.DataB(policy.toBuffer())]; | ||
} | ||
@@ -36,4 +45,8 @@ else if (tag === cardano_ledger_ts_1.TxRedeemerTag.Spend) { | ||
"; tx.inputs.length is: " + tx.inputs.length.toString()); | ||
// @ts-ignore Expected 0 arguments, but got 1.t | ||
purposeArgData = utxoRef.toData(version); | ||
purposeArgs = [utxoRef.toData(version)]; | ||
if (version === "v3") | ||
purposeArgs.push((0, plutus_data_1.isData)(datum) ? | ||
new plutus_data_1.DataConstr(0, [datum]) : // just datum | ||
new plutus_data_1.DataConstr(1, []) // nothing | ||
); | ||
} | ||
@@ -45,5 +58,6 @@ else if (tag === cardano_ledger_ts_1.TxRedeemerTag.Withdraw) { | ||
throw new Error("invalid stake credentials for rewarding redeemer " + rdmr.index.toString()); | ||
purposeArgData = new cardano_ledger_ts_1.StakeCredentials("script", new cardano_ledger_ts_1.StakeValidatorHash(stakeAddr.credentials)) | ||
// @ts-ignore Expected 0 arguments, but got 1.t | ||
.toData(version); | ||
purposeArgs = [ | ||
new cardano_ledger_ts_1.StakeCredentials("script", new cardano_ledger_ts_1.StakeValidatorHash(stakeAddr.credentials)) | ||
.toData(version) | ||
]; | ||
} | ||
@@ -60,8 +74,40 @@ else if (tag === cardano_ledger_ts_1.TxRedeemerTag.Cert) { | ||
} | ||
purposeArgData = tmp; | ||
purposeArgs = [tmp]; | ||
if (version === "v3") { | ||
purposeArgs.unshift(new plutus_data_1.DataI(rdmr.index)); | ||
} | ||
} | ||
else if (version !== "v3") { | ||
throw new Error("voting and proposing script purpose only introduced in plutus v3"); | ||
} | ||
else if (tag === cardano_ledger_ts_1.TxRedeemerTag.Voting) { | ||
ctorIdx = 4; | ||
var votingProcedure = (_f = tx.votingProcedures) === null || _f === void 0 ? void 0 : _f.procedures.filter(function (p) { | ||
return p.voter.kind === cardano_ledger_ts_1.VoterKind.ConstitutionalCommitteScript || | ||
p.voter.kind === cardano_ledger_ts_1.VoterKind.DRepScript; | ||
})[rdmr.index]; | ||
if (!votingProcedure) { | ||
throw new Error("mismatching voting redeemer, couldn't find voting procedure at index " + | ||
rdmr.index.toString()); | ||
} | ||
purposeArgs = [ | ||
votingProcedure.voter.toData(version) | ||
]; | ||
} | ||
else if (tag === cardano_ledger_ts_1.TxRedeemerTag.Proposing) { | ||
ctorIdx = 5; | ||
var proposalProcedure = (_g = tx.proposalProcedures) === null || _g === void 0 ? void 0 : _g.filter(function (p) { return p.rewardAccount.type === "script"; })[rdmr.index]; | ||
if (!proposalProcedure) { | ||
throw new Error("mismatching proposal redeemer, couldn't find voting procedure at index " + | ||
rdmr.index.toString()); | ||
} | ||
purposeArgs = [ | ||
new plutus_data_1.DataI(rdmr.index), | ||
proposalProcedure.toData(version) | ||
]; | ||
} | ||
else | ||
throw new Error("invalid redeemer tag"); | ||
return new plutus_data_1.DataConstr(ctorIdx, [purposeArgData]); | ||
return new plutus_data_1.DataConstr(ctorIdx, purposeArgs); | ||
} | ||
exports.getSpendingPurposeData = getSpendingPurposeData; | ||
exports.getScriptInfoData = getScriptInfoData; |
@@ -27,2 +27,3 @@ "use strict"; | ||
var mintData = ((_b = tx.mint) !== null && _b !== void 0 ? _b : cardano_ledger_ts_1.Value.lovelaces(0)).toData(); | ||
var mintDataNoLovelaces = new plutus_data_1.DataMap(mintData.map.slice(1)); | ||
var intervalData = (0, getTxIntervalData_1.getTxIntervalData)(tx.validityIntervalStart, tx.ttl, genesisInfos); | ||
@@ -57,3 +58,3 @@ var sigsData = new plutus_data_1.DataList((_d = (_c = tx.requiredSigners) === null || _c === void 0 ? void 0 : _c.map(function (sig) { return sig.toData(); })) !== null && _d !== void 0 ? _d : []); | ||
// id | ||
txIdData.clone() | ||
new plutus_data_1.DataConstr(0, [txIdData.clone()]) | ||
]); | ||
@@ -92,3 +93,3 @@ } | ||
// id | ||
txIdData | ||
new plutus_data_1.DataConstr(0, [txIdData.clone()]) | ||
]); | ||
@@ -107,7 +108,7 @@ } | ||
new plutus_data_1.DataList(tx.outputs.map(function (out) { return out.toData("v3"); })), | ||
// fee | ||
feeData, | ||
// fee (only lovelaces) | ||
new plutus_data_1.DataI(tx.fee), | ||
// mint | ||
mintData, | ||
// dCertificates | ||
mintDataNoLovelaces, | ||
// certificates | ||
new plutus_data_1.DataList((_v = (_u = tx.certs) === null || _u === void 0 ? void 0 : _u.map(function (cert) { return cert.toData("v3"); })) !== null && _v !== void 0 ? _v : []), | ||
@@ -114,0 +115,0 @@ // withderawals |
@@ -66,3 +66,3 @@ "use strict"; | ||
// from | ||
new plutus_data_1.DataConstr(// PLowerBound | ||
new plutus_data_1.DataConstr(// PBound | ||
0, // only constructor | ||
@@ -76,3 +76,3 @@ [ | ||
// to | ||
new plutus_data_1.DataConstr(// PUpperBound | ||
new plutus_data_1.DataConstr(// PBound | ||
0, // only constructor | ||
@@ -79,0 +79,0 @@ [ |
import { GenesisInfos, NormalizedGenesisInfos } from "./GenesisInfos.js"; | ||
import { Tx, Value, ValueUnits, TxOut, TxRedeemerTag, ScriptType, TxRedeemer, ScriptDataHash } from "@harmoniclabs/cardano-ledger-ts"; | ||
import { Tx, Value, ValueUnits, TxOut, TxRedeemerTag, ScriptType, UTxO, TxRedeemer, ScriptDataHash } from "@harmoniclabs/cardano-ledger-ts"; | ||
import { CborString, CanBeCborString } from "@harmoniclabs/cbor"; | ||
@@ -74,2 +74,3 @@ import { Data } from "@harmoniclabs/plutus-data"; | ||
}; | ||
findCollaterals(utxos: UTxO[], targetCollateralLovelaces?: number | bigint): UTxO[]; | ||
} | ||
@@ -76,0 +77,0 @@ type ScriptToExecEntry = { |
@@ -76,2 +76,13 @@ "use strict"; | ||
}; | ||
var __values = (this && this.__values) || function(o) { | ||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; | ||
if (m) return m.call(o); | ||
if (o && typeof o.length === "number") return { | ||
next: function () { | ||
if (o && i >= o.length) o = void 0; | ||
return { value: o && o[i++], done: !o }; | ||
} | ||
}; | ||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
@@ -310,4 +321,6 @@ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
throw new Error("unexpected redeemer for native script"); | ||
var ctxData = getCtx(script.type, (0, getSpendingPurposeData_1.getSpendingPurposeData)(rdmr, tx.body, expectedVersion), txInfosV1, txInfosV2, txInfosV3); | ||
var _b = cek.eval(new uplc_1.Application(new uplc_1.Application(getScriptLikeUplc(script), uplc_1.UPLCConst.data(rdmrData)), uplc_1.UPLCConst.data(ctxData))), result = _b.result, budgetSpent = _b.budgetSpent, logs = _b.logs; | ||
var ctxData = getCtx(script.type, (0, getSpendingPurposeData_1.getSpendingPurposeData)(rdmr, tx.body, expectedVersion), (0, getSpendingPurposeData_1.getScriptInfoData)(rdmr, tx.body, expectedVersion), rdmrData, txInfosV1, txInfosV2, txInfosV3); | ||
var _b = cek.eval(script.type === cardano_ledger_ts_1.ScriptType.PlutusV3 ? | ||
new uplc_1.Application(getScriptLikeUplc(script), uplc_1.UPLCConst.data(ctxData)) : | ||
new uplc_1.Application(new uplc_1.Application(getScriptLikeUplc(script), uplc_1.UPLCConst.data(rdmrData)), uplc_1.UPLCConst.data(ctxData))), result = _b.result, budgetSpent = _b.budgetSpent, logs = _b.logs; | ||
_isScriptValid = onEvaluationResult(i, totExBudget, rdmr, result, budgetSpent, logs, [ | ||
@@ -326,3 +339,4 @@ rdmrData, | ||
var script = entry.script, datum = entry.datum; | ||
if (datum === undefined) | ||
var isV2OrLess = script.type === cardano_ledger_ts_1.ScriptType.PlutusV1 || script.type === cardano_ledger_ts_1.ScriptType.PlutusV2; | ||
if (datum === undefined && isV2OrLess) | ||
throw new Error("missing datum for spend redeemer " + index); | ||
@@ -332,9 +346,11 @@ var expectedVersion = (0, utils_1.scriptTypeToDataVersion)(script.type); | ||
throw new Error("unexpected redeemer for native script"); | ||
var ctxData = getCtx(script.type, (0, getSpendingPurposeData_1.getSpendingPurposeData)(rdmr, tx.body, expectedVersion), txInfosV1, txInfosV2, txInfosV3); | ||
var _f = cek.eval(new uplc_1.Application(new uplc_1.Application(new uplc_1.Application(getScriptLikeUplc(script), uplc_1.UPLCConst.data(datum)), uplc_1.UPLCConst.data(rdmrData)), uplc_1.UPLCConst.data(ctxData))), result = _f.result, budgetSpent = _f.budgetSpent, logs = _f.logs; | ||
_isScriptValid = onEvaluationResult(i, totExBudget, rdmr, result, budgetSpent, logs, [ | ||
var ctxData = getCtx(script.type, (0, getSpendingPurposeData_1.getSpendingPurposeData)(rdmr, tx.body, expectedVersion), (0, getSpendingPurposeData_1.getScriptInfoData)(rdmr, tx.body, expectedVersion, datum), rdmrData, txInfosV1, txInfosV2, txInfosV3); | ||
var _f = cek.eval(isV2OrLess ? | ||
new uplc_1.Application(new uplc_1.Application(new uplc_1.Application(getScriptLikeUplc(script), uplc_1.UPLCConst.data(datum)), uplc_1.UPLCConst.data(rdmrData)), uplc_1.UPLCConst.data(ctxData)) : | ||
new uplc_1.Application(getScriptLikeUplc(script), uplc_1.UPLCConst.data(ctxData))), result = _f.result, budgetSpent = _f.budgetSpent, logs = _f.logs; | ||
_isScriptValid = onEvaluationResult(i, totExBudget, rdmr, result, budgetSpent, logs, isV2OrLess ? [ | ||
datum, | ||
rdmrData, | ||
ctxData | ||
], rdmrs, onScriptResult, onScriptInvalid); | ||
] : [ctxData], rdmrs, onScriptResult, onScriptInvalid); | ||
} | ||
@@ -412,5 +428,5 @@ else if (tag === cardano_ledger_ts_1.TxRedeemerTag.Mint) | ||
TxBuilder.prototype.initTxBuild = function (buildArgs) { | ||
var _a = (0, txBuild_1.normalizeITxBuildArgs)(buildArgs), outputs = _a.outputs, requiredSigners = _a.requiredSigners, collaterals = _a.collaterals, collateralReturn = _a.collateralReturn, mints = _a.mints, invalidAfter = _a.invalidAfter, certificates = _a.certificates, withdrawals = _a.withdrawals, metadata = _a.metadata, votingProcedures = _a.votingProcedures, proposalProcedures = _a.proposalProcedures, currentTreasuryValue = _a.currentTreasuryValue, paymentToTreasury = _a.paymentToTreasury, args = __rest(_a, ["outputs", "requiredSigners", "collaterals", "collateralReturn", "mints", "invalidAfter", "certificates", "withdrawals", "metadata", "votingProcedures", "proposalProcedures", "currentTreasuryValue", "paymentToTreasury"]); | ||
var _a = (0, txBuild_1.normalizeITxBuildArgs)(buildArgs), outputs = _a.outputs, requiredSigners = _a.requiredSigners, mints = _a.mints, invalidAfter = _a.invalidAfter, certificates = _a.certificates, withdrawals = _a.withdrawals, metadata = _a.metadata, votingProcedures = _a.votingProcedures, proposalProcedures = _a.proposalProcedures, currentTreasuryValue = _a.currentTreasuryValue, paymentToTreasury = _a.paymentToTreasury, args = __rest(_a, ["outputs", "requiredSigners", "mints", "invalidAfter", "certificates", "withdrawals", "metadata", "votingProcedures", "proposalProcedures", "currentTreasuryValue", "paymentToTreasury"]); | ||
// mutable args | ||
var inputs = args.inputs, changeAddress = args.changeAddress, change = args.change, invalidBefore = args.invalidBefore, readonlyRefInputs = args.readonlyRefInputs; | ||
var inputs = args.inputs, changeAddress = args.changeAddress, change = args.change, invalidBefore = args.invalidBefore, readonlyRefInputs = args.readonlyRefInputs, collaterals = args.collaterals, collateralReturn = args.collateralReturn; | ||
if (change) | ||
@@ -588,12 +604,12 @@ changeAddress = change.address; | ||
var dat = pushWitDatum(datum, utxo.resolved.datum); | ||
var i = sortedIns.indexOf(input); | ||
if (i < 0) | ||
var i_1 = sortedIns.indexOf(input); | ||
if (i_1 < 0) | ||
throw new Error("input missing in sorted"); | ||
spendRedeemers.push(new cardano_ledger_ts_1.TxRedeemer({ | ||
data: (0, CanBeData_1.forceData)(redeemer), | ||
index: i, | ||
index: i_1, | ||
execUnits: dummyExecBudget.clone(), | ||
tag: cardano_ledger_ts_1.TxRedeemerTag.Spend | ||
})); | ||
pushScriptToExec(i, cardano_ledger_ts_1.TxRedeemerTag.Spend, refScript, dat); | ||
pushScriptToExec(i_1, cardano_ledger_ts_1.TxRedeemerTag.Spend, refScript, dat); | ||
} | ||
@@ -606,12 +622,12 @@ if (inputScript !== undefined) { | ||
var dat = pushWitDatum(datum, utxo.resolved.datum); | ||
var i = sortedIns.indexOf(input); | ||
if (i < 0) | ||
var i_2 = sortedIns.indexOf(input); | ||
if (i_2 < 0) | ||
throw new Error("input missing in sorted"); | ||
spendRedeemers.push(new cardano_ledger_ts_1.TxRedeemer({ | ||
data: (0, CanBeData_1.forceData)(redeemer), | ||
index: i, | ||
index: i_2, | ||
execUnits: dummyExecBudget.clone(), | ||
tag: cardano_ledger_ts_1.TxRedeemerTag.Spend | ||
})); | ||
pushScriptToExec(i, cardano_ledger_ts_1.TxRedeemerTag.Spend, script, dat); | ||
pushScriptToExec(i_2, cardano_ledger_ts_1.TxRedeemerTag.Spend, script, dat); | ||
} | ||
@@ -706,4 +722,5 @@ return new cardano_ledger_ts_1.TxIn(utxo); | ||
}); | ||
var i = 0; | ||
var _votingProcedures = Array.isArray(votingProcedures) ? | ||
new cardano_ledger_ts_1.VotingProcedures(votingProcedures === null || votingProcedures === void 0 ? void 0 : votingProcedures.map(function (_a, i) { | ||
new cardano_ledger_ts_1.VotingProcedures(votingProcedures === null || votingProcedures === void 0 ? void 0 : votingProcedures.map(function (_a) { | ||
var votingProcedure = _a.votingProcedure, script = _a.script; | ||
@@ -719,11 +736,12 @@ if (script !== undef) { | ||
pushScriptToExec(i, cardano_ledger_ts_1.TxRedeemerTag.Voting, toExec); | ||
i++; | ||
} | ||
return votingProcedure; | ||
})) : undef; | ||
// TODO | ||
i = 0; | ||
var _proposalProcedures = Array.isArray(proposalProcedures) ? | ||
proposalProcedures.map(function (_a, i) { | ||
proposalProcedures.map(function (_a) { | ||
var proposalProcedure = _a.proposalProcedure, script = _a.script; | ||
if (script !== undef) { | ||
voteRedeemers.push(new cardano_ledger_ts_1.TxRedeemer({ | ||
proposeRedeemers.push(new cardano_ledger_ts_1.TxRedeemer({ | ||
data: (0, CanBeData_1.forceData)(script.redeemer), | ||
@@ -736,5 +754,7 @@ index: i, | ||
pushScriptToExec(i, cardano_ledger_ts_1.TxRedeemerTag.Proposing, toExec); | ||
i++; | ||
} | ||
return new cardano_ledger_ts_1.ProposalProcedure(proposalProcedure); | ||
}) : undef; | ||
i = 0; | ||
var auxData = metadata !== undefined ? new cardano_ledger_ts_1.AuxiliaryData({ metadata: metadata }) : undefined; | ||
@@ -780,9 +800,22 @@ var redeemers = spendRedeemers | ||
if (!Array.isArray(collaterals) || | ||
collaterals.length <= 0) | ||
throw new Error("tx includes plutus scripts to execute but no collateral input was provided"); | ||
collaterals.length <= 0) { | ||
collaterals = this.findCollaterals(_inputs); | ||
collateralReturn = undef; | ||
} | ||
if (collaterals.length <= 0) | ||
throw new Error("collaterals missing, and no input could be used"); | ||
var collateralValue = collaterals.reduce(function (accum, collateral) { return cardano_ledger_ts_1.Value.add(accum, collateral.resolved.value); }, cardano_ledger_ts_1.Value.zero); | ||
if (!cardano_ledger_ts_1.Value.isAdaOnly(collateralValue)) { | ||
if (!collateralReturn) | ||
throw new Error("total collateral input value was including non-ADA value; no collateral return was specified\n" + | ||
"total collateral input value was: ".concat(JSON.stringify(collateralValue.toJson(), undef, 2))); | ||
if (!collateralReturn) { | ||
var addr = collaterals[0].resolved.address; | ||
collateralReturn = new cardano_ledger_ts_1.TxOut({ | ||
address: addr, | ||
value: collateralValue | ||
}); | ||
var minAda = this.getMinimumOutputLovelaces(collateralReturn); | ||
collateralReturn = new cardano_ledger_ts_1.TxOut({ | ||
address: addr, | ||
value: cardano_ledger_ts_1.Value.sub(collateralValue, cardano_ledger_ts_1.Value.lovelaces(collateralValue.lovelaces - minAda)) | ||
}); | ||
} | ||
var realCollValue = cardano_ledger_ts_1.Value.sub(collateralValue, collateralReturn.value); | ||
@@ -861,2 +894,66 @@ if (!cardano_ledger_ts_1.Value.isAdaOnly(realCollValue)) | ||
}; | ||
TxBuilder.prototype.findCollaterals = function (utxos, targetCollateralLovelaces) { | ||
var e_1, _a, e_2, _b; | ||
var _c; | ||
if (targetCollateralLovelaces === void 0) { targetCollateralLovelaces = 10000000; } | ||
var grouped = {}; | ||
var pkhs = []; | ||
try { | ||
for (var utxos_1 = __values(utxos), utxos_1_1 = utxos_1.next(); !utxos_1_1.done; utxos_1_1 = utxos_1.next()) { | ||
var u = utxos_1_1.value; | ||
var creds = u.resolved.address.paymentCreds; | ||
if (creds.type === cardano_ledger_ts_1.CredentialType.Script) | ||
continue; | ||
var pkh = creds.hash.toString(); | ||
if (!Array.isArray(grouped[pkh])) { | ||
grouped[pkh] = []; | ||
pkhs.push(pkh); | ||
} | ||
grouped[pkh].push(u); | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (utxos_1_1 && !utxos_1_1.done && (_a = utxos_1.return)) _a.call(utxos_1); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
if (pkhs.length === 0) | ||
return []; | ||
for (var i = 0; i < pkhs.length; i++) { | ||
var pkh = pkhs[i]; | ||
grouped[pkh] = grouped[pkh] | ||
.sort(function (a, b) { return -Number(a.resolved.value.lovelaces - b.resolved.value.lovelaces); }) | ||
.slice(0, Number((_c = this.protocolParamters.maxCollateralInputs) !== null && _c !== void 0 ? _c : 3)); | ||
} | ||
var maxPkh = pkhs.shift(); | ||
var maxLove = grouped[maxPkh].reduce(function (a, b) { return a + b.resolved.value.lovelaces; }, BigInt(0)); | ||
try { | ||
for (var pkhs_1 = __values(pkhs), pkhs_1_1 = pkhs_1.next(); !pkhs_1_1.done; pkhs_1_1 = pkhs_1.next()) { | ||
var pkh = pkhs_1_1.value; | ||
var love = grouped[pkh].reduce(function (a, b) { return a + b.resolved.value.lovelaces; }, BigInt(0)); | ||
if (love > maxLove) { | ||
maxPkh = pkh; | ||
maxLove = love; | ||
} | ||
} | ||
} | ||
catch (e_2_1) { e_2 = { error: e_2_1 }; } | ||
finally { | ||
try { | ||
if (pkhs_1_1 && !pkhs_1_1.done && (_b = pkhs_1.return)) _b.call(pkhs_1); | ||
} | ||
finally { if (e_2) throw e_2.error; } | ||
} | ||
var collaterals = grouped[maxPkh]; | ||
targetCollateralLovelaces = BigInt(targetCollateralLovelaces); | ||
if (targetCollateralLovelaces < 0) | ||
targetCollateralLovelaces = -targetCollateralLovelaces; | ||
var filtered = collaterals.filter(function (u) { return u.resolved.value.lovelaces >= targetCollateralLovelaces; }); | ||
if (filtered.length === 0) | ||
return collaterals; | ||
// try to reduce the number of utxo collaterals and collateral value. | ||
return [filtered[filtered.length - 1]]; | ||
}; | ||
return TxBuilder; | ||
@@ -874,7 +971,8 @@ }()); | ||
} | ||
function getCtx(scriptType, spendingPurpose, txInfosV1, txInfosV2, txInfosV3) { | ||
function getCtx(scriptType, spendingPurpose, scriptInfo, redeemerData, txInfosV1, txInfosV2, txInfosV3) { | ||
if (scriptType === cardano_ledger_ts_1.ScriptType.PlutusV3) { | ||
return new plutus_data_1.DataConstr(0, [ | ||
txInfosV3, | ||
spendingPurpose | ||
redeemerData, | ||
scriptInfo | ||
]); | ||
@@ -884,3 +982,3 @@ } | ||
if (txInfosV2 === undefined) | ||
throw new Error("plutus script v1 included in a v2 transaction"); | ||
throw new Error("plutus script v2 included in a v3 transaction"); | ||
return new plutus_data_1.DataConstr(0, [ | ||
@@ -925,6 +1023,3 @@ txInfosV2, | ||
.map(function (d, i) { | ||
return (i === 0 ? (rdmr.tag === cardano_ledger_ts_1.TxRedeemerTag.Spend ? "datum" : "redeemer") : | ||
i === 1 ? (rdmr.tag === cardano_ledger_ts_1.TxRedeemerTag.Spend ? "redeemer" : "script context") : | ||
i === 2 ? (rdmr.tag === cardano_ledger_ts_1.TxRedeemerTag.Spend ? "script context" : i.toString()) : | ||
i.toString()) + ": " + (0, plutus_data_1.dataToCbor)(d).toString(); | ||
return i.toString() + ": " + (0, plutus_data_1.dataToCbor)(d).toString(); | ||
}) | ||
@@ -931,0 +1026,0 @@ .join("\n"), "\n\n") + |
{ | ||
"name": "@harmoniclabs/plu-ts-offchain", | ||
"version": "0.1.13-dev4", | ||
"version": "0.1.13-dev5", | ||
"description": "An embedded DSL for Cardano smart contracts creation coupled with a library for Cardano transactions, all in Typescript", | ||
@@ -67,5 +67,5 @@ "main": "./dist/index.js", | ||
"@harmoniclabs/cardano-costmodels-ts": "^1.1.0", | ||
"@harmoniclabs/plutus-machine": "^2.0.0-dev2", | ||
"@harmoniclabs/plutus-machine": "^2.0.0-dev3", | ||
"@harmoniclabs/uplc": "^1.2.3", | ||
"@harmoniclabs/cardano-ledger-ts": "^0.2.0-dev6" | ||
"@harmoniclabs/cardano-ledger-ts": "^0.2.1" | ||
}, | ||
@@ -72,0 +72,0 @@ "devDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
254492
4727