summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2024-02-20 18:48:42 +0100
committerFlorian Dold <florian@dold.me>2024-02-20 18:55:02 +0100
commitd70f722866b62e4a0076c805b65d66d5a049b366 (patch)
treeeae153cb78a4987c12e18bd1dedcd8ab34030d71
parentba3e64470ae035c431ca8107ed547269e7307c4a (diff)
downloadwallet-core-d70f722866b62e4a0076c805b65d66d5a049b366.tar.gz
wallet-core-d70f722866b62e4a0076c805b65d66d5a049b366.tar.bz2
wallet-core-d70f722866b62e4a0076c805b65d66d5a049b366.zip
wallet-core: get rid of separate InternalWalletState interface
-rw-r--r--packages/taler-harness/src/integrationtests/test-timetravel-autorefresh.ts6
-rw-r--r--packages/taler-wallet-core/src/attention.ts2
-rw-r--r--packages/taler-wallet-core/src/backup/index.ts2
-rw-r--r--packages/taler-wallet-core/src/balance.ts2
-rw-r--r--packages/taler-wallet-core/src/common.ts2
-rw-r--r--packages/taler-wallet-core/src/deposits.ts2
-rw-r--r--packages/taler-wallet-core/src/dev-experiments.ts13
-rw-r--r--packages/taler-wallet-core/src/exchanges.ts5
-rw-r--r--packages/taler-wallet-core/src/internal-wallet-state.ts144
-rw-r--r--packages/taler-wallet-core/src/pay-merchant.ts5
-rw-r--r--packages/taler-wallet-core/src/pay-peer-common.ts4
-rw-r--r--packages/taler-wallet-core/src/pay-peer-pull-credit.ts2
-rw-r--r--packages/taler-wallet-core/src/pay-peer-pull-debit.ts2
-rw-r--r--packages/taler-wallet-core/src/pay-peer-push-credit.ts2
-rw-r--r--packages/taler-wallet-core/src/pay-peer-push-debit.ts2
-rw-r--r--packages/taler-wallet-core/src/recoup.ts2
-rw-r--r--packages/taler-wallet-core/src/refresh.ts5
-rw-r--r--packages/taler-wallet-core/src/reward.ts2
-rw-r--r--packages/taler-wallet-core/src/shepherd.ts2
-rw-r--r--packages/taler-wallet-core/src/testing.ts2
-rw-r--r--packages/taler-wallet-core/src/transactions.ts2
-rw-r--r--packages/taler-wallet-core/src/util/coinSelection.ts2
-rw-r--r--packages/taler-wallet-core/src/util/instructedAmountConversion.ts2
-rw-r--r--packages/taler-wallet-core/src/wallet.ts32
-rw-r--r--packages/taler-wallet-core/src/withdraw.ts2
25 files changed, 42 insertions, 206 deletions
diff --git a/packages/taler-harness/src/integrationtests/test-timetravel-autorefresh.ts b/packages/taler-harness/src/integrationtests/test-timetravel-autorefresh.ts
index 3c47f30db..98ac7adae 100644
--- a/packages/taler-harness/src/integrationtests/test-timetravel-autorefresh.ts
+++ b/packages/taler-harness/src/integrationtests/test-timetravel-autorefresh.ts
@@ -143,12 +143,6 @@ export async function runTimetravelAutorefreshTest(t: GlobalTestState) {
},
);
- let p: PendingOperationsResponse;
- p = await walletClient.call(WalletApiOperation.GetPendingOperations, {});
-
- console.log("pending operations after first time travel");
- console.log(JSON.stringify(p, undefined, 2));
-
// The time travel should cause exchanges to update.
await exchangeUpdated1Cond;
await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {});
diff --git a/packages/taler-wallet-core/src/attention.ts b/packages/taler-wallet-core/src/attention.ts
index 6893af010..61f95350d 100644
--- a/packages/taler-wallet-core/src/attention.ts
+++ b/packages/taler-wallet-core/src/attention.ts
@@ -29,7 +29,7 @@ import {
UserAttentionsResponse,
} from "@gnu-taler/taler-util";
import { timestampPreciseFromDb, timestampPreciseToDb } from "./db.js";
-import { InternalWalletState } from "./internal-wallet-state.js";
+import { InternalWalletState } from "./wallet.js";
const logger = new Logger("operations/attention.ts");
diff --git a/packages/taler-wallet-core/src/backup/index.ts b/packages/taler-wallet-core/src/backup/index.ts
index 919e92c5a..415af6fd6 100644
--- a/packages/taler-wallet-core/src/backup/index.ts
+++ b/packages/taler-wallet-core/src/backup/index.ts
@@ -87,9 +87,9 @@ import {
timestampOptionalPreciseFromDb,
timestampPreciseToDb,
} from "../db.js";
-import { InternalWalletState } from "../internal-wallet-state.js";
import { preparePayForUri } from "../pay-merchant.js";
import { checkDbInvariant, checkLogicInvariant } from "../util/invariants.js";
+import { InternalWalletState } from "../wallet.js";
const logger = new Logger("operations/backup.ts");
diff --git a/packages/taler-wallet-core/src/balance.ts b/packages/taler-wallet-core/src/balance.ts
index 94a500384..34f719ad3 100644
--- a/packages/taler-wallet-core/src/balance.ts
+++ b/packages/taler-wallet-core/src/balance.ts
@@ -78,9 +78,9 @@ import {
getExchangeScopeInfo,
getExchangeWireDetailsInTx,
} from "./exchanges.js";
-import { InternalWalletState } from "./internal-wallet-state.js";
import { assertUnreachable } from "./util/assertUnreachable.js";
import { checkLogicInvariant } from "./util/invariants.js";
+import { InternalWalletState } from "./wallet.js";
/**
* Logger.
diff --git a/packages/taler-wallet-core/src/common.ts b/packages/taler-wallet-core/src/common.ts
index 45351f680..942a36c7e 100644
--- a/packages/taler-wallet-core/src/common.ts
+++ b/packages/taler-wallet-core/src/common.ts
@@ -57,10 +57,10 @@ import {
WithdrawalGroupRecord,
timestampPreciseToDb,
} from "./db.js";
-import { InternalWalletState } from "./internal-wallet-state.js";
import { createRefreshGroup } from "./refresh.js";
import { assertUnreachable } from "./util/assertUnreachable.js";
import { checkDbInvariant, checkLogicInvariant } from "./util/invariants.js";
+import { InternalWalletState } from "./wallet.js";
const logger = new Logger("operations/common.ts");
diff --git a/packages/taler-wallet-core/src/deposits.ts b/packages/taler-wallet-core/src/deposits.ts
index 38e8f04bb..6c2c53996 100644
--- a/packages/taler-wallet-core/src/deposits.ts
+++ b/packages/taler-wallet-core/src/deposits.ts
@@ -90,7 +90,6 @@ import {
timestampProtocolToDb,
} from "./db.js";
import { getExchangeWireDetailsInTx } from "./exchanges.js";
-import { InternalWalletState } from "./internal-wallet-state.js";
import {
extractContractData,
generateDepositPermissions,
@@ -109,6 +108,7 @@ import {
import { assertUnreachable } from "./util/assertUnreachable.js";
import { selectPayCoinsNew } from "./util/coinSelection.js";
import { checkDbInvariant, checkLogicInvariant } from "./util/invariants.js";
+import { InternalWalletState } from "./wallet.js";
import { getCandidateWithdrawalDenomsTx } from "./withdraw.js";
/**
diff --git a/packages/taler-wallet-core/src/dev-experiments.ts b/packages/taler-wallet-core/src/dev-experiments.ts
index 1c3d2b2a2..b48aa716b 100644
--- a/packages/taler-wallet-core/src/dev-experiments.ts
+++ b/packages/taler-wallet-core/src/dev-experiments.ts
@@ -34,17 +34,16 @@ import {
parseDevExperimentUri,
} from "@gnu-taler/taler-util";
import {
- ConfigRecordKey,
- RefreshGroupRecord,
- RefreshOperationStatus,
- timestampPreciseToDb,
-} from "./db.js";
-import { InternalWalletState } from "./internal-wallet-state.js";
-import {
HttpRequestLibrary,
HttpRequestOptions,
HttpResponse,
} from "@gnu-taler/taler-util/http";
+import {
+ RefreshGroupRecord,
+ RefreshOperationStatus,
+ timestampPreciseToDb,
+} from "./db.js";
+import { InternalWalletState } from "./wallet.js";
const logger = new Logger("dev-experiments.ts");
diff --git a/packages/taler-wallet-core/src/exchanges.ts b/packages/taler-wallet-core/src/exchanges.ts
index 2c15691aa..610536619 100644
--- a/packages/taler-wallet-core/src/exchanges.ts
+++ b/packages/taler-wallet-core/src/exchanges.ts
@@ -117,8 +117,8 @@ import {
timestampProtocolFromDb,
timestampProtocolToDb,
} from "./db.js";
-import { InternalWalletState } from "./internal-wallet-state.js";
import { DbReadOnlyTransaction } from "./query.js";
+import { createRecoupGroup } from "./recoup.js";
import { createRefreshGroup } from "./refresh.js";
import {
createTimeline,
@@ -128,6 +128,7 @@ import {
} from "./util/denominations.js";
import { checkDbInvariant } from "./util/invariants.js";
import { WALLET_EXCHANGE_PROTOCOL_VERSION } from "./versions.js";
+import { InternalWalletState } from "./wallet.js";
const logger = new Logger("exchanges.ts");
@@ -1429,7 +1430,7 @@ export async function updateExchangeFromUrlHandler(
}
if (newlyRevokedCoinPubs.length != 0) {
logger.info("recouping coins", newlyRevokedCoinPubs);
- recoupGroupId = await ws.recoupOps.createRecoupGroup(
+ recoupGroupId = await createRecoupGroup(
ws,
tx,
exchangeBaseUrl,
diff --git a/packages/taler-wallet-core/src/internal-wallet-state.ts b/packages/taler-wallet-core/src/internal-wallet-state.ts
deleted file mode 100644
index d55b12269..000000000
--- a/packages/taler-wallet-core/src/internal-wallet-state.ts
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- This file is part of GNU Taler
- (C) 2019 GNUnet e.V.
-
- GNU Taler is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-
-/**
- * Common interface of the internal wallet state. This object is passed
- * to the various operations (exchange management, withdrawal, refresh, reserve
- * management, etc.).
- *
- * Some operations can be accessed via this state object. This allows mutual
- * recursion between operations, without having cyclic dependencies between
- * the respective TypeScript files.
- *
- * (You can think of this as a "header file" for the wallet implementation.)
- */
-
-/**
- * Imports.
- */
-import { IDBFactory } from "@gnu-taler/idb-bridge";
-import {
- DenominationInfo,
- TimerGroup,
- TransactionState,
- WalletNotification,
-} from "@gnu-taler/taler-util";
-import { HttpRequestLibrary } from "@gnu-taler/taler-util/http";
-import { TalerCryptoInterface } from "./crypto/cryptoImplementation.js";
-import {
- WalletDbAllStoresReadOnlyTransaction,
- WalletDbReadOnlyTransaction,
- WalletDbReadWriteTransaction,
- WalletStoresV1,
-} from "./db.js";
-import { DbAccess } from "./query.js";
-import { TaskScheduler } from "./shepherd.js";
-import { WalletConfig } from "./wallet-api-types.js";
-
-export const EXCHANGE_COINS_LOCK = "exchange-coins-lock";
-export const EXCHANGE_RESERVES_LOCK = "exchange-reserves-lock";
-
-export interface TrustInfo {
- isTrusted: boolean;
- isAudited: boolean;
-}
-
-export interface MerchantInfo {
- protocolVersionCurrent: number;
-}
-
-export interface RecoupOperations {
- createRecoupGroup(
- ws: InternalWalletState,
- tx: WalletDbReadWriteTransaction<
- ["recoupGroups", "denominations", "refreshGroups"]
- >,
- exchangeBaseUrl: string,
- coinPubs: string[],
- ): Promise<string>;
-}
-
-export type NotificationListener = (n: WalletNotification) => void;
-
-export type CancelFn = () => void;
-
-/**
- * Internal, shared wallet state that is used by the implementation
- * of wallet operations.
- *
- * FIXME: This should not be exported anywhere from the taler-wallet-core package,
- * as it's an opaque implementation detail.
- */
-export interface InternalWalletState {
- cryptoApi: TalerCryptoInterface;
-
- timerGroup: TimerGroup;
- stopped: boolean;
-
- config: Readonly<WalletConfig>;
-
- taskScheduler: TaskScheduler;
-
- listeners: NotificationListener[];
-
- initCalled: boolean;
-
- merchantInfoCache: Record<string, MerchantInfo>;
-
- recoupOps: RecoupOperations;
-
- isTaskLoopRunning: boolean;
-
- getTransactionState(
- ws: InternalWalletState,
- tx: WalletDbAllStoresReadOnlyTransaction,
- transactionId: string,
- ): Promise<TransactionState | undefined>;
-
- getDenomInfo(
- ws: InternalWalletState,
- tx: WalletDbReadOnlyTransaction<["denominations"]>,
- exchangeBaseUrl: string,
- denomPubHash: string,
- ): Promise<DenominationInfo | undefined>;
-
- ensureWalletDbOpen(): Promise<void>;
-
- idb: IDBFactory;
- db: DbAccess<typeof WalletStoresV1>;
- http: HttpRequestLibrary;
-
- notify(n: WalletNotification): void;
-
- addNotificationListener(f: (n: WalletNotification) => void): CancelFn;
-
- /**
- * Stop ongoing processing.
- */
- stop(): void;
-
- /**
- * Run an async function after acquiring a list of locks, identified
- * by string tokens.
- */
- runSequentialized<T>(tokens: string[], f: () => Promise<T>): Promise<T>;
-
- /**
- * Ensure that a task loop is currently running.
- * Starts one if no task loop is running.
- */
- ensureTaskLoopRunning(): void;
-}
diff --git a/packages/taler-wallet-core/src/pay-merchant.ts b/packages/taler-wallet-core/src/pay-merchant.ts
index 15de0571c..13580464b 100644
--- a/packages/taler-wallet-core/src/pay-merchant.ts
+++ b/packages/taler-wallet-core/src/pay-merchant.ts
@@ -126,10 +126,6 @@ import {
WalletDbReadWriteTransaction,
WalletStoresV1,
} from "./db.js";
-import {
- EXCHANGE_COINS_LOCK,
- InternalWalletState,
-} from "./internal-wallet-state.js";
import { DbReadWriteTransaction, StoreNames } from "./query.js";
import {
calculateRefreshOutput,
@@ -144,6 +140,7 @@ import {
import { assertUnreachable } from "./util/assertUnreachable.js";
import { PreviousPayCoins, selectPayCoinsNew } from "./util/coinSelection.js";
import { checkDbInvariant } from "./util/invariants.js";
+import { EXCHANGE_COINS_LOCK, InternalWalletState } from "./wallet.js";
import { getCandidateWithdrawalDenomsTx } from "./withdraw.js";
/**
diff --git a/packages/taler-wallet-core/src/pay-peer-common.ts b/packages/taler-wallet-core/src/pay-peer-common.ts
index 5d3aac915..abcffc83a 100644
--- a/packages/taler-wallet-core/src/pay-peer-common.ts
+++ b/packages/taler-wallet-core/src/pay-peer-common.ts
@@ -31,10 +31,10 @@ import {
} from "@gnu-taler/taler-util";
import { SpendCoinDetails } from "./crypto/cryptoImplementation.js";
import { PeerPushPaymentCoinSelection, ReserveRecord } from "./db.js";
-import { InternalWalletState } from "./internal-wallet-state.js";
+import { getTotalRefreshCost } from "./refresh.js";
import type { SelectedPeerCoin } from "./util/coinSelection.js";
import { checkDbInvariant } from "./util/invariants.js";
-import { getTotalRefreshCost } from "./refresh.js";
+import { InternalWalletState } from "./wallet.js";
import { getCandidateWithdrawalDenomsTx } from "./withdraw.js";
const logger = new Logger("operations/peer-to-peer.ts");
diff --git a/packages/taler-wallet-core/src/pay-peer-pull-credit.ts b/packages/taler-wallet-core/src/pay-peer-pull-credit.ts
index 6e4c2df70..e37a948ee 100644
--- a/packages/taler-wallet-core/src/pay-peer-pull-credit.ts
+++ b/packages/taler-wallet-core/src/pay-peer-pull-credit.ts
@@ -71,7 +71,6 @@ import {
timestampPreciseToDb,
} from "./db.js";
import { fetchFreshExchange } from "./exchanges.js";
-import { InternalWalletState } from "./internal-wallet-state.js";
import {
codecForExchangePurseStatus,
getMergeReserveInfo,
@@ -82,6 +81,7 @@ import {
} from "./transactions.js";
import { assertUnreachable } from "./util/assertUnreachable.js";
import { checkDbInvariant } from "./util/invariants.js";
+import { InternalWalletState } from "./wallet.js";
import {
getExchangeWithdrawalInfo,
internalCreateWithdrawalGroup,
diff --git a/packages/taler-wallet-core/src/pay-peer-pull-debit.ts b/packages/taler-wallet-core/src/pay-peer-pull-debit.ts
index 0b4f49ce2..b227e941a 100644
--- a/packages/taler-wallet-core/src/pay-peer-pull-debit.ts
+++ b/packages/taler-wallet-core/src/pay-peer-pull-debit.ts
@@ -80,7 +80,6 @@ import {
WalletStoresV1,
timestampPreciseToDb,
} from "./db.js";
-import { InternalWalletState } from "./internal-wallet-state.js";
import {
codecForExchangePurseStatus,
getTotalPeerPaymentCost,
@@ -96,6 +95,7 @@ import {
import { assertUnreachable } from "./util/assertUnreachable.js";
import { PeerCoinRepair, selectPeerCoins } from "./util/coinSelection.js";
import { checkLogicInvariant } from "./util/invariants.js";
+import { InternalWalletState } from "./wallet.js";
const logger = new Logger("pay-peer-pull-debit.ts");
diff --git a/packages/taler-wallet-core/src/pay-peer-push-credit.ts b/packages/taler-wallet-core/src/pay-peer-push-credit.ts
index b574be36b..6dcf59be9 100644
--- a/packages/taler-wallet-core/src/pay-peer-push-credit.ts
+++ b/packages/taler-wallet-core/src/pay-peer-push-credit.ts
@@ -70,7 +70,6 @@ import {
timestampPreciseToDb,
} from "./db.js";
import { fetchFreshExchange } from "./exchanges.js";
-import { InternalWalletState } from "./internal-wallet-state.js";
import {
codecForExchangePurseStatus,
getMergeReserveInfo,
@@ -83,6 +82,7 @@ import {
} from "./transactions.js";
import { assertUnreachable } from "./util/assertUnreachable.js";
import { checkDbInvariant } from "./util/invariants.js";
+import { InternalWalletState } from "./wallet.js";
import {
PerformCreateWithdrawalGroupResult,
getExchangeWithdrawalInfo,
diff --git a/packages/taler-wallet-core/src/pay-peer-push-debit.ts b/packages/taler-wallet-core/src/pay-peer-push-debit.ts
index 9cfbe25c4..098602ee0 100644
--- a/packages/taler-wallet-core/src/pay-peer-push-debit.ts
+++ b/packages/taler-wallet-core/src/pay-peer-push-debit.ts
@@ -65,7 +65,6 @@ import {
timestampProtocolFromDb,
timestampProtocolToDb,
} from "./db.js";
-import { InternalWalletState } from "./internal-wallet-state.js";
import {
codecForExchangePurseStatus,
getTotalPeerPaymentCost,
@@ -79,6 +78,7 @@ import {
import { assertUnreachable } from "./util/assertUnreachable.js";
import { PeerCoinRepair, selectPeerCoins } from "./util/coinSelection.js";
import { checkLogicInvariant } from "./util/invariants.js";
+import { InternalWalletState } from "./wallet.js";
const logger = new Logger("pay-peer-push-debit.ts");
diff --git a/packages/taler-wallet-core/src/recoup.ts b/packages/taler-wallet-core/src/recoup.ts
index 8e994484c..99c8aabc3 100644
--- a/packages/taler-wallet-core/src/recoup.ts
+++ b/packages/taler-wallet-core/src/recoup.ts
@@ -58,10 +58,10 @@ import {
WithdrawalRecordType,
timestampPreciseToDb,
} from "./db.js";
-import { InternalWalletState } from "./internal-wallet-state.js";
import { createRefreshGroup } from "./refresh.js";
import { constructTransactionIdentifier } from "./transactions.js";
import { checkDbInvariant } from "./util/invariants.js";
+import type { InternalWalletState } from "./wallet.js";
import { internalCreateWithdrawalGroup } from "./withdraw.js";
const logger = new Logger("operations/recoup.ts");
diff --git a/packages/taler-wallet-core/src/refresh.ts b/packages/taler-wallet-core/src/refresh.ts
index 09cd75bdd..8f3a5cab5 100644
--- a/packages/taler-wallet-core/src/refresh.ts
+++ b/packages/taler-wallet-core/src/refresh.ts
@@ -92,16 +92,13 @@ import {
} from "./db.js";
import { fetchFreshExchange } from "./exchanges.js";
import {
- EXCHANGE_COINS_LOCK,
- InternalWalletState,
-} from "./internal-wallet-state.js";
-import {
constructTransactionIdentifier,
notifyTransition,
} from "./transactions.js";
import { assertUnreachable } from "./util/assertUnreachable.js";
import { selectWithdrawalDenominations } from "./util/coinSelection.js";
import { checkDbInvariant } from "./util/invariants.js";
+import { EXCHANGE_COINS_LOCK, InternalWalletState } from "./wallet.js";
import { getCandidateWithdrawalDenomsTx } from "./withdraw.js";
const logger = new Logger("refresh.ts");
diff --git a/packages/taler-wallet-core/src/reward.ts b/packages/taler-wallet-core/src/reward.ts
index 4ef4d7509..6e7d3425c 100644
--- a/packages/taler-wallet-core/src/reward.ts
+++ b/packages/taler-wallet-core/src/reward.ts
@@ -36,12 +36,12 @@ import {
constructTaskIdentifier,
} from "./common.js";
import { RewardRecord, RewardRecordStatus } from "./db.js";
-import { InternalWalletState } from "./internal-wallet-state.js";
import {
constructTransactionIdentifier,
notifyTransition,
} from "./transactions.js";
import { assertUnreachable } from "./util/assertUnreachable.js";
+import { InternalWalletState } from "./wallet.js";
const logger = new Logger("operations/tip.ts");
diff --git a/packages/taler-wallet-core/src/shepherd.ts b/packages/taler-wallet-core/src/shepherd.ts
index 0639b7976..e8fddfc73 100644
--- a/packages/taler-wallet-core/src/shepherd.ts
+++ b/packages/taler-wallet-core/src/shepherd.ts
@@ -57,7 +57,6 @@ import {
} from "./db.js";
import { processDepositGroup } from "./deposits.js";
import { updateExchangeFromUrlHandler } from "./exchanges.js";
-import { InternalWalletState } from "./internal-wallet-state.js";
import { processPurchase } from "./pay-merchant.js";
import { processPeerPullCredit } from "./pay-peer-pull-credit.js";
import { processPeerPullDebit } from "./pay-peer-pull-debit.js";
@@ -66,6 +65,7 @@ import { processPeerPushDebit } from "./pay-peer-push-debit.js";
import { processRecoupGroup } from "./recoup.js";
import { processRefreshGroup } from "./refresh.js";
import { constructTransactionIdentifier } from "./transactions.js";
+import { InternalWalletState } from "./wallet.js";
import { processWithdrawalGroup } from "./withdraw.js";
const logger = new Logger("shepherd.ts");
diff --git a/packages/taler-wallet-core/src/testing.ts b/packages/taler-wallet-core/src/testing.ts
index 8192bacfd..4dcb59868 100644
--- a/packages/taler-wallet-core/src/testing.ts
+++ b/packages/taler-wallet-core/src/testing.ts
@@ -59,7 +59,6 @@ import {
import { getBalances } from "./balance.js";
import { createDepositGroup } from "./deposits.js";
import { fetchFreshExchange } from "./exchanges.js";
-import { InternalWalletState } from "./internal-wallet-state.js";
import {
confirmPay,
preparePayForUri,
@@ -78,6 +77,7 @@ import { initiatePeerPushDebit } from "./pay-peer-push-debit.js";
import { getRefreshesForTransaction } from "./refresh.js";
import { getTransactionById, getTransactions } from "./transactions.js";
import { checkLogicInvariant } from "./util/invariants.js";
+import type { InternalWalletState } from "./wallet.js";
import { acceptWithdrawalFromUri } from "./withdraw.js";
const logger = new Logger("operations/testing.ts");
diff --git a/packages/taler-wallet-core/src/transactions.ts b/packages/taler-wallet-core/src/transactions.ts
index 2050abac2..828c4dec3 100644
--- a/packages/taler-wallet-core/src/transactions.ts
+++ b/packages/taler-wallet-core/src/transactions.ts
@@ -90,7 +90,6 @@ import {
ExchangeWireDetails,
getExchangeWireDetailsInTx,
} from "./exchanges.js";
-import { InternalWalletState } from "./internal-wallet-state.js";
import {
computePayMerchantTransactionActions,
computePayMerchantTransactionState,
@@ -132,6 +131,7 @@ import {
} from "./reward.js";
import { assertUnreachable } from "./util/assertUnreachable.js";
import { checkDbInvariant, checkLogicInvariant } from "./util/invariants.js";
+import type { InternalWalletState } from "./wallet.js";
import {
augmentPaytoUrisForWithdrawal,
computeWithdrawalTransactionActions,
diff --git a/packages/taler-wallet-core/src/util/coinSelection.ts b/packages/taler-wallet-core/src/util/coinSelection.ts
index 88dd08f63..02eb3ae32 100644
--- a/packages/taler-wallet-core/src/util/coinSelection.ts
+++ b/packages/taler-wallet-core/src/util/coinSelection.ts
@@ -61,7 +61,7 @@ import {
import { getAutoRefreshExecuteThreshold } from "../common.js";
import { DenominationRecord, WalletDbReadOnlyTransaction } from "../db.js";
import { getExchangeWireDetailsInTx } from "../exchanges.js";
-import { InternalWalletState } from "../internal-wallet-state.js";
+import { InternalWalletState } from "../wallet.js";
import { isWithdrawableDenom } from "./denominations.js";
import { checkDbInvariant, checkLogicInvariant } from "./invariants.js";
diff --git a/packages/taler-wallet-core/src/util/instructedAmountConversion.ts b/packages/taler-wallet-core/src/util/instructedAmountConversion.ts
index f01dc4e21..1cd30fece 100644
--- a/packages/taler-wallet-core/src/util/instructedAmountConversion.ts
+++ b/packages/taler-wallet-core/src/util/instructedAmountConversion.ts
@@ -32,9 +32,9 @@ import {
} from "@gnu-taler/taler-util";
import { DenominationRecord, timestampProtocolFromDb } from "../db.js";
import { getExchangeWireDetailsInTx } from "../exchanges.js";
-import { InternalWalletState } from "../internal-wallet-state.js";
import { CoinInfo } from "./coinSelection.js";
import { checkDbInvariant } from "./invariants.js";
+import { InternalWalletState } from "../wallet.js";
/**
* If the operation going to be plan subtracts
diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts
index 63b7ca4f2..5a6cfb96b 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -162,7 +162,6 @@ import {
ConfigRecordKey,
DenominationRecord,
WalletDbReadOnlyTransaction,
- WalletDbReadWriteTransaction,
WalletStoresV1,
clearDatabase,
exportDb,
@@ -189,13 +188,6 @@ import {
lookupExchangeByUri,
} from "./exchanges.js";
import {
- CancelFn,
- InternalWalletState,
- MerchantInfo,
- NotificationListener,
- RecoupOperations,
-} from "./internal-wallet-state.js";
-import {
computePayMerchantTransactionState,
computeRefundTransactionState,
confirmPay,
@@ -227,7 +219,6 @@ import {
initiatePeerPushDebit,
} from "./pay-peer-push-debit.js";
import { DbAccess } from "./query.js";
-import { createRecoupGroup } from "./recoup.js";
import { computeRefreshTransactionState, forceRefresh } from "./refresh.js";
import { computeRewardTransactionStatus } from "./reward.js";
import { TaskScheduler } from "./shepherd.js";
@@ -287,6 +278,13 @@ import {
const logger = new Logger("wallet.ts");
+export const EXCHANGE_COINS_LOCK = "exchange-coins-lock";
+export const EXCHANGE_RESERVES_LOCK = "exchange-reserves-lock";
+
+export type NotificationListener = (n: WalletNotification) => void;
+
+type CancelFn = () => void;
+
async function runTaskLoop(
ws: InternalWalletState,
opts: RetryLoopOpts = {},
@@ -493,7 +491,7 @@ async function dumpCoins(ws: InternalWalletState): Promise<CoinDumpJson> {
/**
* Get an API client from an internal wallet state object.
*/
-export async function getClientFromWalletState(
+async function getClientFromWalletState(
ws: InternalWalletState,
): Promise<WalletCoreApiClient> {
let id = 0;
@@ -1363,7 +1361,7 @@ export class Wallet {
cryptoWorkerFactory: CryptoWorkerFactory,
config?: WalletConfigParameter,
) {
- this.ws = new InternalWalletStateImpl(
+ this.ws = new InternalWalletState(
idb,
http,
timer,
@@ -1446,24 +1444,18 @@ export class Wallet {
*
* This ties together all the operation implementations.
*/
-class InternalWalletStateImpl implements InternalWalletState {
+export class InternalWalletState {
cryptoApi: TalerCryptoInterface;
cryptoDispatcher: CryptoDispatcher;
- merchantInfoCache: Record<string, MerchantInfo> = {};
-
readonly timerGroup: TimerGroup;
workAvailable = new AsyncCondition();
stopped = false;
- listeners: NotificationListener[] = [];
+ private listeners: NotificationListener[] = [];
initCalled = false;
- recoupOps: RecoupOperations = {
- createRecoupGroup,
- };
-
// FIXME: Use an LRU cache here.
private denomCache: Record<string, DenominationInfo> = {};
@@ -1621,7 +1613,7 @@ class InternalWalletStateImpl implements InternalWalletState {
async getDenomInfo(
ws: InternalWalletState,
- tx: WalletDbReadWriteTransaction<["denominations"]>,
+ tx: WalletDbReadOnlyTransaction<["denominations"]>,
exchangeBaseUrl: string,
denomPubHash: string,
): Promise<DenominationInfo | undefined> {
diff --git a/packages/taler-wallet-core/src/withdraw.ts b/packages/taler-wallet-core/src/withdraw.ts
index b34ad521d..391fbc9e2 100644
--- a/packages/taler-wallet-core/src/withdraw.ts
+++ b/packages/taler-wallet-core/src/withdraw.ts
@@ -128,7 +128,6 @@ import {
listExchanges,
markExchangeUsed,
} from "./exchanges.js";
-import { InternalWalletState } from "./internal-wallet-state.js";
import { DbAccess } from "./query.js";
import {
TransitionInfo,
@@ -146,6 +145,7 @@ import {
WALLET_BANK_INTEGRATION_PROTOCOL_VERSION,
WALLET_EXCHANGE_PROTOCOL_VERSION,
} from "./versions.js";
+import type { InternalWalletState } from "./wallet.js";
/**
* Logger for this file.