aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2023-08-30 18:33:56 +0200
committerFlorian Dold <florian@dold.me>2023-08-30 18:33:56 +0200
commit8fed5b4b7370431602c0b25f8142009e61f7b906 (patch)
tree3f188e815eb56e9d69ef1ef7fe6da663a8d8e2e5
parenta713d90c3c564408309d92223d383ecc9225924f (diff)
wallet-core: allow version change event
-rw-r--r--packages/taler-wallet-cli/src/index.ts10
-rw-r--r--packages/taler-wallet-core/src/db.ts14
-rw-r--r--packages/taler-wallet-core/src/util/query.ts12
-rw-r--r--packages/taler-wallet-core/src/wallet.ts24
-rw-r--r--packages/taler-wallet-webextension/src/wxBackend.ts1
5 files changed, 36 insertions, 25 deletions
diff --git a/packages/taler-wallet-cli/src/index.ts b/packages/taler-wallet-cli/src/index.ts
index 9652f84f3..36e7f7768 100644
--- a/packages/taler-wallet-cli/src/index.ts
+++ b/packages/taler-wallet-cli/src/index.ts
@@ -883,6 +883,16 @@ backupCli.subcommand("exportDb", "export-db").action(async (args) => {
});
});
+backupCli.subcommand("storeBackup", "store-backup").action(async (args) => {
+ await withWallet(args, async (wallet) => {
+ const resp = await wallet.client.call(
+ WalletApiOperation.CreateStoredBackup,
+ {},
+ );
+ console.log(JSON.stringify(resp, undefined, 2));
+ });
+});
+
backupCli.subcommand("importDb", "import-db").action(async (args) => {
await withWallet(args, async (wallet) => {
const dumpRaw = await read(process.stdin);
diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts
index 1255e8c71..a642c0203 100644
--- a/packages/taler-wallet-core/src/db.ts
+++ b/packages/taler-wallet-core/src/db.ts
@@ -114,6 +114,11 @@ export const TALER_WALLET_MAIN_DB_NAME = "taler-wallet-main-v9";
*/
export const TALER_WALLET_META_DB_NAME = "taler-wallet-meta";
+/**
+ * Stored backups, mainly created when manually importing a backup.
+ */
+export const TALER_WALLET_STORED_BACKUPS_DB_NAME = "taler-wallet-stored-backups";
+
export const CURRENT_DB_CONFIG_KEY = "currentMainDbName";
/**
@@ -2773,15 +2778,10 @@ export interface StoredBackupMeta {
name: string;
}
-export interface StoredBackupData {
- name: string;
- data: any;
-}
-
export const StoredBackupStores = {
backupMeta: describeStore(
"backupMeta",
- describeContents<MetaConfigRecord>({ keyPath: "name" }),
+ describeContents<StoredBackupMeta>({ keyPath: "name" }),
{},
),
backupData: describeStore("backupData", describeContents<any>({}), {}),
@@ -3250,7 +3250,7 @@ export async function openStoredBackupsDatabase(
): Promise<DbAccess<typeof StoredBackupStores>> {
const backupsDbHandle = await openDatabase(
idbFactory,
- TALER_WALLET_META_DB_NAME,
+ TALER_WALLET_STORED_BACKUPS_DB_NAME,
1,
() => {},
onStoredBackupsDbUpgradeNeeded,
diff --git a/packages/taler-wallet-core/src/util/query.ts b/packages/taler-wallet-core/src/util/query.ts
index eb2bddec1..7697ed3db 100644
--- a/packages/taler-wallet-core/src/util/query.ts
+++ b/packages/taler-wallet-core/src/util/query.ts
@@ -376,8 +376,8 @@ export interface InsertResponse {
export interface StoreReadWriteAccessor<RecordType, IndexMap> {
get(key: IDBValidKey): Promise<RecordType | undefined>;
iter(query?: IDBValidKey): ResultStream<RecordType>;
- put(r: RecordType): Promise<InsertResponse>;
- add(r: RecordType): Promise<InsertResponse>;
+ put(r: RecordType, key?: IDBValidKey): Promise<InsertResponse>;
+ add(r: RecordType, key?: IDBValidKey): Promise<InsertResponse>;
delete(key: IDBValidKey): Promise<void>;
indexes: GetIndexReadWriteAccess<RecordType, IndexMap>;
}
@@ -652,15 +652,15 @@ function makeWriteContext(
const req = tx.objectStore(storeName).openCursor(query);
return new ResultStream<any>(req);
},
- async add(r) {
- const req = tx.objectStore(storeName).add(r);
+ async add(r, k) {
+ const req = tx.objectStore(storeName).add(r, k);
const key = await requestToPromise(req);
return {
key: key,
};
},
- async put(r) {
- const req = tx.objectStore(storeName).put(r);
+ async put(r, k) {
+ const req = tx.objectStore(storeName).put(r, k);
const key = await requestToPromise(req);
return {
key: key,
diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts
index 283539a08..626409dd6 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -343,9 +343,8 @@ async function callOperationHandler(
return await processRecoupGroup(ws, pending.recoupGroupId);
case PendingTaskType.ExchangeCheckRefresh:
return await autoRefresh(ws, pending.exchangeBaseUrl);
- case PendingTaskType.Deposit: {
+ case PendingTaskType.Deposit:
return await processDepositGroup(ws, pending.depositGroupId);
- }
case PendingTaskType.Backup:
return await processBackupForProvider(ws, pending.backupProviderBaseUrl);
case PendingTaskType.PeerPushDebit:
@@ -1031,9 +1030,15 @@ async function createStoredBackup(
const backup = await exportDb(ws.idb);
const backupsDb = await openStoredBackupsDatabase(ws.idb);
const name = `backup-${new Date().getTime()}`;
- backupsDb.mktxAll().runReadWrite(async (tx) => {});
-
- throw Error("not implemented");
+ await backupsDb.mktxAll().runReadWrite(async (tx) => {
+ await tx.backupMeta.add({
+ name,
+ });
+ await tx.backupData.add(backup, name);
+ });
+ return {
+ name,
+ };
}
/**
@@ -1634,7 +1639,7 @@ export function getVersion(ws: InternalWalletState): WalletCoreVersion {
/**
* Handle a request to the wallet-core API.
*/
-export async function handleCoreApiRequest(
+async function handleCoreApiRequest(
ws: InternalWalletState,
operation: string,
id: string,
@@ -1849,11 +1854,8 @@ class InternalWalletStateImpl implements InternalWalletState {
if (this._db) {
return;
}
- const myVersionChange = (): Promise<void> => {
- logger.error("version change requested, should not happen");
- throw Error(
- "BUG: wallet DB version change event can't happen with memory IDB",
- );
+ const myVersionChange = async (): Promise<void> => {
+ logger.info("version change requested for Taler DB");
};
const myDb = await openTalerDatabase(this.idb, myVersionChange);
this._db = myDb;
diff --git a/packages/taler-wallet-webextension/src/wxBackend.ts b/packages/taler-wallet-webextension/src/wxBackend.ts
index b7484164d..e7385abe5 100644
--- a/packages/taler-wallet-webextension/src/wxBackend.ts
+++ b/packages/taler-wallet-webextension/src/wxBackend.ts
@@ -50,7 +50,6 @@ import {
exportDb,
importDb,
openPromise,
- openTalerDatabase,
} from "@gnu-taler/taler-wallet-core";
import {
MessageFromBackend,