UNPKG

@pokt-network/pocket-js

Version:

Pocket-js core package with the main functionalities to interact with the Pocket Network.

80 lines 3.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RawTxResponse = void 0; var tx_log_1 = require("./tx-log"); var utils_1 = require("../../../utils"); /** * Represents a /v1/rawtx RPC response */ var RawTxResponse = /** @class */ (function () { /** * Constructor for this class * @param {BigInt} height - The height for this Transaction * @param {string} hash - The transaction hash in hex format * @param {BigInt} code - The code for this tx * @param {string} data - Data hex for this tranaction * @param {string} rawLog - Dumped logs in string format * @param {TxLog[]} logs - Logs for this transaction * @param {string} info - Raw tx information. * @param {string} codeSpace - Code space string. * @param {string} tx - Transaction string. * @param {string} timestamp - Transaction timestamp. */ function RawTxResponse(height, hash, code, data, rawLog, logs, info, codeSpace, tx, timestamp) { this.height = height; this.hash = hash; this.code = code; this.data = data; this.rawLog = rawLog; this.logs = logs; this.info = info; this.codeSpace = codeSpace; this.tx = tx; this.timestamp = timestamp; } /** * Construct this model from it's JSON representation * @param jsonStr {string} * @returns {RawTxResponse | Error} */ RawTxResponse.fromJSON = function (jsonStr) { var _a; try { var rawTxResObj = JSON.parse(jsonStr); var logs = []; var height = void 0; var hash = void 0; height = BigInt((_a = rawTxResObj.height) !== null && _a !== void 0 ? _a : 0); if (rawTxResObj.txhash && utils_1.typeGuard(rawTxResObj.txhash, "string")) { hash = rawTxResObj.txhash; } else { return new Error("Failed to parse RawTxRespone due to invalid tx hash: " + rawTxResObj.txhash); } // Parse the logs if they are available if (rawTxResObj.logs && utils_1.typeGuard(rawTxResObj.logs, Array)) { var logObjs = rawTxResObj.logs; for (var i = 0; i < logObjs.length; i++) { var txLogOrError = tx_log_1.TxLog.fromJSONObj(logObjs[i]); if (utils_1.typeGuard(txLogOrError, tx_log_1.TxLog)) { logs.push(txLogOrError); } } } var rawLog = rawTxResObj.raw_log ? rawTxResObj.raw_log : undefined; if (rawLog !== undefined) { // Search for errors if (rawLog.includes("ERROR") || rawLog.include("error")) { return new Error(rawLog); } } return new RawTxResponse(height, hash, rawTxResObj.code ? BigInt(rawTxResObj.code) : undefined, rawTxResObj.data ? rawTxResObj.data : undefined, rawLog, logs, rawTxResObj.info ? rawTxResObj.info : undefined, rawTxResObj.codespace ? rawTxResObj.codespace : undefined, rawTxResObj.tx ? rawTxResObj.tx : undefined, rawTxResObj.timestamp ? rawTxResObj.timestamp : undefined); } catch (err) { return err; } }; return RawTxResponse; }()); exports.RawTxResponse = RawTxResponse; //# sourceMappingURL=raw-tx-response.js.map