cosmwasm-stargate: Separate CosmWasmClient.searchTx and .getTx
This commit is contained in:
parent
90f2e765f7
commit
793bd1ba4c
@ -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<IndexedTx | null> {
|
||||
const results = await this.txsQuery(`tx.hash='${id}'`);
|
||||
return results[0] ?? null;
|
||||
}
|
||||
|
||||
public async searchTx(query: SearchTxQuery, filter: SearchTxFilter = {}): Promise<readonly IndexedTx[]> {
|
||||
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}`)
|
||||
|
||||
@ -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"));
|
||||
|
||||
@ -29,6 +29,7 @@ export declare class CosmWasmClient {
|
||||
getSequence(address: string): Promise<SequenceResponse | null>;
|
||||
getBlock(height?: number): Promise<Block>;
|
||||
getBalance(address: string, searchDenom: string): Promise<Coin | null>;
|
||||
getTx(id: string): Promise<IndexedTx | null>;
|
||||
searchTx(query: SearchTxQuery, filter?: SearchTxFilter): Promise<readonly IndexedTx[]>;
|
||||
disconnect(): void;
|
||||
broadcastTx(tx: Uint8Array): Promise<BroadcastTxResponse>;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user