diff options
author | Florian Dold <florian@dold.me> | 2024-04-23 03:09:40 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2024-04-23 03:09:40 +0200 |
commit | 1edc144b3595ae1ab6b8af7a43d26b811b2c2623 (patch) | |
tree | db552f6b4a351eb1d0dae902f4d504031852bda7 /packages/taler-wallet-core/src/withdraw.ts | |
parent | 4b69853c347071acb73efcde9d4969cf06d0dfcc (diff) | |
download | wallet-core-1edc144b3595ae1ab6b8af7a43d26b811b2c2623.tar.gz wallet-core-1edc144b3595ae1ab6b8af7a43d26b811b2c2623.tar.bz2 wallet-core-1edc144b3595ae1ab6b8af7a43d26b811b2c2623.zip |
wallet-core: pass options object to all transactions
Diffstat (limited to 'packages/taler-wallet-core/src/withdraw.ts')
-rw-r--r-- | packages/taler-wallet-core/src/withdraw.ts | 197 |
1 files changed, 111 insertions, 86 deletions
diff --git a/packages/taler-wallet-core/src/withdraw.ts b/packages/taler-wallet-core/src/withdraw.ts index ecd654edf..4936135bd 100644 --- a/packages/taler-wallet-core/src/withdraw.ts +++ b/packages/taler-wallet-core/src/withdraw.ts @@ -325,7 +325,7 @@ export class WithdrawTransactionContext implements TransactionContext { ? [...baseStores, ...opts.extraStores] : baseStores; const transitionInfo = await this.wex.db.runReadWriteTx( - stores, + { storeNames: stores }, async (tx) => { const wgRec = await tx.withdrawalGroups.get(this.withdrawalGroupId); let oldTxState: TransactionState; @@ -773,9 +773,12 @@ async function getCandidateWithdrawalDenoms( exchangeBaseUrl: string, currency: string, ): Promise<DenominationRecord[]> { - return await wex.db.runReadOnlyTx(["denominations"], async (tx) => { - return getCandidateWithdrawalDenomsTx(wex, tx, exchangeBaseUrl, currency); - }); + return await wex.db.runReadOnlyTx( + { storeNames: ["denominations"] }, + async (tx) => { + return getCandidateWithdrawalDenomsTx(wex, tx, exchangeBaseUrl, currency); + }, + ); } export async function getCandidateWithdrawalDenomsTx( @@ -806,12 +809,15 @@ async function processPlanchetGenerate( withdrawalGroup: WithdrawalGroupRecord, coinIdx: number, ): Promise<void> { - let planchet = await wex.db.runReadOnlyTx(["planchets"], async (tx) => { - return tx.planchets.indexes.byGroupAndIndex.get([ - withdrawalGroup.withdrawalGroupId, - coinIdx, - ]); - }); + let planchet = await wex.db.runReadOnlyTx( + { storeNames: ["planchets"] }, + async (tx) => { + return tx.planchets.indexes.byGroupAndIndex.get([ + withdrawalGroup.withdrawalGroupId, + coinIdx, + ]); + }, + ); if (planchet) { return; } @@ -837,9 +843,17 @@ async function processPlanchetGenerate( } const denomPubHash = maybeDenomPubHash; - const denom = await wex.db.runReadOnlyTx(["denominations"], async (tx) => { - return getDenomInfo(wex, tx, withdrawalGroup.exchangeBaseUrl, denomPubHash); - }); + const denom = await wex.db.runReadOnlyTx( + { storeNames: ["denominations"] }, + async (tx) => { + return getDenomInfo( + wex, + tx, + withdrawalGroup.exchangeBaseUrl, + denomPubHash, + ); + }, + ); checkDbInvariant(!!denom); const r = await wex.cryptoApi.createPlanchet({ denomPub: denom.denomPub, @@ -865,7 +879,7 @@ async function processPlanchetGenerate( ageCommitmentProof: r.ageCommitmentProof, lastError: undefined, }; - await wex.db.runReadWriteTx(["planchets"], async (tx) => { + await wex.db.runReadWriteTx({ storeNames: ["planchets"] }, async (tx) => { const p = await tx.planchets.indexes.byGroupAndIndex.get([ withdrawalGroup.withdrawalGroupId, coinIdx, @@ -1008,48 +1022,51 @@ async function processPlanchetExchangeBatchRequest( // Indices of coins that are included in the batch request const requestCoinIdxs: number[] = []; - await wex.db.runReadOnlyTx(["planchets", "denominations"], async (tx) => { - for ( - let coinIdx = args.coinStartIndex; - coinIdx < args.coinStartIndex + args.batchSize && - coinIdx < wgContext.numPlanchets; - coinIdx++ - ) { - let planchet = await tx.planchets.indexes.byGroupAndIndex.get([ - withdrawalGroup.withdrawalGroupId, - coinIdx, - ]); - if (!planchet) { - continue; - } - if (planchet.planchetStatus === PlanchetStatus.WithdrawalDone) { - logger.warn("processPlanchet: planchet already withdrawn"); - continue; - } - if (planchet.planchetStatus === PlanchetStatus.AbortedReplaced) { - continue; - } - const denom = await getDenomInfo( - wex, - tx, - withdrawalGroup.exchangeBaseUrl, - planchet.denomPubHash, - ); + await wex.db.runReadOnlyTx( + { storeNames: ["planchets", "denominations"] }, + async (tx) => { + for ( + let coinIdx = args.coinStartIndex; + coinIdx < args.coinStartIndex + args.batchSize && + coinIdx < wgContext.numPlanchets; + coinIdx++ + ) { + let planchet = await tx.planchets.indexes.byGroupAndIndex.get([ + withdrawalGroup.withdrawalGroupId, + coinIdx, + ]); + if (!planchet) { + continue; + } + if (planchet.planchetStatus === PlanchetStatus.WithdrawalDone) { + logger.warn("processPlanchet: planchet already withdrawn"); + continue; + } + if (planchet.planchetStatus === PlanchetStatus.AbortedReplaced) { + continue; + } + const denom = await getDenomInfo( + wex, + tx, + withdrawalGroup.exchangeBaseUrl, + planchet.denomPubHash, + ); - if (!denom) { - logger.error("db inconsistent: denom for planchet not found"); - continue; - } + if (!denom) { + logger.error("db inconsistent: denom for planchet not found"); + continue; + } - const planchetReq: ExchangeWithdrawRequest = { - denom_pub_hash: planchet.denomPubHash, - reserve_sig: planchet.withdrawSig, - coin_ev: planchet.coinEv, - }; - batchReq.planchets.push(planchetReq); - requestCoinIdxs.push(coinIdx); - } - }); + const planchetReq: ExchangeWithdrawRequest = { + denom_pub_hash: planchet.denomPubHash, + reserve_sig: planchet.withdrawSig, + coin_ev: planchet.coinEv, + }; + batchReq.planchets.push(planchetReq); + requestCoinIdxs.push(coinIdx); + } + }, + ); if (batchReq.planchets.length == 0) { logger.warn("empty withdrawal batch"); @@ -1064,7 +1081,7 @@ async function processPlanchetExchangeBatchRequest( coinIdx: number, ): Promise<void> { logger.trace(`withdrawal request failed: ${j2s(errDetail)}`); - await wex.db.runReadWriteTx(["planchets"], async (tx) => { + await wex.db.runReadWriteTx({ storeNames: ["planchets"] }, async (tx) => { let planchet = await tx.planchets.indexes.byGroupAndIndex.get([ withdrawalGroup.withdrawalGroupId, coinIdx, @@ -1136,7 +1153,7 @@ async function processPlanchetVerifyAndStoreCoin( const withdrawalGroup = wgContext.wgRecord; logger.trace(`checking and storing planchet idx=${coinIdx}`); const d = await wex.db.runReadOnlyTx( - ["planchets", "denominations"], + { storeNames: ["planchets", "denominations"] }, async (tx) => { let planchet = await tx.planchets.indexes.byGroupAndIndex.get([ withdrawalGroup.withdrawalGroupId, @@ -1200,7 +1217,7 @@ async function processPlanchetVerifyAndStoreCoin( }); if (!isValid) { - await wex.db.runReadWriteTx(["planchets"], async (tx) => { + await wex.db.runReadWriteTx({ storeNames: ["planchets"] }, async (tx) => { let planchet = await tx.planchets.indexes.byGroupAndIndex.get([ withdrawalGroup.withdrawalGroupId, coinIdx, @@ -1254,7 +1271,7 @@ async function processPlanchetVerifyAndStoreCoin( wgContext.planchetsFinished.add(planchet.coinPub); await wex.db.runReadWriteTx( - ["planchets", "coins", "coinAvailability", "denominations"], + { storeNames: ["planchets", "coins", "coinAvailability", "denominations"] }, async (tx) => { const p = await tx.planchets.get(planchetCoinPub); if (!p || p.planchetStatus === PlanchetStatus.WithdrawalDone) { @@ -1280,7 +1297,7 @@ export async function updateWithdrawalDenoms( `updating denominations used for withdrawal for ${exchangeBaseUrl}`, ); const exchangeDetails = await wex.db.runReadOnlyTx( - ["exchanges", "exchangeDetails"], + { storeNames: ["exchanges", "exchangeDetails"] }, async (tx) => { return getExchangeWireDetailsInTx(tx, exchangeBaseUrl); }, @@ -1343,12 +1360,15 @@ export async function updateWithdrawalDenoms( } if (updatedDenominations.length > 0) { logger.trace("writing denomination batch to db"); - await wex.db.runReadWriteTx(["denominations"], async (tx) => { - for (let i = 0; i < updatedDenominations.length; i++) { - const denom = updatedDenominations[i]; - await tx.denominations.put(denom); - } - }); + await wex.db.runReadWriteTx( + { storeNames: ["denominations"] }, + async (tx) => { + for (let i = 0; i < updatedDenominations.length; i++) { + const denom = updatedDenominations[i]; + await tx.denominations.put(denom); + } + }, + ); wex.ws.denomInfoCache.clear(); logger.trace("done with DB write"); } @@ -1560,7 +1580,7 @@ async function redenominateWithdrawal( ): Promise<void> { logger.trace(`redenominating withdrawal group ${withdrawalGroupId}`); await wex.db.runReadWriteTx( - ["withdrawalGroups", "planchets", "denominations"], + { storeNames: ["withdrawalGroups", "planchets", "denominations"] }, async (tx) => { const wg = await tx.withdrawalGroups.get(withdrawalGroupId); if (!wg) { @@ -1728,7 +1748,7 @@ async function processWithdrawalGroupPendingReady( wgRecord: withdrawalGroup, }; - await wex.db.runReadOnlyTx(["planchets"], async (tx) => { + await wex.db.runReadOnlyTx({ storeNames: ["planchets"] }, async (tx) => { const planchets = await tx.planchets.indexes.byGroup.getAll(withdrawalGroupId); for (const p of planchets) { @@ -1772,7 +1792,7 @@ async function processWithdrawalGroupPendingReady( let redenomRequired = false; - await wex.db.runReadOnlyTx(["planchets"], async (tx) => { + await wex.db.runReadOnlyTx({ storeNames: ["planchets"] }, async (tx) => { const planchets = await tx.planchets.indexes.byGroup.getAll(withdrawalGroupId); for (const p of planchets) { @@ -1876,7 +1896,7 @@ export async function processWithdrawalGroup( ): Promise<TaskRunResult> { logger.trace("processing withdrawal group", withdrawalGroupId); const withdrawalGroup = await wex.db.runReadOnlyTx( - ["withdrawalGroups"], + { storeNames: ["withdrawalGroups"] }, async (tx) => { return tx.withdrawalGroups.get(withdrawalGroupId); }, @@ -2192,9 +2212,12 @@ async function getWithdrawalGroupRecordTx( withdrawalGroupId: string; }, ): Promise<WithdrawalGroupRecord | undefined> { - return await db.runReadOnlyTx(["withdrawalGroups"], async (tx) => { - return tx.withdrawalGroups.get(req.withdrawalGroupId); - }); + return await db.runReadOnlyTx( + { storeNames: ["withdrawalGroups"] }, + async (tx) => { + return tx.withdrawalGroups.get(req.withdrawalGroupId); + }, + ); } export function getReserveRequestTimeout(r: WithdrawalGroupRecord): Duration { @@ -2230,7 +2253,7 @@ async function registerReserveWithBank( withdrawalGroupId: string, ): Promise<void> { const withdrawalGroup = await wex.db.runReadOnlyTx( - ["withdrawalGroups"], + { storeNames: ["withdrawalGroups"] }, async (tx) => { return await tx.withdrawalGroups.get(withdrawalGroupId); }, @@ -2497,7 +2520,7 @@ export async function internalPrepareCreateWithdrawalGroup( withdrawalGroupId = args.forcedWithdrawalGroupId; const wgId = withdrawalGroupId; const existingWg = await wex.db.runReadOnlyTx( - ["withdrawalGroups"], + { storeNames: ["withdrawalGroups"] }, async (tx) => { return tx.withdrawalGroups.get(wgId); }, @@ -2684,14 +2707,16 @@ export async function internalCreateWithdrawalGroup( prep.withdrawalGroup.withdrawalGroupId, ); const res = await wex.db.runReadWriteTx( - [ - "withdrawalGroups", - "reserves", - "exchanges", - "exchangeDetails", - "transactions", - "operationRetries", - ], + { + storeNames: [ + "withdrawalGroups", + "reserves", + "exchanges", + "exchangeDetails", + "transactions", + "operationRetries", + ], + }, async (tx) => { const res = await internalPerformCreateWithdrawalGroup(wex, tx, prep); await updateWithdrawalTransaction(ctx, tx); @@ -2727,7 +2752,7 @@ export async function acceptWithdrawalFromUri( `accepting withdrawal via ${req.talerWithdrawUri}, canonicalized selected exchange ${selectedExchange}`, ); const existingWithdrawalGroup = await wex.db.runReadOnlyTx( - ["withdrawalGroups"], + { storeNames: ["withdrawalGroups"] }, async (tx) => { return await tx.withdrawalGroups.indexes.byTalerWithdrawUri.get( req.talerWithdrawUri, @@ -2821,7 +2846,7 @@ async function internalWaitWithdrawalRegistered( ): Promise<void> { while (true) { const { withdrawalRec, retryRec } = await wex.db.runReadOnlyTx( - ["withdrawalGroups", "operationRetries"], + { storeNames: ["withdrawalGroups", "operationRetries"] }, async (tx) => { return { withdrawalRec: await tx.withdrawalGroups.get(ctx.withdrawalGroupId), @@ -3069,7 +3094,7 @@ export async function createManualWithdrawal( ); const exchangePaytoUris = await wex.db.runReadOnlyTx( - ["withdrawalGroups", "exchanges", "exchangeDetails"], + { storeNames: ["withdrawalGroups", "exchanges", "exchangeDetails"] }, async (tx) => { return await getFundingPaytoUris(tx, withdrawalGroup.withdrawalGroupId); }, @@ -3136,7 +3161,7 @@ async function internalWaitWithdrawalFinal( // Check if refresh is final const res = await ctx.wex.db.runReadOnlyTx( - ["withdrawalGroups", "operationRetries"], + { storeNames: ["withdrawalGroups", "operationRetries"] }, async (tx) => { return { wg: await tx.withdrawalGroups.get(ctx.withdrawalGroupId), |