From a844136489611525726c117cb28086b854bee5c0 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 26 Jun 2023 19:27:34 +0200 Subject: wallet-core: make changes to available amount atomic W.r.t. transactions --- .../taler-wallet-core/src/operations/withdraw.ts | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'packages/taler-wallet-core/src/operations/withdraw.ts') diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts b/packages/taler-wallet-core/src/operations/withdraw.ts index 8eb7f6457..e3897f84e 100644 --- a/packages/taler-wallet-core/src/operations/withdraw.ts +++ b/packages/taler-wallet-core/src/operations/withdraw.ts @@ -97,6 +97,7 @@ import { TaskIdentifiers, constructTaskIdentifier, makeCoinAvailable, + makeCoinsVisible, makeExchangeListItem, runLongpollAsync, } from "../operations/common.js"; @@ -1029,6 +1030,11 @@ async function processPlanchetVerifyAndStoreCoin( return; } + const transactionId = constructTransactionIdentifier({ + tag: TransactionType.Withdrawal, + withdrawalGroupId: wgContext.wgRecord.withdrawalGroupId, + }); + const { planchet, denomInfo } = d; const planchetDenomPub = denomInfo.denomPub; @@ -1099,6 +1105,7 @@ async function processPlanchetVerifyAndStoreCoin( reservePub: withdrawalGroup.reservePub, withdrawalGroupId: withdrawalGroup.withdrawalGroupId, }, + sourceTransactionId: transactionId, maxAge: withdrawalGroup.restrictAge ?? AgeRestriction.AGE_UNRESTRICTED, ageCommitmentProof: planchet.ageCommitmentProof, spendAllocation: undefined, @@ -1111,7 +1118,7 @@ async function processPlanchetVerifyAndStoreCoin( // Check if this is the first time that the whole // withdrawal succeeded. If so, mark the withdrawal // group as finished. - const firstSuccess = await ws.db + const success = await ws.db .mktx((x) => [ x.coins, x.denominations, @@ -1130,7 +1137,9 @@ async function processPlanchetVerifyAndStoreCoin( return true; }); - ws.notify({ type: NotificationType.BalanceChange }); + if (success) { + ws.notify({ type: NotificationType.BalanceChange }); + } } /** @@ -1495,10 +1504,7 @@ async function processWithdrawalGroupPendingReady( }; }); notifyTransition(ws, transactionId, transitionInfo); - return { - type: OperationAttemptResultType.Finished, - result: undefined, - }; + return OperationAttemptResult.finishedEmpty(); } const numTotalCoins = withdrawalGroup.denomsSel.selectedDenoms @@ -1563,7 +1569,7 @@ async function processWithdrawalGroupPendingReady( const maxReportedErrors = 5; const res = await ws.db - .mktx((x) => [x.coins, x.withdrawalGroups, x.planchets]) + .mktx((x) => [x.coins, x.coinAvailability, x.withdrawalGroups, x.planchets]) .runReadWrite(async (tx) => { const wg = await tx.withdrawalGroups.get(withdrawalGroupId); if (!wg) { @@ -1588,6 +1594,7 @@ async function processWithdrawalGroupPendingReady( if (wg.timestampFinish === undefined && numFinished === numTotalCoins) { wg.timestampFinish = TalerPreciseTimestamp.now(); wg.status = WithdrawalGroupStatus.Finished; + await makeCoinsVisible(ws, tx, transactionId); } const newTxState = computeWithdrawalTransactionStatus(wg); -- cgit v1.2.3