-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stream transactions in transactions table to avoid blocking loading (#…
…935) * Stream transactions in transactions table to avoid blocking loading * Tweak performance * Remove unneeded loader
- Loading branch information
1 parent
6577184
commit cd6f987
Showing
4 changed files
with
93 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { uint8ArrayToHex } from '@penumbra-zone/types/src/hex'; | ||
import { SliceCreator } from '.'; | ||
import { viewClient } from '../clients'; | ||
import { getTransactionClassificationLabel } from '@penumbra-zone/perspective/transaction/classify'; | ||
|
||
export interface TransactionSummary { | ||
height: number; | ||
hash: string; | ||
description: string; | ||
} | ||
|
||
export interface TransactionsSlice { | ||
summaries: TransactionSummary[]; | ||
loadSummaries: () => Promise<void>; | ||
} | ||
|
||
export const createTransactionsSlice = (): SliceCreator<TransactionsSlice> => (set, get) => ({ | ||
summaries: [], | ||
|
||
loadSummaries: async () => { | ||
set(state => { | ||
state.transactions.summaries = []; | ||
}); | ||
|
||
for await (const tx of viewClient.transactionInfo({})) { | ||
const summary = { | ||
height: Number(tx.txInfo?.height ?? 0n), | ||
hash: tx.txInfo?.id?.inner ? uint8ArrayToHex(tx.txInfo.id.inner) : 'unknown', | ||
description: getTransactionClassificationLabel(tx.txInfo?.view), | ||
}; | ||
|
||
const summaries = [...get().transactions.summaries, summary].sort( | ||
(a, b) => b.height - a.height, | ||
); | ||
|
||
set(state => { | ||
state.transactions.summaries = summaries; | ||
}); | ||
} | ||
}, | ||
}); |