diff options
author | Florian Dold <florian@dold.me> | 2022-09-14 20:34:37 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2022-09-14 20:40:38 +0200 |
commit | c021876b41bff11ad28c3a43808795fa0d02ce99 (patch) | |
tree | c92f4e83def462ddb0d446c9c476fd32f648d744 /packages/taler-wallet-core/src/operations/refresh.ts | |
parent | 9d044058e267e9e94f3ee63809a1e22426151ee5 (diff) | |
download | wallet-core-c021876b41bff11ad28c3a43808795fa0d02ce99.tar.xz |
wallet-core: cache fresh coin count in DB
Diffstat (limited to 'packages/taler-wallet-core/src/operations/refresh.ts')
-rw-r--r-- | packages/taler-wallet-core/src/operations/refresh.ts | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/packages/taler-wallet-core/src/operations/refresh.ts b/packages/taler-wallet-core/src/operations/refresh.ts index 719093bd8..d1c366cd0 100644 --- a/packages/taler-wallet-core/src/operations/refresh.ts +++ b/packages/taler-wallet-core/src/operations/refresh.ts @@ -77,6 +77,7 @@ import { import { checkDbInvariant } from "../util/invariants.js"; import { GetReadWriteAccess } from "../util/query.js"; import { RetryInfo, runOperationHandlerForResult } from "../util/retries.js"; +import { makeCoinAvailable } from "../wallet.js"; import { guardOperationException } from "./common.js"; import { updateExchangeFromUrl } from "./exchanges.js"; import { @@ -670,7 +671,6 @@ async function refreshReveal( type: CoinSourceType.Refresh, oldCoinPub: refreshGroup.oldCoinPubs[coinIndex], }, - suspended: false, coinEvHash: pc.coinEvHash, ageCommitmentProof: pc.ageCommitmentProof, }; @@ -680,7 +680,7 @@ async function refreshReveal( } await ws.db - .mktx((x) => [x.coins, x.refreshGroups]) + .mktx((x) => [x.coins, x.denominations, x.refreshGroups]) .runReadWrite(async (tx) => { const rg = await tx.refreshGroups.get(refreshGroupId); if (!rg) { @@ -694,7 +694,7 @@ async function refreshReveal( rg.statusPerCoin[coinIndex] = RefreshCoinStatus.Finished; updateGroupStatus(rg); for (const coin of coins) { - await tx.coins.put(coin); + await makeCoinAvailable(ws, tx, coin); } await tx.refreshGroups.put(rg); }); @@ -865,10 +865,22 @@ export async function createRefreshGroup( !!denom, "denomination for existing coin must be in database", ); + if (coin.status !== CoinStatus.Dormant) { + coin.status = CoinStatus.Dormant; + const denom = await tx.denominations.get([ + coin.exchangeBaseUrl, + coin.denomPubHash, + ]); + checkDbInvariant(!!denom); + checkDbInvariant( + denom.freshCoinCount != null && denom.freshCoinCount > 0, + ); + denom.freshCoinCount--; + await tx.denominations.put(denom); + } const refreshAmount = coin.currentAmount; inputPerCoin.push(refreshAmount); coin.currentAmount = Amounts.getZero(refreshAmount.currency); - coin.status = CoinStatus.Dormant; await tx.coins.put(coin); const denoms = await getDenoms(coin.exchangeBaseUrl); const cost = getTotalRefreshCost(denoms, denom, refreshAmount); @@ -965,9 +977,6 @@ export async function autoRefresh( if (coin.status !== CoinStatus.Fresh) { continue; } - if (coin.suspended) { - continue; - } const denom = await tx.denominations.get([ exchangeBaseUrl, coin.denomPubHash, |