UNPKG

@pokt-network/pocket-js

Version:

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

65 lines 1.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RequestHash = void 0; /** * * * @class RequestHash */ var relay_payload_1 = require("./relay-payload"); var relay_meta_1 = require("./relay-meta"); var RequestHash = /** @class */ (function () { /** * Request Hash. * @constructor * @param {RelayPayload} payload - RelayPayload object. * @param {RelayMeta} meta - RelayMeta object. */ function RequestHash(payload, meta) { this.payload = payload; this.meta = meta; if (!this.isValid()) { throw new TypeError("Invalid RequestHash properties."); } } /** * * Creates a RequestHash object using a JSON string * @param {string} json - JSON string. * @returns {RequestHash} - RequestHash object. * @memberof RequestHash */ RequestHash.fromJSON = function (json) { try { var jsonObject = JSON.parse(json); return new RequestHash(relay_payload_1.RelayPayload.fromJSON(jsonObject.payload), relay_meta_1.RelayMeta.fromJSON(jsonObject.meta)); } catch (error) { throw error; } }; /** * * Creates a JSON object with the RequestHash properties * @returns {JSON} - JSON Object. * @memberof RelayMeta */ RequestHash.prototype.toJSON = function () { return { payload: this.payload.toJSON(), meta: this.meta.toJSON() }; }; /** * * Check if the RequestHash object is valid * @returns {boolean} - True or false. * @memberof RequestHash */ RequestHash.prototype.isValid = function () { return (this.payload.isValid() && this.meta.isValid()); }; return RequestHash; }()); exports.RequestHash = RequestHash; //# sourceMappingURL=request-hash.js.map