UNPKG

@pokt-network/pocket-js

Version:

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

128 lines (127 loc) 6.71 kB
import { TxMsg, CoinDenom, TxSignature } from "./models/"; import { ITransactionSender, TransactionSigner } from "./index"; import { UnlockedAccount } from "../keybase/models"; import { Pocket, RawTxResponse, RpcError, RawTxRequest } from ".."; export declare class TransactionSender implements ITransactionSender { txMsg?: TxMsg; private unlockedAccount?; private pocket; private txSigner?; private txMsgError?; offlineMode?: boolean; /** * Constructor for this class. Requires either an unlockedAccount or txSigner * @param {Pocket} pocket - Pocket instance * @param {UnlockedAccount} unlockedAccount - Unlocked account * @param {TransactionSigner} txSigner - Transaction signer */ constructor(pocket: Pocket, unlockedAccount?: UnlockedAccount, txSigner?: TransactionSigner, offlineMode?: boolean); /** * Signs and creates a transaction object that can be submitted to the network given the parameters and called upon Msgs. * Will empty the msg list after succesful creation * @param {string} chainID - The chainID of the network to be sent to * @param {string} fee - The amount to pay as a fee for executing this transaction * @param {CoinDenom | undefined} feeDenom - The denomination of the fee amount * @param {string | undefined} memo - The memo field for this account * @returns {Promise<RawTxResponse | RpcError>} - A Raw transaction Response object or Rpc error. * @memberof TransactionSender */ createTransaction(chainID: string, fee: string, feeDenom?: CoinDenom, memo?: string, signature?: TxSignature): Promise<RawTxRequest | RpcError>; /** * Creates an unsigned transaction hex that can be signed with a valid ed25519 private key * @param {string} chainID - The chainID of the network to be sent to * @param {string} fee - The amount to pay as a fee for executing this transaction * @param {CoinDenom | undefined} feeDenom - The denomination of the fee amount * @param {string | undefined} memo - The memo field for this account * @param {string} entropy - The entropy for this tx * @returns {Promise<{ bytesToSign: string, stdTxMsgObj: string } | RpcError>} - bytes to sign and the stringified stxTxMsgObj * @memberof TransactionSender */ createUnsignedTransaction(chainID: string, fee: string, entropy: string, feeDenom?: CoinDenom, memo?: string): { bytesToSign: string; stdTxMsgObj: string; } | RpcError; /** * Signs and submits a transaction to the network given the parameters for each Msg in the Msg list. Will empty the msg list after submission attempt * @param {string} chainID - The chainID of the network to be sent to * @param {string} fee - The amount to pay as a fee for executing this transaction * @param {CoinDenom | undefined} feeDenom - The denomination of the fee amount * @param {string | undefined} memo - The memo field for this account * @param {number | undefined} timeout - Request timeout * @returns {Promise<RawTxResponse | RpcError>} - A Raw transaction Response object or Rpc error. * @memberof TransactionSender */ submit(chainID: string, fee: string, feeDenom?: CoinDenom, memo?: string, timeout?: number): Promise<RawTxResponse | RpcError>; /** * Adds a MsgSend TxMsg for this transaction * @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 * @returns {ITransactionSender} - A transaction sender. * @memberof TransactionSender */ send(fromAddress: string, toAddress: string, amount: string): ITransactionSender; /** * Adds a MsgAppStake TxMsg for this transaction * @param {string} appPubKey - Application Public Key * @param {string[]} chains - Network identifier list to be requested by this app * @param {string} amount - the amount to stake, must be greater than 0 * @returns {ITransactionSender} - A transaction sender. * @memberof TransactionSender */ appStake(appPubKey: string, chains: string[], amount: string): ITransactionSender; /** * Adds a MsgBeginAppUnstake TxMsg for this transaction * @param {string} address - Address of the Application to unstake for * @returns {ITransactionSender} - A transaction sender. * @memberof TransactionSender */ appUnstake(address: string): ITransactionSender; /** * Adds a MsgAppUnjail TxMsg for this transaction * @param {string} address - Address of the Application to unjail * @returns {ITransactionSender} - A transaction sender. * @memberof TransactionSender */ appUnjail(address: string): ITransactionSender; /** * Adds a MsgAppStake TxMsg for this transaction * @param {string} nodePubKey - Node Public key * @param {string[]} chains - Network identifier list to be serviced by this node * @param {string} amount - the amount to stake, must be greater than 0 * @param {URL} serviceURL - Node service url * @returns {ITransactionSender} - A transaction sender. * @memberof TransactionSender */ nodeStake(nodePubKey: string, outputAddress: string, chains: string[], amount: string, serviceURL: URL): ITransactionSender; /** * Adds a MsgBeginUnstake TxMsg for this transaction * @param {string} address - Address of the Node to unstake for * @returns {ITransactionSender} - A transaction sender. * @memberof TransactionSender */ nodeUnstake(nodeAddress: string, signerAddress: string): ITransactionSender; /** * Adds a MsgUnjail TxMsg for this transaction * @param {string} nodeAddress - Address of the Node to unjail * @returns {ITransactionSender} - A transaction sender. * @memberof TransactionSender */ nodeUnjail(nodeAddress: string, signerAddress: string): ITransactionSender; /** * Signs using the unlockedAccount attribute of this class * @param {Buffer} bytesToSign - Bytes to be signed * @param {UnlockedAccount} unlockedAccount - Unlocked account for signing * @returns {TxSignature | Error} - A transaction signature or error. * @memberof TransactionSender */ private signWithUnlockedAccount; /** * Signs using the txSigner attribute of this class * @param {Buffer} bytesToSign - Bytes to sign * @param {TransactionSigner} txSigner - Transaction signer * @returns {TxSignature | Error} - A transaction signature or error. * @memberof TransactionSender */ private signWithTrasactionSigner; }