gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] branch master updated: wallet-core: purge other data


From: gnunet
Subject: [taler-wallet-core] branch master updated: wallet-core: purge other database tables when purging an exchange
Date: Wed, 27 Mar 2024 19:45:20 +0100

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository wallet-core.

The following commit(s) were added to refs/heads/master by this push:
     new e0f4f29bc wallet-core: purge other database tables when purging an 
exchange
e0f4f29bc is described below

commit e0f4f29bc99372c22b6c1bfa09dcba2d85f3b608
Author: Florian Dold <florian@dold.me>
AuthorDate: Wed Mar 27 19:45:16 2024 +0100

    wallet-core: purge other database tables when purging an exchange
---
 packages/taler-wallet-core/src/db.ts        |   5 +-
 packages/taler-wallet-core/src/exchanges.ts | 102 ++++++++++++++++++++++++----
 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);
     },
   );
 

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]