From d483a3f5574355ed9c43eb6ddea59e5734323cf0 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 19 Apr 2023 12:42:47 -0300 Subject: fix #7704 --- .../taler-wallet-core/src/operations/deposits.ts | 7 ++++- .../taler-wallet-core/src/operations/exchanges.ts | 11 +++++--- .../src/operations/pay-merchant.ts | 30 +++++++++++++++++++--- .../taler-wallet-core/src/operations/pay-peer.ts | 1 + .../taler-wallet-core/src/operations/refresh.ts | 13 +++++++--- .../taler-wallet-core/src/operations/withdraw.ts | 16 +++++++++--- 6 files changed, 63 insertions(+), 15 deletions(-) (limited to 'packages/taler-wallet-core/src/operations') diff --git a/packages/taler-wallet-core/src/operations/deposits.ts b/packages/taler-wallet-core/src/operations/deposits.ts index d1dbf5f53..700b875d3 100644 --- a/packages/taler-wallet-core/src/operations/deposits.ts +++ b/packages/taler-wallet-core/src/operations/deposits.ts @@ -840,7 +840,12 @@ export async function getTotalFeesForDepositAmount( denom.value, pcs.coinContributions[i], ).amount; - const refreshCost = getTotalRefreshCost(allDenoms, denom, amountLeft); + const refreshCost = getTotalRefreshCost( + allDenoms, + denom, + amountLeft, + ws.config.testing.denomselAllowLate, + ); refreshFee.push(refreshCost); } diff --git a/packages/taler-wallet-core/src/operations/exchanges.ts b/packages/taler-wallet-core/src/operations/exchanges.ts index d9051b32f..b5e02e64d 100644 --- a/packages/taler-wallet-core/src/operations/exchanges.ts +++ b/packages/taler-wallet-core/src/operations/exchanges.ts @@ -245,7 +245,7 @@ async function validateWireInfo( for (const a of wireInfo.accounts) { logger.trace("validating exchange acct"); let isValid = false; - if (ws.insecureTrustExchange) { + if (ws.config.testing.insecureTrustExchange) { isValid = true; } else { const { valid: v } = await ws.cryptoApi.isValidWireAccount({ @@ -275,7 +275,7 @@ async function validateWireInfo( wireFee: Amounts.stringify(x.wire_fee), }; let isValid = false; - if (ws.insecureTrustExchange) { + if (ws.config.testing.insecureTrustExchange) { isValid = true; } else { const { valid: v } = await ws.cryptoApi.isValidWireFee({ @@ -308,7 +308,7 @@ async function validateGlobalFees( for (const gf of fees) { logger.trace("validating exchange global fees"); let isValid = false; - if (ws.insecureTrustExchange) { + if (ws.config.testing.insecureTrustExchange) { isValid = true; } else { const { valid: v } = await ws.cryptoApi.isValidGlobalFees({ @@ -665,7 +665,10 @@ export async function updateExchangeFromUrlHandler( let ageMask = 0; for (const x of keysInfo.currentDenominations) { - if (isWithdrawableDenom(x) && x.denomPub.age_mask != 0) { + if ( + isWithdrawableDenom(x, ws.config.testing.denomselAllowLate) && + x.denomPub.age_mask != 0 + ) { ageMask = x.denomPub.age_mask; break; } diff --git a/packages/taler-wallet-core/src/operations/pay-merchant.ts b/packages/taler-wallet-core/src/operations/pay-merchant.ts index 496641fe7..2419d32a2 100644 --- a/packages/taler-wallet-core/src/operations/pay-merchant.ts +++ b/packages/taler-wallet-core/src/operations/pay-merchant.ts @@ -168,6 +168,7 @@ export async function getTotalPaymentCost( allDenoms, DenominationRecord.toDenomInfo(denom), amountLeft, + ws.config.testing.denomselAllowLate, ); costs.push(Amounts.parseOrThrow(pcs.coinContributions[i])); costs.push(refreshCost); @@ -1659,6 +1660,7 @@ async function applySuccessfulRefund( p: PurchaseRecord, refreshCoinsMap: Record, r: MerchantCoinRefundSuccessStatus, + denomselAllowLate: boolean, ): Promise { // FIXME: check signature before storing it as valid! @@ -1688,6 +1690,7 @@ async function applySuccessfulRefund( allDenoms, DenominationRecord.toDenomInfo(denom), amountLeft, + denomselAllowLate, ); refreshCoinsMap[coin.coinPub] = { @@ -1714,6 +1717,7 @@ async function storePendingRefund( }>, p: PurchaseRecord, r: MerchantCoinRefundFailureStatus, + denomselAllowLate: boolean, ): Promise { const refundKey = getRefundKey(r); @@ -1745,6 +1749,7 @@ async function storePendingRefund( allDenoms, DenominationRecord.toDenomInfo(denom), amountLeft, + denomselAllowLate, ); p.refunds[refundKey] = { @@ -1767,6 +1772,7 @@ async function storeFailedRefund( p: PurchaseRecord, refreshCoinsMap: Record, r: MerchantCoinRefundFailureStatus, + denomselAllowLate: boolean, ): Promise { const refundKey = getRefundKey(r); @@ -1797,6 +1803,7 @@ async function storeFailedRefund( allDenoms, DenominationRecord.toDenomInfo(denom), amountLeft, + denomselAllowLate, ); p.refunds[refundKey] = { @@ -1905,11 +1912,28 @@ async function acceptRefunds( // Invariant: (!existingRefundInfo) || (existingRefundInfo === Pending) if (refundStatus.type === "success") { - await applySuccessfulRefund(tx, p, refreshCoinsMap, refundStatus); + await applySuccessfulRefund( + tx, + p, + refreshCoinsMap, + refundStatus, + ws.config.testing.denomselAllowLate, + ); } else if (isPermanentFailure) { - await storeFailedRefund(tx, p, refreshCoinsMap, refundStatus); + await storeFailedRefund( + tx, + p, + refreshCoinsMap, + refundStatus, + ws.config.testing.denomselAllowLate, + ); } else { - await storePendingRefund(tx, p, refundStatus); + await storePendingRefund( + tx, + p, + refundStatus, + ws.config.testing.denomselAllowLate, + ); } } diff --git a/packages/taler-wallet-core/src/operations/pay-peer.ts b/packages/taler-wallet-core/src/operations/pay-peer.ts index ebf521079..33659afe0 100644 --- a/packages/taler-wallet-core/src/operations/pay-peer.ts +++ b/packages/taler-wallet-core/src/operations/pay-peer.ts @@ -417,6 +417,7 @@ export async function getTotalPeerPaymentCost( allDenoms, DenominationRecord.toDenomInfo(denom), amountLeft, + ws.config.testing.denomselAllowLate, ); costs.push(Amounts.parseOrThrow(pcs[i].contribution)); costs.push(refreshCost); diff --git a/packages/taler-wallet-core/src/operations/refresh.ts b/packages/taler-wallet-core/src/operations/refresh.ts index 70f0579c0..3122c9685 100644 --- a/packages/taler-wallet-core/src/operations/refresh.ts +++ b/packages/taler-wallet-core/src/operations/refresh.ts @@ -86,7 +86,7 @@ import { import { makeCoinAvailable } from "./common.js"; import { updateExchangeFromUrl } from "./exchanges.js"; import { selectWithdrawalDenominations } from "../util/coinSelection.js"; -import { isWithdrawableDenom } from "../index.js"; +import { isWithdrawableDenom, WalletConfig } from "../index.js"; const logger = new Logger("refresh.ts"); @@ -105,13 +105,18 @@ export function getTotalRefreshCost( denoms: DenominationRecord[], refreshedDenom: DenominationInfo, amountLeft: AmountJson, + denomselAllowLate: boolean, ): AmountJson { const withdrawAmount = Amounts.sub( amountLeft, refreshedDenom.feeRefresh, ).amount; const denomMap = Object.fromEntries(denoms.map((x) => [x.denomPubHash, x])); - const withdrawDenoms = selectWithdrawalDenominations(withdrawAmount, denoms); + const withdrawDenoms = selectWithdrawalDenominations( + withdrawAmount, + denoms, + denomselAllowLate, + ); const resultingAmount = Amounts.add( Amounts.zeroOfCurrency(withdrawAmount.currency), ...withdrawDenoms.selectedDenoms.map( @@ -232,6 +237,7 @@ async function refreshCreateSession( const newCoinDenoms = selectWithdrawalDenominations( availableAmount, availableDenoms, + ws.config.testing.denomselAllowLate, ); if (newCoinDenoms.selectedDenoms.length === 0) { @@ -897,7 +903,7 @@ export async function createRefreshGroup( const allDenoms = await tx.denominations.indexes.byExchangeBaseUrl .iter(exchangeBaseUrl) .filter((x) => { - return isWithdrawableDenom(x); + return isWithdrawableDenom(x, ws.config.testing.denomselAllowLate); }); denomsPerExchange[exchangeBaseUrl] = allDenoms; return allDenoms; @@ -955,6 +961,7 @@ export async function createRefreshGroup( denoms, denom, Amounts.parseOrThrow(refreshAmount), + ws.config.testing.denomselAllowLate, ); const output = Amounts.sub(refreshAmount, cost).amount; estimatedOutputPerCoin.push(output); diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts b/packages/taler-wallet-core/src/operations/withdraw.ts index 643737e93..23c3e6713 100644 --- a/packages/taler-wallet-core/src/operations/withdraw.ts +++ b/packages/taler-wallet-core/src/operations/withdraw.ts @@ -210,7 +210,9 @@ export async function getCandidateWithdrawalDenoms( const allDenoms = await tx.denominations.indexes.byExchangeBaseUrl.getAll( exchangeBaseUrl, ); - return allDenoms.filter(isWithdrawableDenom); + return allDenoms.filter((d) => + isWithdrawableDenom(d, ws.config.testing.denomselAllowLate), + ); }); } @@ -719,7 +721,7 @@ export async function updateWithdrawalDenoms( }) signature of ${denom.denomPubHash}`, ); let valid = false; - if (ws.insecureTrustExchange) { + if (ws.config.testing.insecureTrustExchange) { valid = true; } else { const res = await ws.cryptoApi.isValidDenom({ @@ -1003,7 +1005,7 @@ export async function processWithdrawalGroup( const resp = await processPlanchetExchangeBatchRequest(ws, wgContext, { batchSize: maxBatchSize, coinStartIndex: i, - useBatchRequest: ws.batchWithdrawal, + useBatchRequest: ws.config.features.batchWithdrawal, }); let work: Promise[] = []; work = []; @@ -1180,6 +1182,7 @@ export async function getExchangeWithdrawalInfo( const selectedDenoms = selectWithdrawalDenominations( instructedAmount, denoms, + ws.config.testing.denomselAllowLate, ); if (selectedDenoms.selectedDenoms.length === 0) { @@ -1710,9 +1713,14 @@ export async function internalCreateWithdrawalGroup( amount, denoms, args.forcedDenomSel, + ws.config.testing.denomselAllowLate, ); } else { - initialDenomSel = selectWithdrawalDenominations(amount, denoms); + initialDenomSel = selectWithdrawalDenominations( + amount, + denoms, + ws.config.testing.denomselAllowLate, + ); } const withdrawalGroup: WithdrawalGroupRecord = { -- cgit v1.2.3