@harmoniclabs/plu-ts-offchain
Advanced tools
Comparing version 0.1.13-dev8 to 0.1.13-dev9
@@ -424,3 +424,4 @@ "use strict"; | ||
TxBuilder.prototype.initTxBuild = function (buildArgs) { | ||
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"]); | ||
var _a; | ||
var _b = (0, txBuild_1.normalizeITxBuildArgs)(buildArgs), outputs = _b.outputs, requiredSigners = _b.requiredSigners, mints = _b.mints, invalidAfter = _b.invalidAfter, certificates = _b.certificates, withdrawals = _b.withdrawals, metadata = _b.metadata, votingProcedures = _b.votingProcedures, proposalProcedures = _b.proposalProcedures, currentTreasuryValue = _b.currentTreasuryValue, paymentToTreasury = _b.paymentToTreasury, args = __rest(_b, ["outputs", "requiredSigners", "mints", "invalidAfter", "certificates", "withdrawals", "metadata", "votingProcedures", "proposalProcedures", "currentTreasuryValue", "paymentToTreasury"]); | ||
// mutable args | ||
@@ -881,5 +882,16 @@ var inputs = args.inputs, changeAddress = args.changeAddress, change = args.change, invalidBefore = args.invalidBefore, readonlyRefInputs = args.readonlyRefInputs, collaterals = args.collaterals, collateralReturn = args.collateralReturn; | ||
}); | ||
var totRefScriptBytes = ((_a = dummyTx.body.refInputs) !== null && _a !== void 0 ? _a : []) | ||
.reduce(function (sum, refIn) { | ||
if (refIn.resolved.refScript) | ||
return sum + BigInt(refIn.resolved.refScript.toCbor().toBuffer().length | ||
+ 10 // second Cbor wrap | ||
); | ||
return sum; | ||
}, BigInt(0)); | ||
var minRefScriptFee = this.protocolParamters.minfeeRefScriptCostPerByte ? (totRefScriptBytes * this.protocolParamters.minfeeRefScriptCostPerByte.num / | ||
this.protocolParamters.minfeeRefScriptCostPerByte.den) : BigInt(0); | ||
var minFeeMultiplier = (0, ints_1.forceBigUInt)(this.protocolParamters.txFeePerByte); | ||
var nVkeyWits = BigInt((0, cardano_ledger_ts_1.getNSignersNeeded)(dummyTx.body)); | ||
var nVkeyWits = BigInt((0, utils_1.estimateMaxSignersNeeded)(dummyTx)); | ||
var minFee = this.calcLinearFee(dummyTx) + | ||
minRefScriptFee + | ||
// consider also vkeys witnesses to be added | ||
@@ -886,0 +898,0 @@ // each vkey witness has fixed size of 102 cbor bytes |
@@ -1,3 +0,4 @@ | ||
import { ScriptType } from "@harmoniclabs/cardano-ledger-ts"; | ||
import { ScriptType, Tx } from "@harmoniclabs/cardano-ledger-ts"; | ||
import type { ToDataVersion } from "@harmoniclabs/cardano-ledger-ts/dist/toData/defaultToDataVersion"; | ||
export declare function scriptTypeToDataVersion(scriptType: ScriptType): ToDataVersion | undefined; | ||
export declare function estimateMaxSignersNeeded(tx: Tx): number; |
"use strict"; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.scriptTypeToDataVersion = void 0; | ||
exports.estimateMaxSignersNeeded = exports.scriptTypeToDataVersion = void 0; | ||
var cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts"); | ||
@@ -16,1 +41,27 @@ function scriptTypeToDataVersion(scriptType) { | ||
exports.scriptTypeToDataVersion = scriptTypeToDataVersion; | ||
function estimateMaxSignersNeeded(tx) { | ||
var _a; | ||
var bodySigners = (0, cardano_ledger_ts_1.getAllRequiredSigners)(tx.body) | ||
.map(function (hash) { return hash.toString(); }) | ||
.filter(function (elem, i, thisArr) { return thisArr.indexOf(elem) === i; }); | ||
var allSigners = getAllNativeScriptSigners(((_a = tx.witnesses.nativeScripts) !== null && _a !== void 0 ? _a : []) | ||
.map(function (script) { return script.toJson(); })) | ||
.filter(function (native) { return native.type === "sig"; }) | ||
.map(function (native) { return native.keyHash.toString(); }) | ||
.concat(bodySigners) | ||
.filter(function (elem, i, thisArr) { return thisArr.indexOf(elem) === i; }); | ||
return allSigners.length <= 0 ? 1 : allSigners.length; | ||
} | ||
exports.estimateMaxSignersNeeded = estimateMaxSignersNeeded; | ||
function getAllNativeScriptSigners(natives) { | ||
return natives | ||
.reduce(function (accum, native) { | ||
if (native.type === "sig") | ||
accum.push(native); | ||
if (native.type === "all" || | ||
native.type === "any" || | ||
native.type === "atLeast") | ||
accum.push.apply(accum, __spreadArray([], __read(getAllNativeScriptSigners(native.scripts)), false)); | ||
return accum; | ||
}, []); | ||
} |
{ | ||
"name": "@harmoniclabs/plu-ts-offchain", | ||
"version": "0.1.13-dev8", | ||
"version": "0.1.13-dev9", | ||
"description": "An embedded DSL for Cardano smart contracts creation coupled with a library for Cardano transactions, all in Typescript", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
260126
4842