Avoid throwing error when transaction ID does not exist

Before we got "Error: Tx: RPC error -32603 - Internal error: tx
(0000000000000000000000000000000000000000000000000000000000000000) not
found"
This commit is contained in:
Simon Warta 2020-02-12 16:06:46 +01:00
parent 297910039a
commit fd725998c6
2 changed files with 9 additions and 1 deletions

View File

@ -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()");

View File

@ -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)) {