aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2024-03-31 17:52:57 +0200
committerFlorian Dold <florian@dold.me>2024-03-31 17:53:07 +0200
commiteb2c8d948c2b6fc75915b708ad68d53d37032981 (patch)
treedcf692f0e95c61726a986a7bec53ce6a0ac4c8a0 /packages/taler-wallet-core
parent863e468df9d70c3d7268e96378c03b1cf7333f88 (diff)
downloadwallet-core-eb2c8d948c2b6fc75915b708ad68d53d37032981.tar.xz
wallet-core: mark coins as lost, test
Diffstat (limited to 'packages/taler-wallet-core')
-rw-r--r--packages/taler-wallet-core/src/exchanges.ts37
-rw-r--r--packages/taler-wallet-core/src/refresh.ts2
2 files changed, 29 insertions, 10 deletions
diff --git a/packages/taler-wallet-core/src/exchanges.ts b/packages/taler-wallet-core/src/exchanges.ts
index 48d8d4972..7fb387a9e 100644
--- a/packages/taler-wallet-core/src/exchanges.ts
+++ b/packages/taler-wallet-core/src/exchanges.ts
@@ -1697,7 +1697,7 @@ interface DenomLossResult {
async function handleDenomLoss(
wex: WalletExecutionContext,
tx: WalletDbReadWriteTransaction<
- ["coinAvailability", "denominations", "denomLossEvents"]
+ ["coinAvailability", "denominations", "denomLossEvents", "coins"]
>,
currency: string,
exchangeBaseUrl: string,
@@ -1721,6 +1721,9 @@ async function handleDenomLoss(
}
const n = coinAv.freshCoinCount;
const denom = await tx.denominations.get(coinAv.denomPubHash);
+ const timestampExpireDeposit = !denom
+ ? undefined
+ : timestampAbsoluteFromDb(denom.stampExpireDeposit);
if (!denom) {
// Remove availability
coinAv.freshCoinCount = 0;
@@ -1729,9 +1732,7 @@ async function handleDenomLoss(
denomsVanished.push(coinAv.denomPubHash);
const total = Amount.from(coinAv.value).mult(n);
amountVanished = amountVanished.add(total);
- continue;
- }
- if (!denom.isOffered) {
+ } else if (!denom.isOffered) {
// Remove availability
coinAv.freshCoinCount = 0;
coinAv.visibleCoinCount = 0;
@@ -1739,12 +1740,10 @@ async function handleDenomLoss(
denomsUnoffered.push(coinAv.denomPubHash);
const total = Amount.from(coinAv.value).mult(n);
amountUnoffered = amountUnoffered.add(total);
- continue;
- }
- const timestampExpireDeposit = timestampAbsoluteFromDb(
- denom.stampExpireDeposit,
- );
- if (AbsoluteTime.isExpired(timestampExpireDeposit)) {
+ } else if (
+ timestampExpireDeposit &&
+ AbsoluteTime.isExpired(timestampExpireDeposit)
+ ) {
// Remove availability
coinAv.freshCoinCount = 0;
coinAv.visibleCoinCount = 0;
@@ -1752,8 +1751,26 @@ async function handleDenomLoss(
denomsExpired.push(coinAv.denomPubHash);
const total = Amount.from(coinAv.value).mult(n);
amountExpired = amountExpired.add(total);
+ } else {
+ // Denomination is still fine!
continue;
}
+
+ logger.warn(`denomination ${coinAv.denomPubHash} is a loss`);
+
+ const coins = await tx.coins.indexes.byDenomPubHash.getAll(
+ coinAv.denomPubHash,
+ );
+ for (const coin of coins) {
+ switch (coin.status) {
+ case CoinStatus.Fresh:
+ case CoinStatus.FreshSuspended: {
+ coin.status = CoinStatus.DenomLoss;
+ await tx.coins.put(coin);
+ break;
+ }
+ }
+ }
}
if (denomsVanished.length > 0) {
diff --git a/packages/taler-wallet-core/src/refresh.ts b/packages/taler-wallet-core/src/refresh.ts
index 7c9ec84bd..516d5e3da 100644
--- a/packages/taler-wallet-core/src/refresh.ts
+++ b/packages/taler-wallet-core/src/refresh.ts
@@ -1311,6 +1311,8 @@ async function applyRefresh(
coin.status = CoinStatus.Dormant;
break;
}
+ case CoinStatus.DenomLoss:
+ break;
default:
assertUnreachable(coin.status);
}