aboutsummaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2024-08-27 19:38:31 +0200
committerFlorian Dold <florian@dold.me>2024-08-27 19:38:38 +0200
commit084e4d0d9212ccb2395b4c9b1bea82d4538dd6b8 (patch)
tree625195a8198c5d515fa063ff309d814585df45f5 /packages
parent5310193891283186dc1d03003367192a70e48885 (diff)
wallet-core: do not delete unrelated exchange detals when deleting one exchange
Diffstat (limited to 'packages')
-rw-r--r--packages/taler-wallet-core/src/exchanges.ts68
1 files changed, 25 insertions, 43 deletions
diff --git a/packages/taler-wallet-core/src/exchanges.ts b/packages/taler-wallet-core/src/exchanges.ts
index 7b8e57c8b..fe78c63aa 100644
--- a/packages/taler-wallet-core/src/exchanges.ts
+++ b/packages/taler-wallet-core/src/exchanges.ts
@@ -143,6 +143,7 @@ import {
ReserveRecord,
ReserveRecordStatus,
WalletDbAllStoresReadOnlyTransaction,
+ WalletDbAllStoresReadWriteTransaction,
WalletDbHelpers,
WalletDbReadOnlyTransaction,
WalletDbReadWriteTransaction,
@@ -166,6 +167,7 @@ import { createRefreshGroup } from "./refresh.js";
import {
constructTransactionIdentifier,
notifyTransition,
+ rematerializeTransactions,
} from "./transactions.js";
import { WALLET_EXCHANGE_PROTOCOL_VERSION } from "./versions.js";
import { InternalWalletState, WalletExecutionContext } from "./wallet.js";
@@ -2776,27 +2778,20 @@ async function internalGetExchangeResources(
* but keeps some transactions (payments, p2p, refreshes) around.
*/
async function purgeExchange(
- tx: WalletDbReadWriteTransaction<
- [
- "exchanges",
- "exchangeDetails",
- "transactionsMeta",
- "coinAvailability",
- "coins",
- "denominations",
- "exchangeSignKeys",
- "withdrawalGroups",
- "planchets",
- ]
- >,
+ wex: WalletExecutionContext,
+ tx: WalletDbAllStoresReadWriteTransaction,
exchangeBaseUrl: string,
): Promise<void> {
const detRecs = await tx.exchangeDetails.indexes.byExchangeBaseUrl.getAll();
+ // Remove all exchange detail records for that exchange
for (const r of detRecs) {
if (r.rowId == null) {
// Should never happen, as rowId is the primary key.
continue;
}
+ if (r.exchangeBaseUrl !== exchangeBaseUrl) {
+ continue;
+ }
await tx.exchangeDetails.delete(r.rowId);
const signkeyRecs =
await tx.exchangeSignKeys.indexes.byExchangeDetailsRowId.getAll(r.rowId);
@@ -2851,6 +2846,8 @@ async function purgeExchange(
}
}
}
+
+ await rematerializeTransactions(wex, tx);
}
export async function deleteExchange(
@@ -2859,36 +2856,21 @@ export async function deleteExchange(
): Promise<void> {
let inUse: boolean = false;
const exchangeBaseUrl = req.exchangeBaseUrl;
- await wex.db.runReadWriteTx(
- {
- storeNames: [
- "exchanges",
- "exchangeDetails",
- "transactionsMeta",
- "coinAvailability",
- "coins",
- "denominations",
- "exchangeSignKeys",
- "withdrawalGroups",
- "planchets",
- ],
- },
- async (tx) => {
- const exchangeRec = await tx.exchanges.get(exchangeBaseUrl);
- if (!exchangeRec) {
- // Nothing to delete!
- logger.info("no exchange found to delete");
- return;
- }
- const res = await internalGetExchangeResources(wex, tx, exchangeBaseUrl);
- if (res.hasResources && !req.purge) {
- inUse = true;
- return;
- }
- await purgeExchange(tx, exchangeBaseUrl);
- wex.ws.exchangeCache.clear();
- },
- );
+ await wex.db.runAllStoresReadWriteTx({}, async (tx) => {
+ const exchangeRec = await tx.exchanges.get(exchangeBaseUrl);
+ if (!exchangeRec) {
+ // Nothing to delete!
+ logger.info("no exchange found to delete");
+ return;
+ }
+ const res = await internalGetExchangeResources(wex, tx, exchangeBaseUrl);
+ if (res.hasResources && !req.purge) {
+ inUse = true;
+ return;
+ }
+ await purgeExchange(wex, tx, exchangeBaseUrl);
+ wex.ws.exchangeCache.clear();
+ });
if (inUse) {
throw TalerError.fromUncheckedDetail({