From fd725998c6b264e9f2b58a3811d88dba42773b43 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 12 Feb 2020 16:06:46 +0100 Subject: [PATCH] Avoid throwing error when transaction ID does not exist Before we got "Error: Tx: RPC error -32603 - Internal error: tx (0000000000000000000000000000000000000000000000000000000000000000) not found" --- packages/sdk/src/cosmwasmclient.spec.ts | 8 ++++++++ packages/sdk/src/cosmwasmclient.ts | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/sdk/src/cosmwasmclient.spec.ts b/packages/sdk/src/cosmwasmclient.spec.ts index 69cb70b4..5862ae17 100644 --- a/packages/sdk/src/cosmwasmclient.spec.ts +++ b/packages/sdk/src/cosmwasmclient.spec.ts @@ -202,6 +202,14 @@ describe("CosmWasmClient", () => { ); }); + it("can search by ID (non existent)", async () => { + pendingWithoutCosmos(); + const client = CosmWasmClient.makeReadOnly(httpUrl); + const nonExistentId = "0000000000000000000000000000000000000000000000000000000000000000"; + const result = await client.searchTx({ id: nonExistentId }); + expect(result.length).toEqual(0); + }); + it("can search by height", async () => { pendingWithoutCosmos(); assert(posted, "value must be set in beforeAll()"); diff --git a/packages/sdk/src/cosmwasmclient.ts b/packages/sdk/src/cosmwasmclient.ts index 130f8949..c94232fd 100644 --- a/packages/sdk/src/cosmwasmclient.ts +++ b/packages/sdk/src/cosmwasmclient.ts @@ -164,7 +164,7 @@ export class CosmWasmClient { } if (isSearchByIdQuery(query)) { - return [await this.restClient.txsById(query.id)]; + return (await this.restClient.txs(`tx.hash=${query.id}`)).txs; } else if (isSearchByHeightQuery(query)) { return (await this.restClient.txs(`tx.height=${query.height}`)).txs; } else if (isSearchBySentFromOrToQuery(query)) {