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/withdraw.ts | 32 ++++++++++++++-------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'packages/taler-wallet-core/src/operations/withdraw.ts') diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts b/packages/taler-wallet-core/src/operations/withdraw.ts index 731e9b3aa..ae3763a02 100644 --- a/packages/taler-wallet-core/src/operations/withdraw.ts +++ b/packages/taler-wallet-core/src/operations/withdraw.ts @@ -418,10 +418,7 @@ async function processPlanchetGenerate( coinIdx, coinPriv: r.coinPriv, coinPub: r.coinPub, - coinValue: r.coinValue, - denomPub: r.denomPub, denomPubHash: r.denomPubHash, - isFromTip: false, reservePub: r.reservePub, withdrawalDone: false, withdrawSig: r.withdrawSig, @@ -557,6 +554,7 @@ async function processPlanchetVerifyAndStoreCoin( .mktx((x) => ({ withdrawalGroups: x.withdrawalGroups, planchets: x.planchets, + denominations: x.denominations, })) .runReadOnly(async (tx) => { let planchet = await tx.planchets.indexes.byGroupAndIndex.get([ @@ -570,16 +568,29 @@ async function processPlanchetVerifyAndStoreCoin( logger.warn("processPlanchet: planchet already withdrawn"); return; } - return { planchet, exchangeBaseUrl: withdrawalGroup.exchangeBaseUrl }; + const denomInfo = await ws.getDenomInfo( + ws, + tx, + withdrawalGroup.exchangeBaseUrl, + planchet.denomPubHash, + ); + if (!denomInfo) { + return; + } + return { + planchet, + denomInfo, + exchangeBaseUrl: withdrawalGroup.exchangeBaseUrl, + }; }); if (!d) { return; } - const { planchet, exchangeBaseUrl } = d; + const { planchet, denomInfo } = d; - const planchetDenomPub = planchet.denomPub; + const planchetDenomPub = denomInfo.denomPub; if (planchetDenomPub.cipher !== DenomKeyType.Rsa) { throw Error(`cipher (${planchetDenomPub.cipher}) not supported`); } @@ -623,9 +634,9 @@ async function processPlanchetVerifyAndStoreCoin( } let denomSig: UnblindedSignature; - if (planchet.denomPub.cipher === DenomKeyType.Rsa) { + if (planchetDenomPub.cipher === DenomKeyType.Rsa) { denomSig = { - cipher: planchet.denomPub.cipher, + cipher: planchetDenomPub.cipher, rsa_signature: denomSigRsa, }; } else { @@ -636,12 +647,11 @@ async function processPlanchetVerifyAndStoreCoin( blindingKey: planchet.blindingKey, coinPriv: planchet.coinPriv, coinPub: planchet.coinPub, - currentAmount: planchet.coinValue, - denomPub: planchet.denomPub, + currentAmount: denomInfo.value, denomPubHash: planchet.denomPubHash, denomSig, coinEvHash: planchet.coinEvHash, - exchangeBaseUrl: exchangeBaseUrl, + exchangeBaseUrl: d.exchangeBaseUrl, status: CoinStatus.Fresh, coinSource: { type: CoinSourceType.Withdraw, -- cgit v1.2.3