diff options
author | Florian Dold <florian@dold.me> | 2024-02-27 15:31:01 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2024-02-27 15:31:01 +0100 |
commit | f78d7dc613946b0316a559aa0161dd02b056b05d (patch) | |
tree | bcf37180afbd02d71e4faac896edcd0b18e2f4bb /packages/taler-wallet-core/src/wallet.ts | |
parent | 41f34031ae934e8c802cdbb73fffb5a39c9c6a68 (diff) | |
download | wallet-core-f78d7dc613946b0316a559aa0161dd02b056b05d.tar.gz wallet-core-f78d7dc613946b0316a559aa0161dd02b056b05d.tar.bz2 wallet-core-f78d7dc613946b0316a559aa0161dd02b056b05d.zip |
-move function
Diffstat (limited to 'packages/taler-wallet-core/src/wallet.ts')
-rw-r--r-- | packages/taler-wallet-core/src/wallet.ts | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index f21db0531..79f7a1be5 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -310,6 +310,24 @@ async function fillDefaults(ws: InternalWalletState): Promise<void> { } } +export async function getDenomInfo( + ws: InternalWalletState, + tx: WalletDbReadOnlyTransaction<["denominations"]>, + exchangeBaseUrl: string, + denomPubHash: string, +): Promise<DenominationInfo | undefined> { + const key = `${exchangeBaseUrl}:${denomPubHash}`; + const cached = ws.denomCache[key]; + if (cached) { + return cached; + } + const d = await tx.denominations.get([exchangeBaseUrl, denomPubHash]); + if (d) { + return DenominationRecord.toDenomInfo(d); + } + return undefined; +} + /** * List bank accounts known to the wallet from * previous withdrawals. @@ -440,7 +458,7 @@ async function dumpCoins(ws: InternalWalletState): Promise<CoinDumpJson> { if (cs.type == CoinSourceType.Withdraw) { withdrawalReservePub = cs.reservePub; } - const denomInfo = await ws.getDenomInfo( + const denomInfo = await getDenomInfo( ws, tx, c.exchangeBaseUrl, @@ -1456,7 +1474,7 @@ export class InternalWalletState { initCalled = false; // FIXME: Use an LRU cache here. - private denomCache: Record<string, DenominationInfo> = {}; + denomCache: Record<string, DenominationInfo> = {}; /** * Promises that are waiting for a particular resource. @@ -1517,24 +1535,6 @@ export class InternalWalletState { } } - async getDenomInfo( - ws: InternalWalletState, - tx: WalletDbReadOnlyTransaction<["denominations"]>, - exchangeBaseUrl: string, - denomPubHash: string, - ): Promise<DenominationInfo | undefined> { - const key = `${exchangeBaseUrl}:${denomPubHash}`; - const cached = this.denomCache[key]; - if (cached) { - return cached; - } - const d = await tx.denominations.get([exchangeBaseUrl, denomPubHash]); - if (d) { - return DenominationRecord.toDenomInfo(d); - } - return undefined; - } - notify(n: WalletNotification): void { logger.trace(`Notification: ${j2s(n)}`); for (const l of this.listeners) { |