UNPKG

@provenanceio/wallet-utils

Version:

Typescript Utilities for Provenance Blockchain Wallet

97 lines (87 loc) 4.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.buildBroadcastTxRequest = void 0; var _service_pb = require("../../../proto/cosmos/tx/v1beta1/service_pb"); var _tx_pb = require("../../../proto/cosmos/tx/v1beta1/tx_pb"); var _buildAuthInfo = require("./buildAuthInfo"); var _buildSignDoc = require("./buildSignDoc"); var _buildSignerInfo = require("./buildSignerInfo"); var _buildTxBody = require("./buildTxBody"); var _utils = require("../../../utils"); /** * Builds the BroadcastTxRequest, the request type for the * Service.BroadcastTxRequest RPC method * @param msgAny any valid Provenance message * @param account the account number sending the message * @param chainId the unique identifier of the chain this transaction targets. * It prevents signed transactions from being used on another chain by an * attacker * @param wallet the signing wallet. Used to identify the private key for * signature * @param feeEstimate the estimated fee * @param memo any arbitrary note/comment to be added to the transaction * @param feeDenom the denom of the fee. Not required * @param gasLimit the maximum gas that can be used in transaction processing * @param feeGranter if set, the fee payer (either the first signer or the value of the payer field) requests that a fee grant be used * to pay fees instead of the fee payer's own balance. If an appropriate fee grant does not exist or the chain does * not support fee grants, this will fail * @param feePayer if unset, the first signer is responsible for paying the fees. If set, the specified account must pay the fees. * The payer must be a tx signer (and thus have signed this field in AuthInfo). * Setting this field does *not* change the ordering of required signers for the transaction * @param timeoutHeight the block height after which this transaction will not * be processed by the chain * @param extensionOptionsList arbitrary options that can be added by chains * when the default options are not sufficient. If any of these are present * and can't be handled, the transaction will be rejected * @param nonCriticalExtensionOptionsList arbitrary options that can be added by chains * when the default options are not sufficient. If any of these are present * and can't be handled, they will be ignored * @returns the BroadCastTxRequest * reference: https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/tx/v1beta1/tx.proto#L13-L26 */ var buildBroadcastTxRequest = function buildBroadcastTxRequest(_ref) { var msgAny = _ref.msgAny, account = _ref.account, chainId = _ref.chainId, wallet = _ref.wallet, feeEstimate = _ref.feeEstimate, _ref$memo = _ref.memo, memo = _ref$memo === void 0 ? '' : _ref$memo, _ref$feeDenom = _ref.feeDenom, feeDenom = _ref$feeDenom === void 0 ? 'nhash' : _ref$feeDenom, gasLimit = _ref.gasLimit, feeGranter = _ref.feeGranter, feePayer = _ref.feePayer, timeoutHeight = _ref.timeoutHeight, extensionOptionsList = _ref.extensionOptionsList, nonCriticalExtensionOptionsList = _ref.nonCriticalExtensionOptionsList; var signerInfo = (0, _buildSignerInfo.buildSignerInfo)(account, wallet.publicKey); var authInfo = (0, _buildAuthInfo.buildAuthInfo)({ signerInfo: signerInfo, feeDenom: feeDenom, feeEstimate: feeEstimate, gasLimit: gasLimit, feeGranter: feeGranter, feePayer: feePayer }); var txBody = (0, _buildTxBody.buildTxBody)({ msgAny: msgAny, memo: memo, timeoutHeight: timeoutHeight, extensionOptionsList: extensionOptionsList, nonCriticalExtensionOptionsList: nonCriticalExtensionOptionsList }); var txRaw = new _tx_pb.TxRaw(); txRaw.setBodyBytes(txBody.serializeBinary()); txRaw.setAuthInfoBytes(authInfo.serializeBinary()); var signDoc = (0, _buildSignDoc.buildSignDoc)(account.getAccountNumber(), chainId, txRaw); var signature = (0, _utils.signBytes)(signDoc.serializeBinary(), wallet.privateKey); txRaw.setSignaturesList([signature]); var txRequest = new _service_pb.BroadcastTxRequest(); txRequest.setTxBytes(txRaw.serializeBinary()); txRequest.setMode(_service_pb.BroadcastMode.BROADCAST_MODE_BLOCK); return txRequest; }; exports.buildBroadcastTxRequest = buildBroadcastTxRequest;