@pokt-network/pocket-js
Version:
Pocket-js core package with the main functionalities to interact with the Pocket Network.
68 lines • 2.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConsensusNode = void 0;
/**
*
*
* @class ConsensusNode
*/
var ConsensusNode = /** @class */ (function () {
/**
* Consensus node.
* @constructor
* @param {Node} node - Signature.
* @param {boolean} status - True if the response is accepted or false if not.
* @param {RelayResponse} relayResponse - Relay Response.
*/
function ConsensusNode(node, status, relayResponse) {
this.node = node;
this.status = status;
this.relayResponse = relayResponse;
if (!this.isValid()) {
throw new TypeError("Invalid ConsensusNode properties.");
}
}
/**
*
* Creates a ConsensusNode object using a JSON string
* @param {String} json - JSON string.
* @returns {ConsensusNode} - ConsensusNode object.
* @memberof ConsensusNode
*/
ConsensusNode.fromJSON = function (json) {
try {
var jsonObject = JSON.parse(json);
return new ConsensusNode(jsonObject.node, jsonObject.status, jsonObject.relay_response);
}
catch (error) {
throw error;
}
};
/**
*
* Creates a JSON object with the ConsensusNode properties
* @returns {JSON} - JSON Object.
* @memberof ConsensusNode
*/
ConsensusNode.prototype.toJSON = function () {
return {
node: this.node.toJSON(),
status: this.status,
relay_response: this.relayResponse.toJSON()
};
};
/**
*
* Check if the ConsensusNode object is valid
* @returns {boolean} - True or false.
* @memberof ConsensusNode
*/
ConsensusNode.prototype.isValid = function () {
return (this.node.isValid() &&
this.status !== undefined &&
this.relayResponse.isValid());
};
return ConsensusNode;
}());
exports.ConsensusNode = ConsensusNode;
//# sourceMappingURL=consensus-node.js.map