wallet-core: allow version change event

This commit is contained in:
Florian Dold 2023-08-30 18:33:56 +02:00
parent a713d90c3c
commit 8fed5b4b73
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
5 changed files with 36 additions and 25 deletions

View File

@ -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);

View File

@ -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,

View File

@ -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,

View File

@ -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;

View File

@ -50,7 +50,6 @@ import {
exportDb,
importDb,
openPromise,
openTalerDatabase,
} from "@gnu-taler/taler-wallet-core";
import {
MessageFromBackend,