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) => { backupCli.subcommand("importDb", "import-db").action(async (args) => {
await withWallet(args, async (wallet) => { await withWallet(args, async (wallet) => {
const dumpRaw = await read(process.stdin); 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"; 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"; export const CURRENT_DB_CONFIG_KEY = "currentMainDbName";
/** /**
@ -2773,15 +2778,10 @@ export interface StoredBackupMeta {
name: string; name: string;
} }
export interface StoredBackupData {
name: string;
data: any;
}
export const StoredBackupStores = { export const StoredBackupStores = {
backupMeta: describeStore( backupMeta: describeStore(
"backupMeta", "backupMeta",
describeContents<MetaConfigRecord>({ keyPath: "name" }), describeContents<StoredBackupMeta>({ keyPath: "name" }),
{}, {},
), ),
backupData: describeStore("backupData", describeContents<any>({}), {}), backupData: describeStore("backupData", describeContents<any>({}), {}),
@ -3250,7 +3250,7 @@ export async function openStoredBackupsDatabase(
): Promise<DbAccess<typeof StoredBackupStores>> { ): Promise<DbAccess<typeof StoredBackupStores>> {
const backupsDbHandle = await openDatabase( const backupsDbHandle = await openDatabase(
idbFactory, idbFactory,
TALER_WALLET_META_DB_NAME, TALER_WALLET_STORED_BACKUPS_DB_NAME,
1, 1,
() => {}, () => {},
onStoredBackupsDbUpgradeNeeded, onStoredBackupsDbUpgradeNeeded,

View File

@ -376,8 +376,8 @@ export interface InsertResponse {
export interface StoreReadWriteAccessor<RecordType, IndexMap> { export interface StoreReadWriteAccessor<RecordType, IndexMap> {
get(key: IDBValidKey): Promise<RecordType | undefined>; get(key: IDBValidKey): Promise<RecordType | undefined>;
iter(query?: IDBValidKey): ResultStream<RecordType>; iter(query?: IDBValidKey): ResultStream<RecordType>;
put(r: RecordType): Promise<InsertResponse>; put(r: RecordType, key?: IDBValidKey): Promise<InsertResponse>;
add(r: RecordType): Promise<InsertResponse>; add(r: RecordType, key?: IDBValidKey): Promise<InsertResponse>;
delete(key: IDBValidKey): Promise<void>; delete(key: IDBValidKey): Promise<void>;
indexes: GetIndexReadWriteAccess<RecordType, IndexMap>; indexes: GetIndexReadWriteAccess<RecordType, IndexMap>;
} }
@ -652,15 +652,15 @@ function makeWriteContext(
const req = tx.objectStore(storeName).openCursor(query); const req = tx.objectStore(storeName).openCursor(query);
return new ResultStream<any>(req); return new ResultStream<any>(req);
}, },
async add(r) { async add(r, k) {
const req = tx.objectStore(storeName).add(r); const req = tx.objectStore(storeName).add(r, k);
const key = await requestToPromise(req); const key = await requestToPromise(req);
return { return {
key: key, key: key,
}; };
}, },
async put(r) { async put(r, k) {
const req = tx.objectStore(storeName).put(r); const req = tx.objectStore(storeName).put(r, k);
const key = await requestToPromise(req); const key = await requestToPromise(req);
return { return {
key: key, key: key,

View File

@ -343,9 +343,8 @@ async function callOperationHandler(
return await processRecoupGroup(ws, pending.recoupGroupId); return await processRecoupGroup(ws, pending.recoupGroupId);
case PendingTaskType.ExchangeCheckRefresh: case PendingTaskType.ExchangeCheckRefresh:
return await autoRefresh(ws, pending.exchangeBaseUrl); return await autoRefresh(ws, pending.exchangeBaseUrl);
case PendingTaskType.Deposit: { case PendingTaskType.Deposit:
return await processDepositGroup(ws, pending.depositGroupId); return await processDepositGroup(ws, pending.depositGroupId);
}
case PendingTaskType.Backup: case PendingTaskType.Backup:
return await processBackupForProvider(ws, pending.backupProviderBaseUrl); return await processBackupForProvider(ws, pending.backupProviderBaseUrl);
case PendingTaskType.PeerPushDebit: case PendingTaskType.PeerPushDebit:
@ -1031,9 +1030,15 @@ async function createStoredBackup(
const backup = await exportDb(ws.idb); const backup = await exportDb(ws.idb);
const backupsDb = await openStoredBackupsDatabase(ws.idb); const backupsDb = await openStoredBackupsDatabase(ws.idb);
const name = `backup-${new Date().getTime()}`; const name = `backup-${new Date().getTime()}`;
backupsDb.mktxAll().runReadWrite(async (tx) => {}); await backupsDb.mktxAll().runReadWrite(async (tx) => {
await tx.backupMeta.add({
throw Error("not implemented"); 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. * Handle a request to the wallet-core API.
*/ */
export async function handleCoreApiRequest( async function handleCoreApiRequest(
ws: InternalWalletState, ws: InternalWalletState,
operation: string, operation: string,
id: string, id: string,
@ -1849,11 +1854,8 @@ class InternalWalletStateImpl implements InternalWalletState {
if (this._db) { if (this._db) {
return; return;
} }
const myVersionChange = (): Promise<void> => { const myVersionChange = async (): Promise<void> => {
logger.error("version change requested, should not happen"); logger.info("version change requested for Taler DB");
throw Error(
"BUG: wallet DB version change event can't happen with memory IDB",
);
}; };
const myDb = await openTalerDatabase(this.idb, myVersionChange); const myDb = await openTalerDatabase(this.idb, myVersionChange);
this._db = myDb; this._db = myDb;

View File

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