From 1ec521b9d214b286e747b3ccb3113730ac3a2509 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 19 Feb 2024 12:49:17 +0100 Subject: wallet-core: simplify/unify DB access --- packages/taler-wallet-core/src/shepherd.ts | 62 +++++++++++++++--------------- 1 file changed, 30 insertions(+), 32 deletions(-) (limited to 'packages/taler-wallet-core/src/shepherd.ts') diff --git a/packages/taler-wallet-core/src/shepherd.ts b/packages/taler-wallet-core/src/shepherd.ts index a3735e78f..f9290cdd9 100644 --- a/packages/taler-wallet-core/src/shepherd.ts +++ b/packages/taler-wallet-core/src/shepherd.ts @@ -39,10 +39,9 @@ import { } from "@gnu-taler/taler-util"; import { CryptoApiStoppedError } from "./crypto/workers/crypto-dispatcher.js"; import { - GetReadOnlyAccess, OPERATION_STATUS_ACTIVE_FIRST, OPERATION_STATUS_ACTIVE_LAST, - WalletStoresV1, + WalletDbAllStoresReadOnlyTransaction, timestampAbsoluteFromDb, } from "./index.js"; import { InternalWalletState } from "./internal-wallet-state.js"; @@ -214,12 +213,12 @@ export class TaskScheduler { } async resetTaskRetries(taskId: TaskId): Promise { - const maybeNotification = await this.ws.db - .mktxAll() - .runReadWrite(async (tx) => { + const maybeNotification = await this.ws.db.runAllStoresReadWriteTx( + async (tx) => { await tx.operationRetries.delete(taskId); return taskToRetryNotification(this.ws, tx, taskId, undefined); - }); + }, + ); this.stopShepherdTask(taskId); if (maybeNotification) { this.ws.notify(maybeNotification); @@ -338,7 +337,7 @@ async function storePendingTaskError( e: TalerErrorDetail, ): Promise { logger.info(`storing pending task error for ${pendingTaskId}`); - const maybeNotification = await ws.db.mktxAll().runReadWrite(async (tx) => { + const maybeNotification = await ws.db.runAllStoresReadWriteTx(async (tx) => { let retryRecord = await tx.operationRetries.get(pendingTaskId); if (!retryRecord) { retryRecord = { @@ -365,7 +364,7 @@ async function storeTaskProgress( ws: InternalWalletState, pendingTaskId: string, ): Promise { - await ws.db.mktxAll().runReadWrite(async (tx) => { + await ws.db.runReadWriteTx(["operationRetries"], async (tx) => { await tx.operationRetries.delete(pendingTaskId); }); } @@ -374,7 +373,7 @@ async function storePendingTaskPending( ws: InternalWalletState, pendingTaskId: string, ): Promise { - const maybeNotification = await ws.db.mktxAll().runReadWrite(async (tx) => { + const maybeNotification = await ws.db.runAllStoresReadWriteTx(async (tx) => { let retryRecord = await tx.operationRetries.get(pendingTaskId); let hadError = false; if (!retryRecord) { @@ -405,11 +404,9 @@ async function storePendingTaskFinished( ws: InternalWalletState, pendingTaskId: string, ): Promise { - await ws.db - .mktx((x) => [x.operationRetries]) - .runReadWrite(async (tx) => { - await tx.operationRetries.delete(pendingTaskId); - }); + await ws.db.runReadWriteTx(["operationRetries"], async (tx) => { + await tx.operationRetries.delete(pendingTaskId); + }); } async function runTaskWithErrorReporting( @@ -570,7 +567,7 @@ async function callOperationHandlerForTaskId( */ async function taskToRetryNotification( ws: InternalWalletState, - tx: GetReadOnlyAccess, + tx: WalletDbAllStoresReadOnlyTransaction, pendingTaskId: string, e: TalerErrorDetail | undefined, ): Promise { @@ -597,7 +594,7 @@ async function taskToRetryNotification( async function makeTransactionRetryNotification( ws: InternalWalletState, - tx: GetReadOnlyAccess, + tx: WalletDbAllStoresReadOnlyTransaction, pendingTaskId: string, e: TalerErrorDetail | undefined, ): Promise { @@ -626,7 +623,7 @@ async function makeTransactionRetryNotification( async function makeExchangeRetryNotification( ws: InternalWalletState, - tx: GetReadOnlyAccess, + tx: WalletDbAllStoresReadOnlyTransaction, pendingTaskId: string, e: TalerErrorDetail | undefined, ): Promise { @@ -729,20 +726,20 @@ export async function getActiveTaskIds( const res: ActiveTaskIdsResult = { taskIds: [], }; - await ws.db - .mktx((x) => [ - x.exchanges, - x.refreshGroups, - x.withdrawalGroups, - x.purchases, - x.depositGroups, - x.recoupGroups, - x.peerPullCredit, - x.peerPushDebit, - x.peerPullDebit, - x.peerPushCredit, - ]) - .runReadWrite(async (tx) => { + await ws.db.runReadWriteTx( + [ + "exchanges", + "refreshGroups", + "withdrawalGroups", + "purchases", + "depositGroups", + "recoupGroups", + "peerPullCredit", + "peerPushDebit", + "peerPullDebit", + "peerPushCredit", + ], + async (tx) => { const active = GlobalIDB.KeyRange.bound( OPERATION_STATUS_ACTIVE_FIRST, OPERATION_STATUS_ACTIVE_LAST, @@ -887,7 +884,8 @@ export async function getActiveTaskIds( } // FIXME: Recoup! - }); + }, + ); return res; } -- cgit v1.2.3