@pokt-network/pocket-js
Version:
Pocket-js core package with the main functionalities to interact with the Pocket Network.
80 lines • 2.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MsgClaim = void 0;
var input_1 = require("../input");
var evidence_type_1 = require("../evidence-type");
var hex_1 = require("../../../utils/hex");
/**
*
*
* @class MsgClaim
*/
var MsgClaim = /** @class */ (function () {
/**
* Challenge Response.
* @constructor
* @param {string} response - response json.
*/
function MsgClaim(header, merkleRoot, totalProofs, fromAddress, evidenceType, expirationHeight) {
this.header = header;
this.merkleRoot = merkleRoot;
this.totalProofs = totalProofs;
this.fromAddress = fromAddress;
this.evidenceType = evidenceType;
this.expirationHeight = expirationHeight;
if (!this.isValid()) {
throw new TypeError("Invalid MsgClaim properties.");
}
}
/**
*
* Creates a RelayMeta object using a JSON string
* @param {string} json - JSON string.
* @returns {MsgClaim} - MsgClaim object.
* @memberof MsgClaim
*/
MsgClaim.fromJSON = function (json) {
try {
var jsonObject = JSON.parse(json);
var header = input_1.SessionHeader.fromJSON(JSON.stringify(jsonObject.header));
var merkleRoot = { hash: jsonObject.merkle_root.hash, sum: BigInt(jsonObject.merkle_root.sum) };
var evidenceType = evidence_type_1.EvidenceType.getType(jsonObject.evidence_type);
return new MsgClaim(header, merkleRoot, BigInt(jsonObject.total_proofs), jsonObject.from_address, evidenceType, BigInt(jsonObject.expiration_height));
}
catch (error) {
throw error;
}
};
/**
*
* Creates a JSON object with the MsgClaim properties
* @returns {JSON} - JSON Object.
* @memberof MsgClaim
*/
MsgClaim.prototype.toJSON = function () {
return {
header: this.header.toJSON(),
merkle_root: this.merkleRoot,
total_proofs: Number(this.totalProofs.toString()),
from_address: this.fromAddress,
evidence_type: this.evidenceType,
expiration_height: Number(this.expirationHeight.toString()),
};
};
/**
*
* Check if the MsgClaim object is valid
* @returns {boolean} - True or false.
* @memberof MsgClaim
*/
MsgClaim.prototype.isValid = function () {
return (this.header.isValid() &&
this.merkleRoot.hash.length > 0 &&
Number(this.merkleRoot.sum.toString()) >= 0 &&
hex_1.Hex.validateAddress(this.fromAddress) &&
Number(this.expirationHeight.toString()) >= 0);
};
return MsgClaim;
}());
exports.MsgClaim = MsgClaim;
//# sourceMappingURL=msg-claim.js.map