summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2024-02-13 11:46:34 +0100
committerFlorian Dold <florian@dold.me>2024-02-13 11:46:34 +0100
commit3a62b8522e6b7cb587bbb0c3ce606527e918e06d (patch)
treed680c3fb8f5b86bd80caa440cacfb90a4426bd23
parentc4c89f401431a50a41580aea6b4182277eec7a7f (diff)
downloadwallet-core-3a62b8522e6b7cb587bbb0c3ce606527e918e06d.tar.gz
wallet-core-3a62b8522e6b7cb587bbb0c3ce606527e918e06d.tar.bz2
wallet-core-3a62b8522e6b7cb587bbb0c3ce606527e918e06d.zip
wallet-core: operation status for recoup
-rw-r--r--packages/taler-wallet-core/src/db.ts18
-rw-r--r--packages/taler-wallet-core/src/operations/recoup.ts11
2 files changed, 23 insertions, 6 deletions
diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts
index 705df48b1..3b53bbf35 100644
--- a/packages/taler-wallet-core/src/db.ts
+++ b/packages/taler-wallet-core/src/db.ts
@@ -151,7 +151,7 @@ export const CURRENT_DB_CONFIG_KEY = "currentMainDbName";
* backwards-compatible way or object stores and indices
* are added.
*/
-export const WALLET_DB_MINOR_VERSION = 5;
+export const WALLET_DB_MINOR_VERSION = 6;
declare const symDbProtocolTimestamp: unique symbol;
@@ -1561,6 +1561,14 @@ export interface BankWithdrawUriRecord {
reservePub: string;
}
+export enum RecoupOperationStatus {
+ Pending = 0x0100_0000,
+ Suspended = 0x0110_0000,
+
+ Finished = 0x0500_000,
+ Failed = 0x0501_000,
+}
+
/**
* Status of recoup operations that were grouped together.
*
@@ -1575,6 +1583,8 @@ export interface RecoupGroupRecord {
exchangeBaseUrl: string;
+ operationStatus: RecoupOperationStatus;
+
timestampStarted: DbPreciseTimestamp;
timestampFinished: DbPreciseTimestamp | undefined;
@@ -2471,7 +2481,11 @@ export const WalletStoresV1 = {
describeContents<RecoupGroupRecord>({
keyPath: "recoupGroupId",
}),
- {},
+ {
+ byStatus: describeIndex("byStatus", "operationStatus", {
+ versionAdded: 6,
+ }),
+ },
),
purchases: describeStore(
"purchases",
diff --git a/packages/taler-wallet-core/src/operations/recoup.ts b/packages/taler-wallet-core/src/operations/recoup.ts
index a6270783e..2dd88b614 100644
--- a/packages/taler-wallet-core/src/operations/recoup.ts
+++ b/packages/taler-wallet-core/src/operations/recoup.ts
@@ -43,6 +43,7 @@ import {
CoinRecord,
CoinSourceType,
RecoupGroupRecord,
+ RecoupOperationStatus,
RefreshCoinSource,
WalletStoresV1,
WithdrawCoinSource,
@@ -51,6 +52,7 @@ import {
timestampPreciseToDb,
} from "../db.js";
import { InternalWalletState } from "../internal-wallet-state.js";
+import { PendingTaskType } from "../pending-types.js";
import { checkDbInvariant } from "../util/invariants.js";
import { GetReadWriteAccess } from "../util/query.js";
import {
@@ -59,9 +61,8 @@ import {
constructTaskIdentifier,
} from "./common.js";
import { createRefreshGroup } from "./refresh.js";
-import { internalCreateWithdrawalGroup } from "./withdraw.js";
import { constructTransactionIdentifier } from "./transactions.js";
-import { PendingTaskType } from "../pending-types.js";
+import { internalCreateWithdrawalGroup } from "./withdraw.js";
const logger = new Logger("operations/recoup.ts");
@@ -316,7 +317,7 @@ export async function processRecoupGroup(
}
const ps = recoupGroup.coinPubs.map(async (x, i) => {
try {
- await processRecoup(ws, recoupGroupId, i);
+ await processRecoupForCoin(ws, recoupGroupId, i);
} catch (e) {
logger.warn(`processRecoup failed: ${e}`);
throw e;
@@ -406,6 +407,7 @@ export async function processRecoupGroup(
return;
}
rg2.timestampFinished = timestampPreciseToDb(TalerPreciseTimestamp.now());
+ rg2.operationStatus = RecoupOperationStatus.Finished;
if (rg2.scheduleRefreshCoins.length > 0) {
await createRefreshGroup(
ws,
@@ -479,6 +481,7 @@ export async function createRecoupGroup(
timestampStarted: timestampPreciseToDb(TalerPreciseTimestamp.now()),
recoupFinishedPerCoin: coinPubs.map(() => false),
scheduleRefreshCoins: [],
+ operationStatus: RecoupOperationStatus.Pending,
};
for (let coinIdx = 0; coinIdx < coinPubs.length; coinIdx++) {
@@ -499,7 +502,7 @@ export async function createRecoupGroup(
/**
* Run the recoup protocol for a single coin in a recoup group.
*/
-async function processRecoup(
+async function processRecoupForCoin(
ws: InternalWalletState,
recoupGroupId: string,
coinIdx: number,