gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] 01/04: importDb feature in wallet core


From: gnunet
Subject: [taler-wallet-core] 01/04: importDb feature in wallet core
Date: Thu, 13 Jan 2022 05:34:27 +0100

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

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

commit 5eeb00e158ee5908bb4b62374f43e35d1a5f1a49
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Thu Jan 13 01:30:26 2022 -0300

    importDb feature in wallet core
---
 packages/taler-wallet-core/src/db.ts | 51 +++++++++++++++++++++++++++---------
 1 file changed, 39 insertions(+), 12 deletions(-)

diff --git a/packages/taler-wallet-core/src/db.ts 
b/packages/taler-wallet-core/src/db.ts
index 0b2d16ae..c3d67d7c 100644
--- a/packages/taler-wallet-core/src/db.ts
+++ b/packages/taler-wallet-core/src/db.ts
@@ -1294,9 +1294,9 @@ export const WALLET_BACKUP_STATE_KEY = 
"walletBackupState";
  */
 export type ConfigRecord =
   | {
-      key: typeof WALLET_BACKUP_STATE_KEY;
-      value: WalletBackupConfState;
-    }
+    key: typeof WALLET_BACKUP_STATE_KEY;
+    value: WalletBackupConfState;
+  }
   | { key: "currencyDefaultsApplied"; value: boolean };
 
 export interface WalletBackupConfState {
@@ -1480,17 +1480,17 @@ export enum BackupProviderStateTag {
 
 export type BackupProviderState =
   | {
-      tag: BackupProviderStateTag.Provisional;
-    }
+    tag: BackupProviderStateTag.Provisional;
+  }
   | {
-      tag: BackupProviderStateTag.Ready;
-      nextBackupTimestamp: Timestamp;
-    }
+    tag: BackupProviderStateTag.Ready;
+    nextBackupTimestamp: Timestamp;
+  }
   | {
-      tag: BackupProviderStateTag.Retrying;
-      retryInfo: RetryInfo;
-      lastError?: TalerErrorDetails;
-    };
+    tag: BackupProviderStateTag.Retrying;
+    retryInfo: RetryInfo;
+    lastError?: TalerErrorDetails;
+  };
 
 export interface BackupProviderTerms {
   supportedProtocolVersion: string;
@@ -1873,3 +1873,30 @@ export function exportDb(db: IDBDatabase): Promise<any> {
     }
   });
 }
+
+export interface DatabaseDump {
+  name: string,
+  stores: { [s: string]: any },
+  version: string,
+}
+
+export function importDb(db: IDBDatabase, dump: DatabaseDump): Promise<any> {
+  return new Promise((resolve, reject) => {
+    const tx = db.transaction(Array.from(db.objectStoreNames), "readwrite");
+    tx.addEventListener("complete", () => {
+      tx.commit();
+      resolve(db);
+    });
+    for (let i = 0; i < db.objectStoreNames.length; i++) {
+      const name = db.objectStoreNames[i];
+      const storeDump = dump.stores[name];
+      if (!storeDump) continue;
+      Object.keys(storeDump).forEach(async key => {
+        const value = storeDump[key]
+        if (!value) return;
+        tx.objectStore(name).put(value)
+      })
+
+    }
+  });
+}

-- 
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]