From 793bd1ba4c054ccb0dccf36ca66aa62894d86753 Mon Sep 17 00:00:00 2001 From: willclarktech Date: Tue, 15 Dec 2020 14:12:14 +0000 Subject: [PATCH] cosmwasm-stargate: Separate CosmWasmClient.searchTx and .getTx --- packages/cosmwasm-stargate/src/cosmwasmclient.ts | 10 ++++++---- .../src/signingcosmwasmclient.spec.ts | 10 ++++++---- packages/cosmwasm-stargate/types/cosmwasmclient.d.ts | 1 + 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/cosmwasm-stargate/src/cosmwasmclient.ts b/packages/cosmwasm-stargate/src/cosmwasmclient.ts index 902f40d4..0d36eff7 100644 --- a/packages/cosmwasm-stargate/src/cosmwasmclient.ts +++ b/packages/cosmwasm-stargate/src/cosmwasmclient.ts @@ -5,7 +5,6 @@ import { Block, Coin, isSearchByHeightQuery, - isSearchByIdQuery, isSearchBySentFromOrToQuery, isSearchByTagsQuery, SearchTxFilter, @@ -126,6 +125,11 @@ export class CosmWasmClient { return balance ? coinFromProto(balance) : null; } + public async getTx(id: string): Promise { + const results = await this.txsQuery(`tx.hash='${id}'`); + return results[0] ?? null; + } + public async searchTx(query: SearchTxQuery, filter: SearchTxFilter = {}): Promise { const minHeight = filter.minHeight || 0; const maxHeight = filter.maxHeight || Number.MAX_SAFE_INTEGER; @@ -134,9 +138,7 @@ export class CosmWasmClient { let txs: readonly IndexedTx[]; - if (isSearchByIdQuery(query)) { - txs = await this.txsQuery(`tx.hash='${query.id}'`); - } else if (isSearchByHeightQuery(query)) { + if (isSearchByHeightQuery(query)) { txs = query.height >= minHeight && query.height <= maxHeight ? await this.txsQuery(`tx.height=${query.height}`) diff --git a/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts b/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts index 7f21df86..2bc3b8ce 100644 --- a/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts +++ b/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts @@ -495,8 +495,9 @@ describe("SigningCosmWasmClient", () => { await sleep(1000); - const searchResult = await client.searchTx({ id: result.transactionHash }); - const tx = Tx.decode(searchResult[0].tx); + const searchResult = await client.getTx(result.transactionHash); + assert(searchResult, "Must find transaction"); + const tx = Tx.decode(searchResult.tx); // From ModifyingDirectSecp256k1HdWallet expect(tx.body!.memo).toEqual("This was modified"); expect({ ...tx.authInfo!.fee!.amount![0] }).toEqual(coin(3000, "ucosm")); @@ -571,8 +572,9 @@ describe("SigningCosmWasmClient", () => { await sleep(1000); - const searchResult = await client.searchTx({ id: result.transactionHash }); - const tx = Tx.decode(searchResult[0].tx); + const searchResult = await client.getTx(result.transactionHash); + assert(searchResult, "Must find transaction"); + const tx = Tx.decode(searchResult.tx); // From ModifyingSecp256k1HdWallet expect(tx.body!.memo).toEqual("This was modified"); expect({ ...tx.authInfo!.fee!.amount![0] }).toEqual(coin(3000, "ucosm")); diff --git a/packages/cosmwasm-stargate/types/cosmwasmclient.d.ts b/packages/cosmwasm-stargate/types/cosmwasmclient.d.ts index 9630ed1c..60f63c08 100644 --- a/packages/cosmwasm-stargate/types/cosmwasmclient.d.ts +++ b/packages/cosmwasm-stargate/types/cosmwasmclient.d.ts @@ -29,6 +29,7 @@ export declare class CosmWasmClient { getSequence(address: string): Promise; getBlock(height?: number): Promise; getBalance(address: string, searchDenom: string): Promise; + getTx(id: string): Promise; searchTx(query: SearchTxQuery, filter?: SearchTxFilter): Promise; disconnect(): void; broadcastTx(tx: Uint8Array): Promise;