aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/wallet.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-core/src/wallet.ts')
-rw-r--r--packages/taler-wallet-core/src/wallet.ts19
1 files changed, 18 insertions, 1 deletions
diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts
index 5a6cfb96b..dfe7b2395 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -49,6 +49,7 @@ import {
StoredBackupList,
TalerError,
TalerErrorCode,
+ TalerProtocolTimestamp,
TalerUriAction,
TestingWaitTransactionRequest,
TimerAPI,
@@ -168,6 +169,7 @@ import {
importDb,
openStoredBackupsDatabase,
openTalerDatabase,
+ timestampProtocolToDb,
} from "./db.js";
import {
computeDepositTransactionStatus,
@@ -646,6 +648,21 @@ async function dispatchRequestInternal<Op extends WalletApiOperation>(
}
case WalletApiOperation.InitWallet: {
logger.trace("initializing wallet");
+ // Write to the DB to make sure that we're failing early in
+ // case the DB is not writeable.
+ try {
+ await ws.db.runReadWriteTx(["config"], async (tx) => {
+ tx.config.put({
+ key: ConfigRecordKey.LastInitInfo,
+ value: timestampProtocolToDb(TalerProtocolTimestamp.now()),
+ });
+ });
+ } catch (e) {
+ logger.error("error writing to database during initialization");
+ throw TalerError.fromDetail(TalerErrorCode.WALLET_DB_UNAVAILABLE, {
+ innerError: getErrorDetailFromException(e),
+ });
+ }
ws.initCalled = true;
if (ws.config.testing.skipDefaults) {
logger.trace("skipping defaults");
@@ -1324,8 +1341,8 @@ async function handleCoreApiRequest(
id: string,
payload: unknown,
): Promise<CoreApiResponse> {
- await ws.ensureWalletDbOpen();
try {
+ await ws.ensureWalletDbOpen();
const result = await dispatchRequestInternal(ws, operation as any, payload);
return {
type: "response",