From a0ea2ab353c1d2f59b068811401ab3ba89fb8d3d Mon Sep 17 00:00:00 2001 From: Milos Zivkovic Date: Wed, 6 Sep 2023 14:10:35 +0200 Subject: [PATCH] Update the Wallet API to support custom send transaction endpoints --- package.json | 2 +- src/wallet/wallet.ts | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 8f14640..6a9912f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gnolang/tm2-js-client", - "version": "1.0.5", + "version": "1.0.6", "description": "Tendermint2 JS / TS Client", "main": "./bin/index.js", "repository": { diff --git a/src/wallet/wallet.ts b/src/wallet/wallet.ts index 73f6ae9..cb2151b 100644 --- a/src/wallet/wallet.ts +++ b/src/wallet/wallet.ts @@ -1,4 +1,9 @@ -import { Provider, Status, uint8ArrayToBase64 } from '../provider'; +import { + Provider, + Status, + TransactionEndpoint, + uint8ArrayToBase64, +} from '../provider'; import { Signer } from './signer'; import { LedgerSigner } from './ledger'; import { KeySigner } from './key'; @@ -296,8 +301,15 @@ export class Wallet { * The transaction needs to be signed beforehand. * Returns the transaction hash (base-64) * @param {Tx} tx the signed transaction + * @param {TransactionEndpoint} endpoint the transaction broadcast type (sync / commit). + * Defaults to broadcast_sync */ - sendTransaction = async (tx: Tx): Promise => { + sendTransaction = async ( + tx: Tx, + endpoint?: + | TransactionEndpoint.BROADCAST_TX_SYNC + | TransactionEndpoint.BROADCAST_TX_COMMIT + ): Promise => { if (!this.provider) { throw new Error('provider not connected'); } @@ -306,7 +318,7 @@ export class Wallet { const encodedTx: string = uint8ArrayToBase64(Tx.encode(tx).finish()); // Send the encoded transaction - return this.provider.sendTransaction(encodedTx); + return this.provider.sendTransaction(encodedTx, endpoint); }; /**