summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/wallet.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-core/src/wallet.ts')
-rw-r--r--packages/taler-wallet-core/src/wallet.ts61
1 files changed, 38 insertions, 23 deletions
diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts
index f21db0531..086c2ffa5 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -26,7 +26,7 @@ import { IDBFactory } from "@gnu-taler/idb-bridge";
import {
AmountString,
Amounts,
- AsyncCondition,
+ CancellationToken,
CoinDumpJson,
CoinStatus,
CoreApiResponse,
@@ -135,6 +135,7 @@ import {
validateIban,
} from "@gnu-taler/taler-util";
import type { HttpRequestLibrary } from "@gnu-taler/taler-util/http";
+import { ObservabilityContext } from "../../taler-util/src/observability.js";
import {
getUserAttentions,
getUserAttentionsUnreadCount,
@@ -269,6 +270,21 @@ import {
const logger = new Logger("wallet.ts");
+/**
+ * Execution context for code that is run in the wallet.
+ *
+ * Typically the excecution context is either for a wallet-core
+ * request handler or for a shepherded task.
+ */
+export interface WalletExecutionContext {
+ readonly ws: InternalWalletState;
+ readonly cryptoApi: TalerCryptoInterface;
+ readonly cancellationToken: CancellationToken;
+ readonly http: HttpRequestLibrary;
+ readonly db: DbAccess<typeof WalletStoresV1>;
+ readonly oc: ObservabilityContext;
+}
+
export const EXCHANGE_COINS_LOCK = "exchange-coins-lock";
export const EXCHANGE_RESERVES_LOCK = "exchange-reserves-lock";
@@ -440,7 +456,7 @@ async function dumpCoins(ws: InternalWalletState): Promise<CoinDumpJson> {
if (cs.type == CoinSourceType.Withdraw) {
withdrawalReservePub = cs.reservePub;
}
- const denomInfo = await ws.getDenomInfo(
+ const denomInfo = await getDenomInfo(
ws,
tx,
c.exchangeBaseUrl,
@@ -1438,6 +1454,24 @@ export class Wallet {
}
}
+export async function getDenomInfo(
+ ws: InternalWalletState,
+ tx: WalletDbReadOnlyTransaction<["denominations"]>,
+ exchangeBaseUrl: string,
+ denomPubHash: string,
+): Promise<DenominationInfo | undefined> {
+ const key = `${exchangeBaseUrl}:${denomPubHash}`;
+ const cached = ws.denomCache[key];
+ if (cached) {
+ return cached;
+ }
+ const d = await tx.denominations.get([exchangeBaseUrl, denomPubHash]);
+ if (d) {
+ return DenominationRecord.toDenomInfo(d);
+ }
+ return undefined;
+}
+
/**
* Internal state of the wallet.
*
@@ -1445,10 +1479,9 @@ export class Wallet {
*/
export class InternalWalletState {
cryptoApi: TalerCryptoInterface;
- cryptoDispatcher: CryptoDispatcher;
+ private cryptoDispatcher: CryptoDispatcher;
readonly timerGroup: TimerGroup;
- workAvailable = new AsyncCondition();
stopped = false;
private listeners: NotificationListener[] = [];
@@ -1456,7 +1489,7 @@ export class InternalWalletState {
initCalled = false;
// FIXME: Use an LRU cache here.
- private denomCache: Record<string, DenominationInfo> = {};
+ denomCache: Record<string, DenominationInfo> = {};
/**
* Promises that are waiting for a particular resource.
@@ -1517,24 +1550,6 @@ export class InternalWalletState {
}
}
- async getDenomInfo(
- ws: InternalWalletState,
- tx: WalletDbReadOnlyTransaction<["denominations"]>,
- exchangeBaseUrl: string,
- denomPubHash: string,
- ): Promise<DenominationInfo | undefined> {
- const key = `${exchangeBaseUrl}:${denomPubHash}`;
- const cached = this.denomCache[key];
- if (cached) {
- return cached;
- }
- const d = await tx.denominations.get([exchangeBaseUrl, denomPubHash]);
- if (d) {
- return DenominationRecord.toDenomInfo(d);
- }
- return undefined;
- }
-
notify(n: WalletNotification): void {
logger.trace(`Notification: ${j2s(n)}`);
for (const l of this.listeners) {