summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2024-03-27 19:45:16 +0100
committerFlorian Dold <florian@dold.me>2024-03-27 19:45:16 +0100
commite0f4f29bc99372c22b6c1bfa09dcba2d85f3b608 (patch)
tree704bbca22ebe2a30dd98f7e5f719b49d3d8d985e /packages
parentbe0f21389bb2c206344ed9c4f78c72ae84d5548d (diff)
downloadwallet-core-e0f4f29bc99372c22b6c1bfa09dcba2d85f3b608.tar.gz
wallet-core-e0f4f29bc99372c22b6c1bfa09dcba2d85f3b608.tar.bz2
wallet-core-e0f4f29bc99372c22b6c1bfa09dcba2d85f3b608.zip
wallet-core: purge other database tables when purging an exchange
Diffstat (limited to 'packages')
-rw-r--r--packages/taler-wallet-core/src/db.ts5
-rw-r--r--packages/taler-wallet-core/src/exchanges.ts102
2 files changed, 94 insertions, 13 deletions
diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts
index 92cf63ae1..a587363c5 100644
--- a/packages/taler-wallet-core/src/db.ts
+++ b/packages/taler-wallet-core/src/db.ts
@@ -149,7 +149,7 @@ export const CURRENT_DB_CONFIG_KEY = "currentMainDbName";
* backwards-compatible way or object stores and indices
* are added.
*/
-export const WALLET_DB_MINOR_VERSION = 7;
+export const WALLET_DB_MINOR_VERSION = 8;
declare const symDbProtocolTimestamp: unique symbol;
@@ -2420,6 +2420,9 @@ export const WalletStoresV1 = {
"maxAge",
"freshCoinCount",
]),
+ byExchangeBaseUrl: describeIndex("byExchangeBaseUrl", "exchangeBaseUrl", {
+ versionAdded: 8,
+ }),
},
),
coins: describeStore(
diff --git a/packages/taler-wallet-core/src/exchanges.ts b/packages/taler-wallet-core/src/exchanges.ts
index 152bc76ce..91d436100 100644
--- a/packages/taler-wallet-core/src/exchanges.ts
+++ b/packages/taler-wallet-core/src/exchanges.ts
@@ -2093,6 +2093,84 @@ async function internalGetExchangeResources(
};
}
+async function purgeExchange(
+ tx: WalletDbReadWriteTransaction<
+ [
+ "exchanges",
+ "exchangeDetails",
+ "transactions",
+ "coinAvailability",
+ "coins",
+ "denominations",
+ "exchangeSignKeys",
+ "withdrawalGroups",
+ "planchets",
+ ]
+ >,
+ exchangeBaseUrl: string,
+): Promise<void> {
+ const detRecs = await tx.exchangeDetails.indexes.byExchangeBaseUrl.getAll();
+ for (const r of detRecs) {
+ if (r.rowId == null) {
+ // Should never happen, as rowId is the primary key.
+ continue;
+ }
+ await tx.exchangeDetails.delete(r.rowId);
+ const signkeyRecs =
+ await tx.exchangeSignKeys.indexes.byExchangeDetailsRowId.getAll(r.rowId);
+ for (const rec of signkeyRecs) {
+ await tx.exchangeSignKeys.delete([r.rowId, rec.signkeyPub]);
+ }
+ }
+ // FIXME: Also remove records related to transactions?
+ await tx.exchanges.delete(exchangeBaseUrl);
+
+ {
+ const coinAvailabilityRecs =
+ await tx.coinAvailability.indexes.byExchangeBaseUrl.getAll(
+ exchangeBaseUrl,
+ );
+ for (const rec of coinAvailabilityRecs) {
+ await tx.coinAvailability.delete([
+ exchangeBaseUrl,
+ rec.denomPubHash,
+ rec.maxAge,
+ ]);
+ }
+ }
+
+ {
+ const coinRecs = await tx.coins.indexes.byBaseUrl.getAll(exchangeBaseUrl);
+ for (const rec of coinRecs) {
+ await tx.coins.delete(rec.coinPub);
+ }
+ }
+
+ {
+ const denomRecs =
+ await tx.denominations.indexes.byExchangeBaseUrl.getAll(exchangeBaseUrl);
+ for (const rec of denomRecs) {
+ await tx.denominations.delete(rec.denomPubHash);
+ }
+ }
+
+ {
+ const withdrawalGroupRecs =
+ await tx.withdrawalGroups.indexes.byExchangeBaseUrl.getAll(
+ exchangeBaseUrl,
+ );
+ for (const wg of withdrawalGroupRecs) {
+ await tx.withdrawalGroups.delete(wg.withdrawalGroupId);
+ const planchets = await tx.planchets.indexes.byGroup.getAll(
+ wg.withdrawalGroupId,
+ );
+ for (const p of planchets) {
+ await tx.planchets.delete(p.coinPub);
+ }
+ }
+ }
+}
+
export async function deleteExchange(
wex: WalletExecutionContext,
req: DeleteExchangeRequest,
@@ -2100,7 +2178,17 @@ export async function deleteExchange(
let inUse: boolean = false;
const exchangeBaseUrl = canonicalizeBaseUrl(req.exchangeBaseUrl);
await wex.db.runReadWriteTx(
- ["exchanges", "coins", "withdrawalGroups", "exchangeDetails"],
+ [
+ "exchanges",
+ "exchangeDetails",
+ "transactions",
+ "coinAvailability",
+ "coins",
+ "denominations",
+ "exchangeSignKeys",
+ "withdrawalGroups",
+ "planchets",
+ ],
async (tx) => {
const exchangeRec = await tx.exchanges.get(exchangeBaseUrl);
if (!exchangeRec) {
@@ -2113,17 +2201,7 @@ export async function deleteExchange(
inUse = true;
return;
}
- const detRecs =
- await tx.exchangeDetails.indexes.byExchangeBaseUrl.getAll();
- for (const r of detRecs) {
- if (r.rowId == null) {
- // Should never happen, as rowId is the primary key.
- continue;
- }
- await tx.exchangeDetails.delete(r.rowId);
- }
- // FIXME: Also remove records related to transactions?
- await tx.exchanges.delete(exchangeBaseUrl);
+ await purgeExchange(tx, exchangeBaseUrl);
},
);