aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/withdraw.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2023-06-26 19:27:34 +0200
committerFlorian Dold <florian@dold.me>2023-06-26 19:27:42 +0200
commita844136489611525726c117cb28086b854bee5c0 (patch)
treebb3384fab39600c35675cd8e36caac9246ef9782 /packages/taler-wallet-core/src/operations/withdraw.ts
parent2779086a32a62d6d16b7813c2ca4944dc02c4d93 (diff)
downloadwallet-core-a844136489611525726c117cb28086b854bee5c0.tar.xz
wallet-core: make changes to available amount atomic
W.r.t. transactions
Diffstat (limited to 'packages/taler-wallet-core/src/operations/withdraw.ts')
-rw-r--r--packages/taler-wallet-core/src/operations/withdraw.ts21
1 files changed, 14 insertions, 7 deletions
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);