From 523280b3862b528512ff93c651bc0d9ed632fbf6 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 27 Feb 2024 17:39:58 +0100 Subject: wallet-core: thread through wallet execution context --- packages/taler-wallet-core/src/balance.ts | 32 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'packages/taler-wallet-core/src/balance.ts') diff --git a/packages/taler-wallet-core/src/balance.ts b/packages/taler-wallet-core/src/balance.ts index a287748f1..3b53699ac 100644 --- a/packages/taler-wallet-core/src/balance.ts +++ b/packages/taler-wallet-core/src/balance.ts @@ -80,7 +80,7 @@ import { getExchangeScopeInfo, getExchangeWireDetailsInTx, } from "./exchanges.js"; -import { InternalWalletState } from "./wallet.js"; +import { InternalWalletState, WalletExecutionContext } from "./wallet.js"; /** * Logger. @@ -131,7 +131,7 @@ class BalancesStore { private balanceStore: Record = {}; constructor( - private ws: InternalWalletState, + private wex: WalletExecutionContext, private tx: WalletDbReadOnlyTransaction< [ "globalCurrencyAuditors", @@ -281,7 +281,7 @@ class BalancesStore { * Get balance information. */ export async function getBalancesInsideTransaction( - ws: InternalWalletState, + wex: WalletExecutionContext, tx: WalletDbReadOnlyTransaction< [ "exchanges", @@ -295,7 +295,7 @@ export async function getBalancesInsideTransaction( ] >, ): Promise { - const balanceStore: BalancesStore = new BalancesStore(ws, tx); + const balanceStore: BalancesStore = new BalancesStore(wex, tx); const keyRangeActive = GlobalIDB.KeyRange.bound( OPERATION_STATUS_ACTIVE_FIRST, @@ -428,11 +428,11 @@ export async function getBalancesInsideTransaction( * Get detailed balance information, sliced by exchange and by currency. */ export async function getBalances( - ws: InternalWalletState, + wex: WalletExecutionContext, ): Promise { logger.trace("starting to compute balance"); - const wbal = await ws.db.runReadWriteTx( + const wbal = await wex.db.runReadWriteTx( [ "coinAvailability", "coins", @@ -446,7 +446,7 @@ export async function getBalances( "withdrawalGroups", ], async (tx) => { - return getBalancesInsideTransaction(ws, tx); + return getBalancesInsideTransaction(wex, tx); }, ); @@ -488,12 +488,12 @@ export interface AcceptableExchanges { * Get all exchanges that are acceptable for a particular payment. */ export async function getAcceptableExchangeBaseUrls( - ws: InternalWalletState, + wex: WalletExecutionContext, req: MerchantPaymentRestrictionsForBalance, ): Promise { const acceptableExchangeUrls = new Set(); const depositableExchangeUrls = new Set(); - await ws.db.runReadOnlyTx(["exchanges", "exchangeDetails"], async (tx) => { + await wex.db.runReadOnlyTx(["exchanges", "exchangeDetails"], async (tx) => { // FIXME: We should have a DB index to look up all exchanges // for a particular auditor ... @@ -600,10 +600,10 @@ export interface MerchantPaymentBalanceDetails { } export async function getMerchantPaymentBalanceDetails( - ws: InternalWalletState, + wex: WalletExecutionContext, req: MerchantPaymentRestrictionsForBalance, ): Promise { - const acceptability = await getAcceptableExchangeBaseUrls(ws, req); + const acceptability = await getAcceptableExchangeBaseUrls(wex, req); const d: MerchantPaymentBalanceDetails = { balanceAvailable: Amounts.zeroOfCurrency(req.currency), @@ -613,7 +613,7 @@ export async function getMerchantPaymentBalanceDetails( balanceMerchantDepositable: Amounts.zeroOfCurrency(req.currency), }; - await ws.db.runReadOnlyTx( + await wex.db.runReadOnlyTx( ["coinAvailability", "refreshGroups"], async (tx) => { await tx.coinAvailability.iter().forEach((ca) => { @@ -665,12 +665,12 @@ export async function getMerchantPaymentBalanceDetails( } export async function getBalanceDetail( - ws: InternalWalletState, + wex: WalletExecutionContext, req: GetBalanceDetailRequest, ): Promise { const exchanges: { exchangeBaseUrl: string; exchangePub: string }[] = []; const wires = new Array(); - await ws.db.runReadOnlyTx(["exchanges", "exchangeDetails"], async (tx) => { + await wex.db.runReadOnlyTx(["exchanges", "exchangeDetails"], async (tx) => { const allExchanges = await tx.exchanges.iter().toArray(); for (const e of allExchanges) { const details = await getExchangeWireDetailsInTx(tx, e.baseUrl); @@ -690,7 +690,7 @@ export async function getBalanceDetail( } }); - return await getMerchantPaymentBalanceDetails(ws, { + return await getMerchantPaymentBalanceDetails(wex, { currency: req.currency, acceptedAuditors: [], acceptedExchanges: exchanges, @@ -717,7 +717,7 @@ export interface PeerPaymentBalanceDetails { } export async function getPeerPaymentBalanceDetailsInTx( - ws: InternalWalletState, + wex: WalletExecutionContext, tx: WalletDbReadOnlyTransaction<["coinAvailability", "refreshGroups"]>, req: PeerPaymentRestrictionsForBalance, ): Promise { -- cgit v1.2.3