From eb2c8d948c2b6fc75915b708ad68d53d37032981 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Sun, 31 Mar 2024 17:52:57 +0200 Subject: wallet-core: mark coins as lost, test --- packages/taler-wallet-core/src/exchanges.ts | 37 +++++++++++++++++++++-------- packages/taler-wallet-core/src/refresh.ts | 2 ++ 2 files changed, 29 insertions(+), 10 deletions(-) (limited to 'packages/taler-wallet-core') 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); } -- cgit v1.2.3