diff options
author | Florian Dold <florian@dold.me> | 2024-01-22 21:29:47 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2024-01-22 21:29:47 +0100 |
commit | fb5f098f9e60f03cdd6f78aba5aa248ec5889485 (patch) | |
tree | 2ddbf078597d48cbf9c85fa3c0491e5e63bb2196 /packages/taler-wallet-core/src/operations/refresh.ts | |
parent | 88851f45403c1995c973bcae7ad2976db3c430c7 (diff) | |
download | wallet-core-fb5f098f9e60f03cdd6f78aba5aa248ec5889485.tar.xz |
wallet-core: implement and test balance reporting with scope info
Diffstat (limited to 'packages/taler-wallet-core/src/operations/refresh.ts')
-rw-r--r-- | packages/taler-wallet-core/src/operations/refresh.ts | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/packages/taler-wallet-core/src/operations/refresh.ts b/packages/taler-wallet-core/src/operations/refresh.ts index d49c9a1cf..974eb1619 100644 --- a/packages/taler-wallet-core/src/operations/refresh.ts +++ b/packages/taler-wallet-core/src/operations/refresh.ts @@ -80,6 +80,7 @@ import { } from "../db.js"; import { getCandidateWithdrawalDenomsTx, + RefreshGroupPerExchangeInfo, RefreshSessionRecord, timestampPreciseToDb, timestampProtocolFromDb, @@ -1107,6 +1108,7 @@ async function processRefreshSession( export interface RefreshOutputInfo { outputPerCoin: AmountJson[]; + perExchangeInfo: Record<string, RefreshGroupPerExchangeInfo>; } export async function calculateRefreshOutput( @@ -1124,6 +1126,8 @@ export async function calculateRefreshOutput( const denomsPerExchange: Record<string, DenominationRecord[]> = {}; + const infoPerExchange: Record<string, RefreshGroupPerExchangeInfo> = {}; + // FIXME: Use denom groups instead of querying all denominations! const getDenoms = async ( exchangeBaseUrl: string, @@ -1163,11 +1167,21 @@ export async function calculateRefreshOutput( ws.config.testing.denomselAllowLate, ); const output = Amounts.sub(refreshAmount, cost).amount; + let exchInfo = infoPerExchange[coin.exchangeBaseUrl]; + if (!exchInfo) { + infoPerExchange[coin.exchangeBaseUrl] = exchInfo = { + outputEffective: Amounts.stringify(Amounts.zeroOfAmount(cost)), + }; + } + exchInfo.outputEffective = Amounts.stringify( + Amounts.add(exchInfo.outputEffective, output).amount, + ); estimatedOutputPerCoin.push(output); } return { outputPerCoin: estimatedOutputPerCoin, + perExchangeInfo: infoPerExchange, }; } @@ -1234,6 +1248,10 @@ async function applyRefresh( } } +export interface CreateRefreshGroupResult { + refreshGroupId: string; +} + /** * Create a refresh group for a list of coins. * @@ -1252,7 +1270,7 @@ export async function createRefreshGroup( oldCoinPubs: CoinRefreshRequest[], reason: RefreshReason, reasonDetails?: RefreshReasonDetails, -): Promise<RefreshGroupId> { +): Promise<CreateRefreshGroupResult> { const refreshGroupId = encodeCrock(getRandomBytes(32)); const outInfo = await calculateRefreshOutput(ws, tx, currency, oldCoinPubs); |