@pokt-network/pocket-js
Version:
Pocket-js core package with the main functionalities to interact with the Pocket Network.
100 lines • 3.74 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Application = void 0;
var __1 = require("../..");
var staking_status_1 = require("./staking-status");
/**
*
*
* @class Application
*/
var Application = /** @class */ (function () {
/**
* Creates a Application.
* @constructor
* @param {string} address - The hex address of the application
* @param {string} publicKey - The hex consensus public key of the application.
* @param {boolean} jailed - Has the application been jailed from staked status?
* @param {StakingStatus} status - Application staking status
* @param {string[]} chains - An array of blockchains
* @param {BigInt} stakedTokens - How many staked tokens
* @param {BigInt} maxRelays - Max amount of relays.
* @param {string} unstakingCompletionTime - If unstaking, min time for the application to complete unstaking
*/
function Application(address, publicKey, jailed, status, chains, stakedTokens, maxRelays, unstakingCompletionTime) {
if (chains === void 0) { chains = []; }
if (unstakingCompletionTime === void 0) { unstakingCompletionTime = ""; }
this.address = address;
this.publicKey = publicKey;
this.jailed = jailed;
this.status = status;
this.chains = chains;
this.stakedTokens = stakedTokens;
this.maxRelays = maxRelays;
this.unstakingCompletionTime = unstakingCompletionTime;
if (!this.isValid()) {
throw new TypeError("Invalid Application properties.");
}
}
/**
*
* Creates a Application object using a JSON string
* @param {String} json - JSON string.
* @returns {Application} - Application object.
* @memberof Application
*/
Application.fromJSON = function (json) {
try {
var jsonObject = JSON.parse(json);
var status_1 = staking_status_1.StakingStatus.getStatus(jsonObject.status);
return new Application(jsonObject.address, jsonObject.public_key, jsonObject.jailed, status_1, jsonObject.chains, BigInt(jsonObject.staked_tokens), BigInt(jsonObject.max_relays), jsonObject.unstaking_time);
}
catch (error) {
throw error;
}
};
/**
*
* Creates a JSON object with the Application properties
* @returns {JSON} - JSON Object.
* @memberof Application
*/
Application.prototype.toJSON = function () {
return {
address: this.address,
chains: this.chains,
public_key: this.publicKey,
jailed: this.jailed,
max_relays: Number(this.maxRelays.toString()),
status: this.status,
staked_tokens: Number(this.stakedTokens.toString()),
unstaking_time: this.unstakingCompletionTime
};
};
/**
*
* Verify if all properties are valid
* @returns {boolean} - True or false.
* @memberof Application
*/
Application.prototype.isValid = function () {
var validAddress = true;
var validPubKey = true;
if (this.address) {
validAddress = __1.Hex.validateAddress(this.address);
}
if (this.publicKey) {
validPubKey = __1.Hex.validatePublicKey(this.publicKey);
}
return validAddress &&
this.chains.length > 0 &&
validPubKey &&
this.jailed !== undefined &&
Number(this.maxRelays.toString()) >= 0 &&
this.status !== undefined &&
Number(this.stakedTokens.toString()) >= 0;
};
return Application;
}());
exports.Application = Application;
//# sourceMappingURL=application.js.map