UNPKG

@pokt-network/pocket-js

Version:

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

82 lines 3.18 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.MsgProtoSend = 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"); /** * Model representing a MsgSend to send POKT from one account to another */ var MsgProtoSend = /** @class */ (function (_super) { __extends(MsgProtoSend, _super); /** * Constructor this message * @param {string} fromAddress - Origin address * @param {string} toAddress - Destination address * @param {string} amount - Amount to be sent, needs to be a valid number greater than 0 * @param {CoinDenom | undefined} amountDenom - Amount value denomination */ function MsgProtoSend(fromAddress, toAddress, amount) { var _this = _super.call(this) || this; _this.KEY = "/x.nodes.MsgSend"; _this.AMINO_KEY = "pos/Send"; _this.fromAddress = fromAddress; _this.toAddress = toAddress; _this.amount = amount; var amountNumber = Number(_this.amount) || -1; if (isNaN(amountNumber)) { throw new Error("Fee is not a valid number"); } else if (amountNumber < 0) { throw new Error("Amount < 0"); } return _this; } /** * Converts an Msg Object to StdSignDoc * @returns {object} - Msg type key value. * @memberof MsgSend */ MsgProtoSend.prototype.toStdSignDocMsgObj = function () { return { type: this.AMINO_KEY, value: { amount: this.amount, from_address: this.fromAddress.toLowerCase(), to_address: this.toAddress.toLowerCase() } }; }; /** * Converts an Msg Object to StdSignDoc * @returns {any} - Msg type key value. * @memberof MsgSend */ MsgProtoSend.prototype.toStdTxMsgObj = function () { var data = { FromAddress: Buffer.from(this.fromAddress, "hex"), ToAddress: Buffer.from(this.toAddress, "hex"), amount: this.amount }; var result = any_1.Any.fromJSON({ "typeUrl": this.KEY, "value": Buffer.from(tx_signer_1.MsgSend.encode(data).finish()).toString("base64") }); return result; }; MsgProtoSend.decodeStdTxMsgValue = function (value) { return tx_signer_1.MsgSend.decode(Buffer.from(value, 'base64')); }; return MsgProtoSend; }(tx_msg_1.TxMsg)); exports.MsgProtoSend = MsgProtoSend; //# sourceMappingURL=msg-proto-send.js.map