UNPKG

@pokt-network/pocket-js

Version:

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

68 lines 1.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PartSetHeader = void 0; var hex_1 = require("../../utils/hex"); /** * * * @class PartSetHeader */ var PartSetHeader = /** @class */ (function () { /** * PartSetHeader. * @constructor * @param {BigInt} total - Total count. * @param {string} hash - Part hash. */ function PartSetHeader(total, hash) { this.total = total; this.hash = hash; if (!this.isValid()) { throw new TypeError("Invalid PartSetHeader properties."); } } /** * * Creates a PartSetHeader object using a JSON string * @param {String} json - JSON string. * @returns {PartSetHeader} - PartSetHeader object. * @memberof PartSetHeader */ PartSetHeader.fromJSON = function (json) { try { var jsonObject = JSON.parse(json); return new PartSetHeader(BigInt(jsonObject.total), jsonObject.hash); } catch (error) { throw error; } }; /** * * Creates a JSON object with the PartSetHeader properties * @returns {JSON} - JSON Object. * @memberof PartSetHeader */ PartSetHeader.prototype.toJSON = function () { return { hash: this.hash, total: Number(this.total.toString()) }; }; /** * * Check if the PartSetHeader object is valid * @returns {boolean} - True or false. * @memberof PartSetHeader */ PartSetHeader.prototype.isValid = function () { var validHash = true; if (this.hash) { validHash = hex_1.Hex.isHex(this.hash); } return validHash && Number(this.total.toString()) >= 0; }; return PartSetHeader; }()); exports.PartSetHeader = PartSetHeader; //# sourceMappingURL=part-set-header.js.map