UNPKG

@pokt-network/pocket-js

Version:

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

95 lines 3.51 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.MsgProtoAppStake = void 0; var tx_signer_1 = require("../proto/generated/tx-signer"); var any_1 = require("../proto/generated/google/protobuf/any"); var tx_msg_1 = require("./tx-msg"); var utils_1 = require("./../../../utils"); /** * Model representing a MsgAppStake to stake as an Application in the Pocket Network */ var MsgProtoAppStake = /** @class */ (function (_super) { __extends(MsgProtoAppStake, _super); /** * Constructor for this class * @param {Buffer} pubKey - Public key buffer * @param {string[]} chains - Network identifier list to be requested by this app * @param {string} amount - The amount to stake, must be greater than 0 */ function MsgProtoAppStake(pubKey, chains, amount) { var _this = _super.call(this) || this; _this.KEY = "/x.apps.MsgProtoStake"; _this.AMINO_KEY = "apps/MsgAppStake"; _this.pubKey = pubKey; _this.chains = chains; _this.amount = amount; 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"); } return _this; } /** * Returns the msg type key * @returns {string} - Msg type key value. * @memberof MsgAppStake */ MsgProtoAppStake.prototype.getMsgTypeKey = function () { return this.KEY; }; /** * Converts an Msg Object to StdSignDoc * @returns {object} - Msg type key value. * @memberof MsgAppStake */ MsgProtoAppStake.prototype.toStdSignDocMsgObj = function () { return { type: this.AMINO_KEY, value: { chains: this.chains, pubkey: { type: "crypto/ed25519_public_key", value: this.pubKey.toString("hex") }, value: this.amount } }; }; /** * Converts an Msg Object for StdTx encoding * @returns {any} - Msg type key value. * @memberof MsgAppStake */ MsgProtoAppStake.prototype.toStdTxMsgObj = function () { var data = { pubKey: this.pubKey, chains: this.chains, value: this.amount }; return any_1.Any.fromJSON({ "typeUrl": this.KEY, "value": Buffer.from(tx_signer_1.MsgProtoStake.encode(data).finish()).toString("base64") }); }; return MsgProtoAppStake; }(tx_msg_1.TxMsg)); exports.MsgProtoAppStake = MsgProtoAppStake; //# sourceMappingURL=msg-proto-app-stake.js.map