diff options
author | Florian Dold <florian@dold.me> | 2024-02-19 12:49:17 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2024-02-19 17:47:35 +0100 |
commit | 1ec521b9d214b286e747b3ccb3113730ac3a2509 (patch) | |
tree | 2f3d2b2906810dca45859b8cbfb8d18d53b27e80 /packages/taler-wallet-core/src/shepherd.ts | |
parent | 1034ecb5f20bd8c75e37e0b4b454ea6c1f4c1da6 (diff) | |
download | wallet-core-1ec521b9d214b286e747b3ccb3113730ac3a2509.tar.gz wallet-core-1ec521b9d214b286e747b3ccb3113730ac3a2509.tar.bz2 wallet-core-1ec521b9d214b286e747b3ccb3113730ac3a2509.zip |
wallet-core: simplify/unify DB access
Diffstat (limited to 'packages/taler-wallet-core/src/shepherd.ts')
-rw-r--r-- | packages/taler-wallet-core/src/shepherd.ts | 62 |
1 files changed, 30 insertions, 32 deletions
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<void> { - 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<void> { 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<void> { - 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<void> { - 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<void> { - 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<typeof WalletStoresV1>, + tx: WalletDbAllStoresReadOnlyTransaction, pendingTaskId: string, e: TalerErrorDetail | undefined, ): Promise<WalletNotification | undefined> { @@ -597,7 +594,7 @@ async function taskToRetryNotification( async function makeTransactionRetryNotification( ws: InternalWalletState, - tx: GetReadOnlyAccess<typeof WalletStoresV1>, + tx: WalletDbAllStoresReadOnlyTransaction, pendingTaskId: string, e: TalerErrorDetail | undefined, ): Promise<WalletNotification | undefined> { @@ -626,7 +623,7 @@ async function makeTransactionRetryNotification( async function makeExchangeRetryNotification( ws: InternalWalletState, - tx: GetReadOnlyAccess<typeof WalletStoresV1>, + tx: WalletDbAllStoresReadOnlyTransaction, pendingTaskId: string, e: TalerErrorDetail | undefined, ): Promise<WalletNotification | undefined> { @@ -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; } |