From 9d660788521d93452aa767d86158889fd4870fd1 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 10 Mar 2022 16:30:24 +0100 Subject: wallet-core: do not rely on reserve history for withdrawals --- .../taler-wallet-core/src/operations/recoup.ts | 48 +++++++++++++++++++--- 1 file changed, 43 insertions(+), 5 deletions(-) (limited to 'packages/taler-wallet-core/src/operations/recoup.ts') diff --git a/packages/taler-wallet-core/src/operations/recoup.ts b/packages/taler-wallet-core/src/operations/recoup.ts index afca923bd..23d14f212 100644 --- a/packages/taler-wallet-core/src/operations/recoup.ts +++ b/packages/taler-wallet-core/src/operations/recoup.ts @@ -164,18 +164,34 @@ async function recoupWithdrawCoin( cs: WithdrawCoinSource, ): Promise { const reservePub = cs.reservePub; - const reserve = await ws.db + const d = await ws.db .mktx((x) => ({ reserves: x.reserves, + denominations: x.denominations, })) .runReadOnly(async (tx) => { - return tx.reserves.get(reservePub); + const reserve = await tx.reserves.get(reservePub); + if (!reserve) { + return; + } + const denomInfo = await ws.getDenomInfo( + ws, + tx, + reserve.exchangeBaseUrl, + coin.denomPubHash, + ); + if (!denomInfo) { + return; + } + return { reserve, denomInfo }; }); - if (!reserve) { + if (!d) { // FIXME: We should at least emit some pending operation / warning for this? return; } + const { reserve, denomInfo } = d; + ws.notify({ type: NotificationType.RecoupStarted, }); @@ -184,7 +200,7 @@ async function recoupWithdrawCoin( blindingKey: coin.blindingKey, coinPriv: coin.coinPriv, coinPub: coin.coinPub, - denomPub: coin.denomPub, + denomPub: denomInfo.denomPub, denomPubHash: coin.denomPubHash, denomSig: coin.denomSig, }); @@ -253,6 +269,28 @@ async function recoupRefreshCoin( coin: CoinRecord, cs: RefreshCoinSource, ): Promise { + const d = await ws.db + .mktx((x) => ({ + coins: x.coins, + denominations: x.denominations, + })) + .runReadOnly(async (tx) => { + const denomInfo = await ws.getDenomInfo( + ws, + tx, + coin.exchangeBaseUrl, + coin.denomPubHash, + ); + if (!denomInfo) { + return; + } + return { denomInfo }; + }); + if (!d) { + // FIXME: We should at least emit some pending operation / warning for this? + return; + } + ws.notify({ type: NotificationType.RecoupStarted, }); @@ -261,7 +299,7 @@ async function recoupRefreshCoin( blindingKey: coin.blindingKey, coinPriv: coin.coinPriv, coinPub: coin.coinPub, - denomPub: coin.denomPub, + denomPub: d.denomInfo.denomPub, denomPubHash: coin.denomPubHash, denomSig: coin.denomSig, }); -- cgit v1.2.3