summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/coinSelection.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-core/src/coinSelection.ts')
-rw-r--r--packages/taler-wallet-core/src/coinSelection.ts32
1 files changed, 18 insertions, 14 deletions
diff --git a/packages/taler-wallet-core/src/coinSelection.ts b/packages/taler-wallet-core/src/coinSelection.ts
index e1ae613bc..680e5faa1 100644
--- a/packages/taler-wallet-core/src/coinSelection.ts
+++ b/packages/taler-wallet-core/src/coinSelection.ts
@@ -64,7 +64,11 @@ import { getAutoRefreshExecuteThreshold } from "./common.js";
import { DenominationRecord, WalletDbReadOnlyTransaction } from "./db.js";
import { isWithdrawableDenom } from "./denominations.js";
import { getExchangeWireDetailsInTx } from "./exchanges.js";
-import { getDenomInfo, InternalWalletState } from "./wallet.js";
+import {
+ getDenomInfo,
+ InternalWalletState,
+ WalletExecutionContext,
+} from "./wallet.js";
const logger = new Logger("coinSelection.ts");
@@ -247,7 +251,7 @@ export type SelectPayCoinsResult =
* This function is only exported for the sake of unit tests.
*/
export async function selectPayCoinsNew(
- ws: InternalWalletState,
+ wex: WalletExecutionContext,
req: SelectPayCoinRequestNg,
): Promise<SelectPayCoinsResult> {
const {
@@ -259,7 +263,7 @@ export async function selectPayCoinsNew(
// FIXME: Why don't we do this in a transaction?
const [candidateDenoms, wireFeesPerExchange] =
- await selectPayMerchantCandidates(ws, req);
+ await selectPayMerchantCandidates(wex, req);
const coinPubs: string[] = [];
const coinContributions: AmountJson[] = [];
@@ -312,7 +316,7 @@ export async function selectPayCoinsNew(
}
if (!selectedDenom) {
- const details = await getMerchantPaymentBalanceDetails(ws, {
+ const details = await getMerchantPaymentBalanceDetails(wex, {
acceptedAuditors: req.auditors,
acceptedExchanges: req.exchanges,
acceptedWireMethods: [req.wireMethod],
@@ -357,7 +361,7 @@ export async function selectPayCoinsNew(
logger.trace(`coin selection request ${j2s(req)}`);
logger.trace(`selected coins (via denoms) for payment: ${j2s(finalSel)}`);
- await ws.db.runReadOnlyTx(["coins", "denominations"], async (tx) => {
+ await wex.db.runReadOnlyTx(["coins", "denominations"], async (tx) => {
for (const dph of Object.keys(finalSel)) {
const selInfo = finalSel[dph];
const numRequested = selInfo.contributions.length;
@@ -594,10 +598,10 @@ export type AvailableDenom = DenominationInfo & {
};
async function selectPayMerchantCandidates(
- ws: InternalWalletState,
+ wex: WalletExecutionContext,
req: SelectPayCoinRequestNg,
): Promise<[AvailableDenom[], Record<string, AmountJson>]> {
- return await ws.db.runReadOnlyTx(
+ return await wex.db.runReadOnlyTx(
["exchanges", "exchangeDetails", "denominations", "coinAvailability"],
async (tx) => {
// FIXME: Use the existing helper (from balance.ts) to
@@ -906,7 +910,7 @@ export interface PeerCoinSelectionRequest {
* Get coin availability information for a certain exchange.
*/
async function selectPayPeerCandidatesForExchange(
- ws: InternalWalletState,
+ wex: WalletExecutionContext,
tx: WalletDbReadOnlyTransaction<["coinAvailability", "denominations"]>,
exchangeBaseUrl: string,
): Promise<AvailableDenom[]> {
@@ -1035,7 +1039,7 @@ function greedySelectPeer(
}
export async function selectPeerCoins(
- ws: InternalWalletState,
+ wex: WalletExecutionContext,
req: PeerCoinSelectionRequest,
): Promise<SelectPeerCoinsResult> {
const instructedAmount = req.instructedAmount;
@@ -1044,7 +1048,7 @@ export async function selectPeerCoins(
// one coin to spend.
throw new Error("amount of zero not allowed");
}
- return await ws.db.runReadWriteTx(
+ return await wex.db.runReadWriteTx(
[
"exchanges",
"contractTerms",
@@ -1063,7 +1067,7 @@ export async function selectPeerCoins(
continue;
}
const candidates = await selectPayPeerCandidatesForExchange(
- ws,
+ wex,
tx,
exch.baseUrl,
);
@@ -1089,7 +1093,7 @@ export async function selectPeerCoins(
throw Error("repair not possible, coin not found");
}
const denom = await getDenomInfo(
- ws,
+ wex,
tx,
coin.exchangeBaseUrl,
coin.denomPubHash,
@@ -1188,7 +1192,7 @@ export async function selectPeerCoins(
// We were unable to select coins.
// Now we need to produce error details.
- const infoGeneral = await getPeerPaymentBalanceDetailsInTx(ws, tx, {
+ const infoGeneral = await getPeerPaymentBalanceDetailsInTx(wex, tx, {
currency,
});
@@ -1200,7 +1204,7 @@ export async function selectPeerCoins(
if (exch.detailsPointer?.currency !== currency) {
continue;
}
- const infoExchange = await getPeerPaymentBalanceDetailsInTx(ws, tx, {
+ const infoExchange = await getPeerPaymentBalanceDetailsInTx(wex, tx, {
currency,
restrictExchangeTo: exch.baseUrl,
});