summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/withdraw.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-core/src/operations/withdraw.ts')
-rw-r--r--packages/taler-wallet-core/src/operations/withdraw.ts62
1 files changed, 39 insertions, 23 deletions
diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts b/packages/taler-wallet-core/src/operations/withdraw.ts
index 3dffab7d6..392b3753d 100644
--- a/packages/taler-wallet-core/src/operations/withdraw.ts
+++ b/packages/taler-wallet-core/src/operations/withdraw.ts
@@ -102,6 +102,7 @@ import {
import {
ExchangeDetailsRecord,
ExchangeEntryDbRecordStatus,
+ Wallet,
isWithdrawableDenom,
timestampPreciseToDb,
} from "../index.js";
@@ -613,20 +614,29 @@ export async function getBankWithdrawalInfo(
export async function getCandidateWithdrawalDenoms(
ws: InternalWalletState,
exchangeBaseUrl: string,
+ currency: string,
): Promise<DenominationRecord[]> {
return await ws.db
.mktx((x) => [x.denominations])
.runReadOnly(async (tx) => {
- const allDenoms =
- await tx.denominations.indexes.byExchangeBaseUrl.getAll(
- exchangeBaseUrl,
- );
- return allDenoms.filter((d) =>
- isWithdrawableDenom(d, ws.config.testing.denomselAllowLate),
- );
+ return getCandidateWithdrawalDenomsTx(ws, tx, exchangeBaseUrl, currency);
});
}
+export async function getCandidateWithdrawalDenomsTx(
+ ws: InternalWalletState,
+ tx: GetReadOnlyAccess<{ denominations: typeof WalletStoresV1.denominations }>,
+ exchangeBaseUrl: string,
+ currency: string,
+): Promise<DenominationRecord[]> {
+ // FIXME: Use denom groups instead of querying all denominations!
+ const allDenoms =
+ await tx.denominations.indexes.byExchangeBaseUrl.getAll(exchangeBaseUrl);
+ return allDenoms
+ .filter((d) => d.currency === currency)
+ .filter((d) => isWithdrawableDenom(d, ws.config.testing.denomselAllowLate));
+}
+
/**
* Generate a planchet for a coin index in a withdrawal group.
* Does not actually withdraw the coin yet.
@@ -1193,7 +1203,11 @@ export async function updateWithdrawalDenoms(
// First do a pass where the validity of candidate denominations
// is checked and the result is stored in the database.
logger.trace("getting candidate denominations");
- const denominations = await getCandidateWithdrawalDenoms(ws, exchangeBaseUrl);
+ const denominations = await getCandidateWithdrawalDenoms(
+ ws,
+ exchangeBaseUrl,
+ exchangeDetails.currency,
+ );
logger.trace(`got ${denominations.length} candidate denominations`);
const batchSize = 500;
let current = 0;
@@ -1776,7 +1790,11 @@ export async function getExchangeWithdrawalInfo(
await updateWithdrawalDenoms(ws, exchangeBaseUrl);
logger.trace("getting candidate denoms");
- const denoms = await getCandidateWithdrawalDenoms(ws, exchangeBaseUrl);
+ const denoms = await getCandidateWithdrawalDenoms(
+ ws,
+ exchangeBaseUrl,
+ instructedAmount.currency,
+ );
logger.trace("selecting withdrawal denoms");
const selectedDenoms = selectWithdrawalDenominations(
instructedAmount,
@@ -1833,15 +1851,11 @@ export async function getExchangeWithdrawalInfo(
checkLogicInvariant(!!earliestDepositExpiration);
- const possibleDenoms = await ws.db
- .mktx((x) => [x.denominations])
- .runReadOnly(async (tx) => {
- const ds =
- await tx.denominations.indexes.byExchangeBaseUrl.getAll(
- exchangeBaseUrl,
- );
- return ds.filter((x) => x.isOffered);
- });
+ const possibleDenoms = await getCandidateWithdrawalDenoms(
+ ws,
+ exchangeBaseUrl,
+ instructedAmount.currency,
+ );
let versionMatch;
if (exchange.protocolVersionRange) {
@@ -1950,13 +1964,10 @@ export async function getWithdrawalDetailsForUri(
tx,
r.baseUrl,
);
- const denominations = await tx.denominations.indexes.byExchangeBaseUrl
- .iter(r.baseUrl)
- .toArray();
const retryRecord = await tx.operationRetries.get(
TaskIdentifiers.forExchangeUpdate(r),
);
- if (exchangeDetails && denominations) {
+ if (exchangeDetails) {
exchanges.push(
makeExchangeListItem(r, exchangeDetails, retryRecord?.lastError),
);
@@ -2309,6 +2320,7 @@ export async function internalPrepareCreateWithdrawalGroup(
const secretSeed = encodeCrock(getRandomBytes(32));
const canonExchange = canonicalizeBaseUrl(args.exchangeBaseUrl);
const amount = args.amount;
+ const currency = Amounts.currencyOf(amount);
let withdrawalGroupId;
@@ -2333,7 +2345,11 @@ export async function internalPrepareCreateWithdrawalGroup(
}
await updateWithdrawalDenoms(ws, canonExchange);
- const denoms = await getCandidateWithdrawalDenoms(ws, canonExchange);
+ const denoms = await getCandidateWithdrawalDenoms(
+ ws,
+ canonExchange,
+ currency,
+ );
let initialDenomSel: DenomSelectionState;
const denomSelUid = encodeCrock(getRandomBytes(16));