[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-wallet-core] branch master updated: wallet-core: handle suspended
From: |
gnunet |
Subject: |
[taler-wallet-core] branch master updated: wallet-core: handle suspended coins properly in refresh |
Date: |
Mon, 19 Sep 2022 14:42:15 +0200 |
This is an automated email from the git hooks/post-receive script.
dold pushed a commit to branch master
in repository wallet-core.
The following commit(s) were added to refs/heads/master by this push:
new ffe6a9521 wallet-core: handle suspended coins properly in refresh
ffe6a9521 is described below
commit ffe6a9521400ceabca713c08010532ece03152a8
Author: Florian Dold <florian@dold.me>
AuthorDate: Mon Sep 19 14:41:50 2022 +0200
wallet-core: handle suspended coins properly in refresh
---
.../taler-wallet-core/src/operations/refresh.ts | 36 +++++++++++++++-------
packages/taler-wallet-core/src/wallet.ts | 8 +----
2 files changed, 26 insertions(+), 18 deletions(-)
diff --git a/packages/taler-wallet-core/src/operations/refresh.ts
b/packages/taler-wallet-core/src/operations/refresh.ts
index 9560a3543..55070618f 100644
--- a/packages/taler-wallet-core/src/operations/refresh.ts
+++ b/packages/taler-wallet-core/src/operations/refresh.ts
@@ -67,6 +67,7 @@ import {
EXCHANGE_COINS_LOCK,
InternalWalletState,
} from "../internal-wallet-state.js";
+import { assertUnreachable } from "../util/assertUnreachable.js";
import {
readSuccessResponseJsonOrThrow,
readUnexpectedResponseDetails,
@@ -879,17 +880,30 @@ export async function createRefreshGroup(
!!denom,
"denomination for existing coin must be in database",
);
- if (coin.status !== CoinStatus.Dormant) {
- coin.status = CoinStatus.Dormant;
- const coinAv = await tx.coinAvailability.get([
- coin.exchangeBaseUrl,
- coin.denomPubHash,
- coin.maxAge,
- ]);
- checkDbInvariant(!!coinAv);
- checkDbInvariant(coinAv.freshCoinCount > 0);
- coinAv.freshCoinCount--;
- await tx.coinAvailability.put(coinAv);
+ switch (coin.status) {
+ case CoinStatus.Dormant:
+ break;
+ case CoinStatus.Fresh: {
+ coin.status = CoinStatus.Dormant;
+ const coinAv = await tx.coinAvailability.get([
+ coin.exchangeBaseUrl,
+ coin.denomPubHash,
+ coin.maxAge,
+ ]);
+ checkDbInvariant(!!coinAv);
+ checkDbInvariant(coinAv.freshCoinCount > 0);
+ coinAv.freshCoinCount--;
+ await tx.coinAvailability.put(coinAv);
+ break;
+ }
+ case CoinStatus.FreshSuspended: {
+ // For suspended coins, we don't have to adjust coin
+ // availability, as they are not counted as available.
+ coin.status = CoinStatus.Dormant;
+ break;
+ }
+ default:
+ assertUnreachable(coin.status);
}
const refreshAmount = coin.currentAmount;
inputPerCoin.push(refreshAmount);
diff --git a/packages/taler-wallet-core/src/wallet.ts
b/packages/taler-wallet-core/src/wallet.ts
index c615bc81d..1b74f2025 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -937,10 +937,7 @@ async function setCoinSuspended(
if (c.status !== CoinStatus.Fresh) {
return;
}
- if (
- coinAvailability.freshCoinCount == null ||
- coinAvailability.freshCoinCount === 0
- ) {
+ if (coinAvailability.freshCoinCount === 0) {
throw Error(
`invalid coin count ${coinAvailability.freshCoinCount} in DB`,
);
@@ -951,9 +948,6 @@ async function setCoinSuspended(
if (c.status == CoinStatus.Dormant) {
return;
}
- if (coinAvailability.freshCoinCount == null) {
- coinAvailability.freshCoinCount = 0;
- }
coinAvailability.freshCoinCount++;
c.status = CoinStatus.Fresh;
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-wallet-core] branch master updated: wallet-core: handle suspended coins properly in refresh,
gnunet <=