@pokt-network/pocket-js
Version:
Pocket-js core package with the main functionalities to interact with the Pocket Network.
78 lines • 2.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.QueryBlockTxsResponse = void 0;
var transaction_1 = require("../transaction");
/**
*
*
* @class QueryBlockTxsResponse
*/
var QueryBlockTxsResponse = /** @class */ (function () {
/**
* Query block transactions Response.
* @constructor
* @param {Transaction[]} transactions - List of transactions.
* @param {number} totalCount - Transaction count
*/
function QueryBlockTxsResponse(transactions, totalCount, pageCount) {
this.transactions = transactions;
this.totalCount = totalCount;
this.pageCount = pageCount;
if (!this.isValid()) {
throw new TypeError("Invalid QueryBlockTxsResponse properties.");
}
}
/**
*
* Creates a QueryBlockTxsResponse object using a JSON string
* @param {String} json - JSON string.
* @returns {QueryBlockTxsResponse} - QueryBlockTxsResponse object.
* @memberof QueryBlockTxsResponse
*/
QueryBlockTxsResponse.fromJSON = function (json) {
try {
var rawObjValue = JSON.parse(json);
var transactions_1 = [];
if (rawObjValue.txs) {
rawObjValue.txs.forEach(function (tx) {
var resultTx = transaction_1.Transaction.fromJSON(JSON.stringify(tx));
transactions_1.push(resultTx);
});
}
return new QueryBlockTxsResponse(transactions_1, rawObjValue.total_txs, rawObjValue.page_count);
}
catch (error) {
throw error;
}
};
/**
*
* Creates a JSON object with the QueryBlockTxsResponse properties
* @returns {JSON} - JSON Object.
* @memberof QueryBlockTxsResponse
*/
QueryBlockTxsResponse.prototype.toJSON = function () {
var transactions = [];
this.transactions.forEach(function (tx) {
var transactionsObj = tx.toJSON();
transactions.push(transactionsObj);
});
return {
txs: transactions,
total_count: this.totalCount,
page_count: this.pageCount
};
};
/**
*
* Check if the QueryBlockTxsResponse object is valid
* @returns {boolean} - True or false.
* @memberof QueryBlockTxsResponse
*/
QueryBlockTxsResponse.prototype.isValid = function () {
return true;
};
return QueryBlockTxsResponse;
}());
exports.QueryBlockTxsResponse = QueryBlockTxsResponse;
//# sourceMappingURL=query-block-txs-response.js.map