UNPKG

@pokt-network/pocket-js

Version:

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

110 lines 4.11 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.MsgNodeStake = void 0; var belt_1 = require("@tendermint/belt"); var tx_msg_1 = require("./tx-msg"); var utils_1 = require("./../../../utils"); /** * Model representing a MsgNodeStake to stake as an Node in the Pocket Network */ var MsgNodeStake = /** @class */ (function (_super) { __extends(MsgNodeStake, _super); /** * @param {string} pubKey - Public key * @param {string[]} chains - String array containing a list of blockchain hashes * @param {string} amount - Amount to be sent, has to be a valid number and cannot be lesser than 0 * @param {URL} serviceURL - Service node URL, needs to be https:// */ function MsgNodeStake(pubKey, chains, amount, serviceURL) { var _this = _super.call(this) || this; _this.AMINO_KEY = "pos/MsgStake"; _this.DEFAULT_PORT = "443"; _this.DEFAULT_PROTOCOL = "https:"; _this.pubKey = pubKey; _this.chains = chains; _this.amount = amount; _this.serviceURL = serviceURL; if (!!!_this.serviceURL.port) { _this.serviceURL.port = "443"; } var amountNumber = Number(_this.amount) || -1; if (isNaN(amountNumber)) { throw new Error("Amount is not a valid number"); } else if (amountNumber < 0) { throw new Error("Amount < 0"); } else if (_this.chains.length === 0) { throw new Error("Chains is empty"); } else if (!utils_1.validatePublicKey(_this.pubKey)) { throw new Error("Invalid public key"); } else if (!utils_1.validateServiceURL(_this.serviceURL)) { throw new Error("Invalid Service URL"); } return _this; } /** * Returns the parsed serviceURL * @returns {string} - Parsed serviceURL * @memberof MsgNodeStake */ MsgNodeStake.prototype.getParsedServiceURL = function () { return (this.serviceURL.protocol ? this.serviceURL.protocol : this.DEFAULT_PROTOCOL) + "//" + this.serviceURL.hostname + ":" + (this.serviceURL.port ? this.serviceURL.port : this.DEFAULT_PORT); }; /** * Converts an Msg Object to StdSignDoc * @returns {object} - Msg type key value. * @memberof MsgNodeStake */ MsgNodeStake.prototype.toStdSignDocMsgObj = function () { return { type: this.AMINO_KEY, value: { chains: this.chains, public_key: { type: "crypto/ed25519_public_key", value: this.pubKey.toString("hex") }, service_url: this.getParsedServiceURL(), value: this.amount } }; }; /** * Converts an Msg Object to StdSignDoc * @returns {any} - Msg type key value. * @memberof MsgNodeStake */ MsgNodeStake.prototype.toStdTxMsgObj = function () { return { type: this.AMINO_KEY, value: { chains: this.chains, public_key: { type: "crypto/ed25519_public_key", value: belt_1.bytesToBase64(this.pubKey) }, service_url: this.getParsedServiceURL(), value: this.amount } }; }; return MsgNodeStake; }(tx_msg_1.TxMsg)); exports.MsgNodeStake = MsgNodeStake; //# sourceMappingURL=msg-node-stake.js.map