@mavrykdynamics/taquito
Version:
High level functionality that builds upon the other packages in the Mavryk Typescript Library Suite.
44 lines (43 loc) • 2.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.receiptFromOperation = void 0;
const bignumber_js_1 = require("bignumber.js");
const constants_1 = require("../constants");
const errors_1 = require("../operations/errors");
const receiptFromOperation = (op, { ALLOCATION_BURN, ORIGINATION_BURN } = {
ALLOCATION_BURN: 257,
ORIGINATION_BURN: 257,
}) => {
bignumber_js_1.default.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: bignumber_js_1.default.ROUND_UP });
const operationResults = (0, errors_1.flattenOperationResult)({ contents: op });
let totalMilliGas = new bignumber_js_1.default(0);
let totalStorage = new bignumber_js_1.default(0);
let totalFee = new bignumber_js_1.default(0);
let totalOriginationBurn = new bignumber_js_1.default(0);
let totalAllocationBurn = new bignumber_js_1.default(0);
let totalPaidStorageDiff = new bignumber_js_1.default(0);
operationResults.forEach((result) => {
totalFee = totalFee.plus(result.fee || 0);
totalOriginationBurn = totalOriginationBurn.plus(Array.isArray(result.originated_contracts)
? result.originated_contracts.length * ORIGINATION_BURN
: 0);
totalAllocationBurn = totalAllocationBurn.plus('allocated_destination_contract' in result ? ALLOCATION_BURN : 0);
totalMilliGas = totalMilliGas.plus(result.consumed_milligas || 0);
totalPaidStorageDiff = totalPaidStorageDiff.plus('paid_storage_size_diff' in result ? Number(result.paid_storage_size_diff) || 0 : 0);
});
totalStorage = totalStorage
.plus(totalAllocationBurn)
.plus(totalOriginationBurn)
.plus(totalPaidStorageDiff);
return {
totalFee,
totalMilliGas,
totalGas: totalMilliGas.dividedBy(1000),
totalStorage,
totalAllocationBurn,
totalOriginationBurn,
totalPaidStorageDiff,
totalStorageBurn: new bignumber_js_1.default(totalStorage.multipliedBy(constants_1.COST_PER_BYTE)),
};
};
exports.receiptFromOperation = receiptFromOperation;