taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit fd7f997d3d28448e0de07d3f35c7211368838b30
parent 392d95a9cebf57e34ac81b1ec86d79828e0996cc
Author: Florian Dold <dold@taler.net>
Date:   Wed, 19 Aug 2026 22:19:29 +0200

wallet-core: report database backend during initialization

Diffstat:
Mpackages/taler-util/src/types-taler-wallet.ts | 5+++++
Mpackages/taler-wallet-core/src/requests.test.ts | 45++++++++++++++++++++++++++++++++++++++++++++-
Mpackages/taler-wallet-core/src/requests.ts | 6++++++
3 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/packages/taler-util/src/types-taler-wallet.ts b/packages/taler-util/src/types-taler-wallet.ts @@ -615,8 +615,13 @@ export const codecForInitRequest = (): Codec<InitRequest> => .property("config", codecForAny()) .build("InitRequest"); +export type WalletDatabaseBackend = "indexeddb" | "sqlite"; + export interface InitResponse { versionInfo: WalletCoreVersion; + + /** Database backend used by the initialized wallet. */ + databaseBackend: WalletDatabaseBackend; } /** diff --git a/packages/taler-wallet-core/src/requests.test.ts b/packages/taler-wallet-core/src/requests.test.ts @@ -24,7 +24,9 @@ import { TalerError, TalerErrorCode, TalerPreciseTimestamp, + SetTimeoutTimerAPI, } from "@gnu-taler/taler-util"; +import { HttpRequestLibrary } from "@gnu-taler/taler-util/http"; import { ConfigRecord, @@ -35,13 +37,54 @@ import { timestampPreciseToDb, } from "./db-common.js"; import { WalletDbTransaction } from "./dbtx.js"; +import { makeIdbRunner, makeSqliteRunner } from "./dbtx-runners.js"; import { markExchangeAddedByUser } from "./exchanges.js"; +import { SynchronousCryptoWorkerFactoryPlain } from "./crypto/workers/synchronousWorkerFactoryPlain.js"; import { handleGetDefaultExchanges, handleHintApplicationResumed, handleListWithdrawalExchangeCandidates, } from "./requests.js"; -import { WalletExecutionContext } from "./wallet.js"; +import { WalletApiOperation } from "./wallet-api-types.js"; +import { Wallet, WalletExecutionContext } from "./wallet.js"; + +const backendCases = [ + ["indexeddb", makeIdbRunner], + ["sqlite", makeSqliteRunner], +] as const; + +for (const [expectedBackend, makeRunner] of backendCases) { + test(`init response reports the ${expectedBackend} database backend`, async () => { + const db = await makeRunner(); + const http = { + async fetch(): Promise<never> { + throw Error("unexpected HTTP request"); + }, + } as HttpRequestLibrary; + const wallet = await Wallet.create( + db, + () => http, + new SetTimeoutTimerAPI(), + new SynchronousCryptoWorkerFactoryPlain(), + ); + let initialized = false; + try { + const response = await wallet.client.call(WalletApiOperation.InitWallet, { + config: { + lazyTaskLoop: true, + testing: { skipDefaults: true }, + }, + }); + initialized = true; + assert.strictEqual(response.databaseBackend, expectedBackend); + } finally { + if (initialized) { + await wallet.client.call(WalletApiOperation.Shutdown, {}); + } + await db.close(); + } + }); +} interface TestContext { wex: WalletExecutionContext; diff --git a/packages/taler-wallet-core/src/requests.ts b/packages/taler-wallet-core/src/requests.ts @@ -986,8 +986,14 @@ async function handleSetWalletRunConfig( await deleteEphemeralExchanges(wex); } + const databaseBackend = wex.ws.db.name; + checkDbInvariant( + databaseBackend === "indexeddb" || databaseBackend === "sqlite", + `unknown wallet database backend: ${databaseBackend}`, + ); const resp: InitResponse = { versionInfo: await handleGetVersion(wex), + databaseBackend, }; if (req.config?.lazyTaskLoop) {