mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 21:49:15 +00:00
Improve cosmwasm searchTx by sentFromOrTo
This commit is contained in:
parent
0c6410612c
commit
aff82e1f40
@ -286,11 +286,26 @@ export class CosmWasmClient {
|
||||
// We cannot get both in one request (see https://github.com/cosmos/gaia/issues/75)
|
||||
const sentQuery = withFilters(`message.module=bank&message.sender=${query.sentFromOrTo}`);
|
||||
const receivedQuery = withFilters(`message.module=bank&transfer.recipient=${query.sentFromOrTo}`);
|
||||
const sent = await this.txsQuery(sentQuery);
|
||||
const received = await this.txsQuery(receivedQuery);
|
||||
const [sent, received] = (await Promise.all([
|
||||
this.txsQuery(sentQuery),
|
||||
this.txsQuery(receivedQuery),
|
||||
])) as [IndexedTx[], IndexedTx[]];
|
||||
|
||||
const sentHashes = sent.map((t) => t.hash);
|
||||
txs = [...sent, ...received.filter((t) => !sentHashes.includes(t.hash))];
|
||||
txs = [];
|
||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
||||
// sent/received are presorted
|
||||
while (sent.length && received.length) {
|
||||
const next =
|
||||
sent[0].hash === received[0].hash
|
||||
? sent.shift()! && received.shift()!
|
||||
: sent[0].height <= received[0].height
|
||||
? sent.shift()!
|
||||
: received.shift()!;
|
||||
txs = [...txs, next];
|
||||
}
|
||||
/* eslint-enable @typescript-eslint/no-non-null-assertion */
|
||||
// At least one of sent/received is empty by now
|
||||
txs = [...txs, ...sent, ...received];
|
||||
} else if (isSearchByTagsQuery(query)) {
|
||||
const rawQuery = withFilters(query.tags.map((t) => `${t.key}=${t.value}`).join("&"));
|
||||
txs = await this.txsQuery(rawQuery);
|
||||
|
Loading…
x
Reference in New Issue
Block a user