@pokt-network/pocket-js
Version:
Pocket-js core package with the main functionalities to interact with the Pocket Network.
68 lines • 2.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.QueryBlockResponse = void 0;
var block_meta_1 = require("../block-meta");
var block_1 = require("../block");
/**
*
*
* @class QueryBlockResponse
*/
var QueryBlockResponse = /** @class */ (function () {
/**
* Query Block Response.
* @constructor
* @param {Block} block - Block object.
*/
function QueryBlockResponse(blockMeta, block) {
this.blockMeta = blockMeta;
this.block = block;
if (!this.isValid()) {
throw new TypeError("Invalid QueryBlockResponse properties.");
}
}
/**
*
* Creates a QueryBlockResponse object using a JSON string
* @param {String} json - JSON string.
* @returns {QueryBlockResponse} - QueryBlockResponse object.
* @memberof QueryBlockResponse
*/
QueryBlockResponse.fromJSON = function (json) {
try {
var jsonObject = JSON.parse(json);
var blockMeta = jsonObject.block_meta !== undefined ? jsonObject.block_meta : {
block_id: jsonObject.block_id,
header: jsonObject.block.header
};
return new QueryBlockResponse(block_meta_1.BlockMeta.fromJSON(JSON.stringify(blockMeta)), block_1.Block.fromJSON(JSON.stringify(jsonObject.block)));
}
catch (error) {
throw error;
}
};
/**
*
* Creates a JSON object with the QueryBlockResponse properties
* @returns {JSON} - JSON Object.
* @memberof QueryBlockResponse
*/
QueryBlockResponse.prototype.toJSON = function () {
return {
"block": this.block.toJSON(),
"block_meta": this.blockMeta.toJSON()
};
};
/**
*
* Check if the QueryBlockResponse object is valid
* @returns {boolean} - True or false.
* @memberof QueryBlockResponse
*/
QueryBlockResponse.prototype.isValid = function () {
return this.block.isValid() && this.blockMeta.isValid();
};
return QueryBlockResponse;
}());
exports.QueryBlockResponse = QueryBlockResponse;
//# sourceMappingURL=query-block-response.js.map