From 1edc144b3595ae1ab6b8af7a43d26b811b2c2623 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 23 Apr 2024 03:09:40 +0200 Subject: wallet-core: pass options object to all transactions --- packages/taler-wallet-core/src/recoup.ts | 81 ++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 35 deletions(-) (limited to 'packages/taler-wallet-core/src/recoup.ts') diff --git a/packages/taler-wallet-core/src/recoup.ts b/packages/taler-wallet-core/src/recoup.ts index 758ba106d..6a09f9a0e 100644 --- a/packages/taler-wallet-core/src/recoup.ts +++ b/packages/taler-wallet-core/src/recoup.ts @@ -99,7 +99,7 @@ async function recoupRewardCoin( // Thus we just put the coin to sleep. // FIXME: somehow report this to the user await wex.db.runReadWriteTx( - ["recoupGroups", "denominations", "refreshGroups", "coins"], + { storeNames: ["recoupGroups", "denominations", "refreshGroups", "coins"] }, async (tx) => { const recoupGroup = await tx.recoupGroups.get(recoupGroupId); if (!recoupGroup) { @@ -121,7 +121,7 @@ async function recoupRefreshCoin( cs: RefreshCoinSource, ): Promise { const d = await wex.db.runReadOnlyTx( - ["coins", "denominations"], + { storeNames: ["coins", "denominations"] }, async (tx) => { const denomInfo = await getDenomInfo( wex, @@ -168,7 +168,7 @@ async function recoupRefreshCoin( } await wex.db.runReadWriteTx( - ["coins", "denominations", "recoupGroups", "refreshGroups"], + { storeNames: ["coins", "denominations", "recoupGroups", "refreshGroups"] }, async (tx) => { const recoupGroup = await tx.recoupGroups.get(recoupGroupId); if (!recoupGroup) { @@ -233,7 +233,7 @@ export async function recoupWithdrawCoin( ): Promise { const reservePub = cs.reservePub; const denomInfo = await wex.db.runReadOnlyTx( - ["denominations"], + { storeNames: ["denominations"] }, async (tx) => { const denomInfo = await getDenomInfo( wex, @@ -276,7 +276,7 @@ export async function recoupWithdrawCoin( // FIXME: verify that our expectations about the amount match await wex.db.runReadWriteTx( - ["coins", "denominations", "recoupGroups", "refreshGroups"], + { storeNames: ["coins", "denominations", "recoupGroups", "refreshGroups"] }, async (tx) => { const recoupGroup = await tx.recoupGroups.get(recoupGroupId); if (!recoupGroup) { @@ -300,9 +300,12 @@ export async function processRecoupGroup( wex: WalletExecutionContext, recoupGroupId: string, ): Promise { - let recoupGroup = await wex.db.runReadOnlyTx(["recoupGroups"], async (tx) => { - return tx.recoupGroups.get(recoupGroupId); - }); + let recoupGroup = await wex.db.runReadOnlyTx( + { storeNames: ["recoupGroups"] }, + async (tx) => { + return tx.recoupGroups.get(recoupGroupId); + }, + ); if (!recoupGroup) { return TaskRunResult.finished(); } @@ -320,9 +323,12 @@ export async function processRecoupGroup( }); await Promise.all(ps); - recoupGroup = await wex.db.runReadOnlyTx(["recoupGroups"], async (tx) => { - return tx.recoupGroups.get(recoupGroupId); - }); + recoupGroup = await wex.db.runReadOnlyTx( + { storeNames: ["recoupGroups"] }, + async (tx) => { + return tx.recoupGroups.get(recoupGroupId); + }, + ); if (!recoupGroup) { return TaskRunResult.finished(); } @@ -339,22 +345,25 @@ export async function processRecoupGroup( const reservePrivMap: Record = {}; for (let i = 0; i < recoupGroup.coinPubs.length; i++) { const coinPub = recoupGroup.coinPubs[i]; - await wex.db.runReadOnlyTx(["coins", "reserves"], async (tx) => { - const coin = await tx.coins.get(coinPub); - if (!coin) { - throw Error(`Coin ${coinPub} not found, can't request recoup`); - } - if (coin.coinSource.type === CoinSourceType.Withdraw) { - const reserve = await tx.reserves.indexes.byReservePub.get( - coin.coinSource.reservePub, - ); - if (!reserve) { - return; + await wex.db.runReadOnlyTx( + { storeNames: ["coins", "reserves"] }, + async (tx) => { + const coin = await tx.coins.get(coinPub); + if (!coin) { + throw Error(`Coin ${coinPub} not found, can't request recoup`); } - reserveSet.add(coin.coinSource.reservePub); - reservePrivMap[coin.coinSource.reservePub] = reserve.reservePriv; - } - }); + if (coin.coinSource.type === CoinSourceType.Withdraw) { + const reserve = await tx.reserves.indexes.byReservePub.get( + coin.coinSource.reservePub, + ); + if (!reserve) { + return; + } + reserveSet.add(coin.coinSource.reservePub); + reservePrivMap[coin.coinSource.reservePub] = reserve.reservePriv; + } + }, + ); } for (const reservePub of reserveSet) { @@ -385,14 +394,16 @@ export async function processRecoupGroup( } await wex.db.runReadWriteTx( - [ - "recoupGroups", - "coinAvailability", - "denominations", - "refreshGroups", - "refreshSessions", - "coins", - ], + { + storeNames: [ + "recoupGroups", + "coinAvailability", + "denominations", + "refreshGroups", + "refreshSessions", + "coins", + ], + }, async (tx) => { const rg2 = await tx.recoupGroups.get(recoupGroupId); if (!rg2) { @@ -502,7 +513,7 @@ async function processRecoupForCoin( coinIdx: number, ): Promise { const coin = await wex.db.runReadOnlyTx( - ["coins", "recoupGroups"], + { storeNames: ["coins", "recoupGroups"] }, async (tx) => { const recoupGroup = await tx.recoupGroups.get(recoupGroupId); if (!recoupGroup) { -- cgit v1.2.3