@pokt-network/pocket-js
Version:
Pocket-js core package with the main functionalities to interact with the Pocket Network.
83 lines • 2.88 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NodeReceipt = void 0;
var utils_1 = require("../../../utils");
/**
*
*
* @class NodeReceipt
*/
var NodeReceipt = /** @class */ (function () {
/**
* Node Receipt.
* @constructor
* @param {string} address - Node address.
* @param {string} blockchain - Blockchain hash.
* @param {string} appPubKey - Application Key associated with a client.
* @param {BigInt} sessionBlockHeight - Session Block Height.
* @param {BigInt} height - Current height.
* @param {string} receiptType - Receipt type.
*/
function NodeReceipt(address, blockchain, appPubKey, sessionBlockHeight, height, receiptType) {
this.address = address;
this.blockchain = blockchain;
this.appPubKey = appPubKey;
this.sessionBlockHeight = sessionBlockHeight;
this.height = height;
this.receiptType = receiptType;
if (!this.isValid()) {
throw new TypeError("Invalid NodeReceipt properties.");
}
}
/**
*
* Creates a NodeReceipt object using a JSON string
* @param {String} json - JSON string.
* @returns {NodeReceipt} - NodeReceipt object.
* @memberof NodeReceipt
*/
NodeReceipt.fromJSON = function (json) {
try {
var jsonObject = JSON.parse(json);
return new NodeReceipt(jsonObject.address, jsonObject.blockchain, jsonObject.app_pubkey, BigInt(jsonObject.session_block_height), BigInt(jsonObject.height), jsonObject.evidence_type);
}
catch (error) {
throw error;
}
};
/**
*
* Creates a JSON object with the NodeReceipt properties
* @returns {JSON} - JSON Object.
* @memberof NodeReceipt
*/
NodeReceipt.prototype.toJSON = function () {
return {
address: this.address,
app_pubkey: this.appPubKey,
blockchain: this.blockchain,
height: Number(this.height.toString()),
session_block_height: Number(this.sessionBlockHeight.toString()),
receipt_type: this.receiptType
};
};
/**
*
* Check if the NodeReceipt object is valid
* @returns {boolean} - True or false.
* @memberof NodeReceipt
*/
NodeReceipt.prototype.isValid = function () {
return (utils_1.Hex.isHex(this.address) &&
utils_1.Hex.byteLength(this.address) === 20 &&
this.blockchain.length !== 0 &&
utils_1.Hex.isHex(this.appPubKey) &&
utils_1.Hex.byteLength(this.appPubKey) === 32 &&
this.sessionBlockHeight !== undefined &&
this.height !== undefined &&
this.receiptType.length > 0);
};
return NodeReceipt;
}());
exports.NodeReceipt = NodeReceipt;
//# sourceMappingURL=node-receipt.js.map