UNPKG

@pokt-network/pocket-js

Version:

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

72 lines 2.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MajorityResponse = void 0; /** * @class MajorityResponse */ var validator_1 = require("../../../utils/validator"); var utils_1 = require("../../../utils"); var output_1 = require("../output"); var MajorityResponse = /** @class */ (function () { /** * Majority Response. * @constructor * @param {RelayResponse[]} relays - Array of relay response. */ function MajorityResponse(relays) { this.relays = relays; var valid = this.isValid(); if (utils_1.typeGuard(valid, Error)) { throw valid; } } /** * * Creates a MajorityResponse object using a JSON string * @param {String} json - JSON string. * @returns {MajorityResponse} - MajorityResponse object. * @memberof MajorityResponse */ MajorityResponse.fromJSON = function (json) { try { var jsonObject = JSON.parse(json); var relays_1 = new Array(2); if (Array.isArray(jsonObject.majority_responses)) { jsonObject.majority_responses.forEach(function (relay) { if (relay !== null) { var newRelay = output_1.RelayResponse.fromJSON(JSON.stringify(relay)); relays_1.push(newRelay); } }); } return new MajorityResponse(relays_1); } catch (error) { throw error; } }; /** * * Creates a JSON object with the MajorityResponse properties * @returns {JSON} - JSON Object. * @memberof MajorityResponse */ MajorityResponse.prototype.toJSON = function () { return this.relays; }; /** * * Check if the MajorityResponse object is valid * @returns {boolean} - True or false. * @memberof MajorityResponse */ MajorityResponse.prototype.isValid = function () { if (validator_1.validateMajorityResponse(this) === undefined) { return true; } return false; }; return MajorityResponse; }()); exports.MajorityResponse = MajorityResponse; //# sourceMappingURL=majority-response.js.map