From 17c3ced6488eb14a01b39f1ad724fcfcd5d0c4e7 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 13 Jan 2022 22:01:14 +0100 Subject: make more use of the denom cache --- packages/taler-wallet-core/src/operations/pay.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'packages/taler-wallet-core/src/operations/pay.ts') diff --git a/packages/taler-wallet-core/src/operations/pay.ts b/packages/taler-wallet-core/src/operations/pay.ts index 89930120d..479ab5e1c 100644 --- a/packages/taler-wallet-core/src/operations/pay.ts +++ b/packages/taler-wallet-core/src/operations/pay.ts @@ -166,8 +166,10 @@ export async function getTotalPaymentCost( .filter((x) => Amounts.isSameCurrency(x.value, pcs.coinContributions[i]), ); - const amountLeft = Amounts.sub(denom.value, pcs.coinContributions[i]) - .amount; + const amountLeft = Amounts.sub( + denom.value, + pcs.coinContributions[i], + ).amount; const refreshCost = getTotalRefreshCost(allDenoms, denom, amountLeft); costs.push(pcs.coinContributions[i]); costs.push(refreshCost); @@ -290,10 +292,12 @@ export async function getCandidatePayCoins( // Denomination of the first coin, we assume that all other // coins have the same currency - const firstDenom = await tx.denominations.get([ + const firstDenom = await ws.getDenomInfo( + ws, + tx, exchange.baseUrl, coins[0].denomPubHash, - ]); + ); if (!firstDenom) { throw Error("db inconsistent"); } @@ -365,6 +369,7 @@ export async function applyCoinSpend( coinSelection: PayCoinSelection, allocationId: string, ) { + logger.info(`applying coin spend ${j2s(coinSelection)}`); for (let i = 0; i < coinSelection.coinPubs.length; i++) { const coin = await tx.coins.get(coinSelection.coinPubs[i]); if (!coin) { @@ -525,7 +530,8 @@ async function incrementPurchasePayRetry( pr.payRetryInfo.retryCounter++; updateRetryInfoTimeout(pr.payRetryInfo); logger.trace( - `retrying pay in ${getDurationRemaining(pr.payRetryInfo.nextRetry).d_ms + `retrying pay in ${ + getDurationRemaining(pr.payRetryInfo.nextRetry).d_ms } ms`, ); pr.lastPayError = err; @@ -812,9 +818,8 @@ async function processDownloadProposalImpl( (fulfillmentUrl.startsWith("http://") || fulfillmentUrl.startsWith("https://")) ) { - const differentPurchase = await tx.purchases.indexes.byFulfillmentUrl.get( - fulfillmentUrl, - ); + const differentPurchase = + await tx.purchases.indexes.byFulfillmentUrl.get(fulfillmentUrl); if (differentPurchase) { logger.warn("repurchase detected"); p.proposalStatus = ProposalStatus.REPURCHASE; -- cgit v1.2.3