UNPKG

@pokt-network/pocket-js

Version:

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

84 lines 2.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ResultTx = void 0; var __1 = require("../.."); var response_deliver_tx_1 = require("./response-deliver-tx"); /** * * * @class ResultTx */ var ResultTx = /** @class */ (function () { /** * Creates a ResultTx. * @constructor * @param {string} hash - * @param {BigInt} height - * @param {number} index - * @param {ResponseDeliverTx} txResult - * @param {Transaction} tx - * @param {TxProof} txProof - */ function ResultTx(hash, height, index, txResult, tx, txProof) { this.hash = hash; this.height = height; this.index = index; this.txResult = txResult; this.tx = tx; this.txProof = txProof; if (!this.isValid()) { throw new TypeError("Invalid ResultTx properties."); } } /** * * Creates a ResultTx object using a JSON string * @param {String} json - JSON string. * @returns {ResultTx} - ResultTx object. * @memberof ResultTx */ ResultTx.fromJSON = function (json) { try { var jsonObject = JSON.parse(json); var txProof = __1.TxProof.fromJSON(JSON.stringify(jsonObject.proof)); var responseDeliverTx = response_deliver_tx_1.ResponseDeliverTx.fromJSON(JSON.stringify(jsonObject.tx_result)); return new ResultTx(jsonObject.hash, BigInt(jsonObject.height), jsonObject.index, responseDeliverTx, Buffer.from(jsonObject.tx, "base64"), txProof); } catch (error) { throw error; } }; /** * * Creates a JSON object with the ResultTx properties * @returns {JSON} - JSON Object. * @memberof ResultTx */ ResultTx.prototype.toJSON = function () { return { hash: this.hash, height: Number(this.height.toString()), index: this.index, tx_result: this.txResult.toJSON(), tx: this.tx.toString("base64"), proof: this.txProof.toJSON() }; }; /** * * Verify if all properties are valid * @returns {boolean} - True or false. * @memberof ResultTx */ ResultTx.prototype.isValid = function () { return this.hash.length > 0 && Number(this.height.toString()) >= 0 && this.index >= 0 && this.txResult.isValid() && this.tx.length > 0 && this.txProof.isValid(); }; return ResultTx; }()); exports.ResultTx = ResultTx; //# sourceMappingURL=result-tx.js.map