diff options
author | Florian Dold <florian@dold.me> | 2022-10-15 11:52:07 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2022-10-15 11:53:16 +0200 |
commit | e075134ffc94fda3582b179122bda594d91a962b (patch) | |
tree | 547920b2aa07bdb9f2c87a0c1f8c35dbcd64c8f7 /packages/taler-wallet-core/src/operations/balance.ts | |
parent | 4d70391f3db386766a516bdecc3d1d265c5d49a1 (diff) | |
download | wallet-core-e075134ffc94fda3582b179122bda594d91a962b.tar.xz |
wallet-core: simplify coin record
we only track the allocation now, not the remaining amount
Diffstat (limited to 'packages/taler-wallet-core/src/operations/balance.ts')
-rw-r--r-- | packages/taler-wallet-core/src/operations/balance.ts | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/packages/taler-wallet-core/src/operations/balance.ts b/packages/taler-wallet-core/src/operations/balance.ts index 44357fdf4..3db66b5d9 100644 --- a/packages/taler-wallet-core/src/operations/balance.ts +++ b/packages/taler-wallet-core/src/operations/balance.ts @@ -23,7 +23,7 @@ import { Amounts, Logger, } from "@gnu-taler/taler-util"; -import { CoinStatus, WalletStoresV1 } from "../db.js"; +import { WalletStoresV1 } from "../db.js"; import { GetReadOnlyAccess } from "../util/query.js"; import { InternalWalletState } from "../internal-wallet-state.js"; @@ -42,6 +42,7 @@ export async function getBalancesInsideTransaction( ws: InternalWalletState, tx: GetReadOnlyAccess<{ coins: typeof WalletStoresV1.coins; + coinAvailability: typeof WalletStoresV1.coinAvailability; refreshGroups: typeof WalletStoresV1.refreshGroups; withdrawalGroups: typeof WalletStoresV1.withdrawalGroups; }>, @@ -64,12 +65,14 @@ export async function getBalancesInsideTransaction( return balanceStore[currency]; }; - await tx.coins.iter().forEach((c) => { - // Only count fresh coins, as dormant coins will - // already be in a refresh session. - if (c.status === CoinStatus.Fresh) { - const b = initBalance(c.currentAmount.currency); - b.available = Amounts.add(b.available, c.currentAmount).amount; + await tx.coinAvailability.iter().forEach((ca) => { + const b = initBalance(ca.currency); + for (let i = 0; i < ca.freshCoinCount; i++) { + b.available = Amounts.add(b.available, { + currency: ca.currency, + fraction: ca.amountFrac, + value: ca.amountVal, + }).amount; } }); @@ -139,7 +142,13 @@ export async function getBalances( logger.trace("starting to compute balance"); const wbal = await ws.db - .mktx((x) => [x.coins, x.refreshGroups, x.purchases, x.withdrawalGroups]) + .mktx((x) => [ + x.coins, + x.coinAvailability, + x.refreshGroups, + x.purchases, + x.withdrawalGroups, + ]) .runReadOnly(async (tx) => { return getBalancesInsideTransaction(ws, tx); }); |