UNPKG

@taquito/taquito

Version:

High level functionality that builds upon the other packages in the Tezos Typescript Library Suite.

71 lines 2.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TransactionOperation = void 0; const bignumber_js_1 = require("bignumber.js"); const errors_1 = require("./errors"); const operations_1 = require("./operations"); /** * @description Transaction operation provides utility functions to fetch a newly issued transaction * * @warn Currently supports one transaction per operation */ class TransactionOperation extends operations_1.Operation { constructor(hash, params, source, raw, results, context) { super(hash, raw, results, context); this.params = params; this.source = source; } get operationResults() { const transactionOp = Array.isArray(this.results) && this.results.find((op) => op.kind === 'transaction'); return transactionOp ? [transactionOp] : []; } get status() { const operationResults = this.operationResults; const txResult = operationResults[0]; if (txResult) { return txResult.metadata.operation_result.status; } else { return 'unknown'; } } get amount() { return new bignumber_js_1.default(this.params.amount); } get destination() { return this.params.destination; } get fee() { return Number(this.params.fee); } get gasLimit() { return Number(this.params.gas_limit); } get storageLimit() { return Number(this.params.storage_limit); } sumProp(arr, prop) { return arr.reduce((prev, current) => { return prop in current ? Number(current[prop]) + prev : prev; }, 0); } get consumedGas() { bignumber_js_1.default.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: bignumber_js_1.default.ROUND_UP }); return new bignumber_js_1.default(this.consumedMilliGas).dividedBy(1000).toString(); } get consumedMilliGas() { return String(this.sumProp(errors_1.flattenOperationResult({ contents: this.operationResults }), 'consumed_milligas')); } get storageDiff() { return String(this.sumProp(errors_1.flattenOperationResult({ contents: this.operationResults }), 'paid_storage_size_diff')); } get storageSize() { return String(this.sumProp(errors_1.flattenOperationResult({ contents: this.operationResults }), 'storage_size')); } get errors() { return errors_1.flattenErrors({ contents: this.operationResults }); } } exports.TransactionOperation = TransactionOperation; //# sourceMappingURL=transaction-operation.js.map