commit 86efee05f4f96995f7aad16e6b31c57525deef8a
parent 846b1e7ec1ec7099ea2d8654f6f0d2655cfae802
Author: Florian Dold <dold@taler.net>
Date: Mon, 23 Nov 2026 23:16:32 +0100
wallet-core: report refund deletions and recoup state changes
Queue the transition in the transaction that deletes a refund or
suspends, resumes, or deletes a recoup. Listeners then see the change
after commit, including when a refund is deleted by another operation.
Diffstat:
4 files changed, 51 insertions(+), 28 deletions(-)
diff --git a/packages/taler-wallet-core/src/observe-transaction.test.ts b/packages/taler-wallet-core/src/observe-transaction.test.ts
@@ -57,6 +57,7 @@ import {
} from "./observe-transaction.js";
import { PeerPushCreditTransactionContext } from "./pay-peer-push-credit.js";
import { dispatchRequestInternal } from "./requests.js";
+import { RefundTransactionContext } from "./pay-merchant.js";
import { TaskSchedulerImpl } from "./shepherd.js";
import {
constructTransactionIdentifier,
@@ -1481,7 +1482,10 @@ for (const makeRunner of runnerFactories) {
resolve();
});
});
- await f.wex.runWalletDbTx((tx) => tx.deleteRefundGroup("refund"));
+ await new RefundTransactionContext(
+ f.wex,
+ "refund",
+ ).userDeleteTransaction();
await f.settle();
await deleted;
const deletedPayment = f.nextSnapshot(
diff --git a/packages/taler-wallet-core/src/pay-merchant.ts b/packages/taler-wallet-core/src/pay-merchant.ts
@@ -111,7 +111,6 @@ import {
TimerHandle,
UnclaimPaymentResult,
URL,
- WalletNotification,
} from "@gnu-taler/taler-util";
import {
getHttpResponseErrorDetails,
@@ -1003,21 +1002,13 @@ export class RefundTransactionContext implements TransactionContext {
async userDeleteTransaction(): Promise<void> {
const { wex } = this;
- const res = await wex.runWalletDbTx(async (tx) => {
- return await this.deleteTransactionInTx(tx);
- });
- for (const notif of res.notifs) {
- this.wex.ws.notify(notif);
- }
+ await wex.runWalletDbTx((tx) => this.deleteTransactionInTx(tx));
}
- async deleteTransactionInTx(
- tx: WalletDbTransaction,
- ): Promise<{ notifs: WalletNotification[] }> {
- const notifs: WalletNotification[] = [];
+ async deleteTransactionInTx(tx: WalletDbTransaction): Promise<void> {
const refundRecord = await tx.getRefundGroup(this.refundGroupId);
if (!refundRecord) {
- return { notifs };
+ return;
}
await tx.deleteRefundGroup(this.refundGroupId);
await this.updateTransactionMeta(tx);
@@ -1028,7 +1019,14 @@ export class RefundTransactionContext implements TransactionContext {
await tx.deleteRefundItem(item.id);
}
}
- return { notifs };
+ tx.notify({
+ type: NotificationType.TransactionStateTransition,
+ causeHint: "delete",
+ transactionId: this.transactionId,
+ oldTxState: computeRefundTransactionState(refundRecord),
+ newTxState: { major: TransactionMajorState.Deleted },
+ newStId: -1,
+ });
}
userSuspendTransaction(): Promise<void> {
diff --git a/packages/taler-wallet-core/src/recoup.test.ts b/packages/taler-wallet-core/src/recoup.test.ts
@@ -823,10 +823,15 @@ test("deleting recoup history does not requeue credited, rejected or reward coin
] as R.WalletCoin[];
let deleted = false;
const tx = {
+ notify: () => {},
getRecoupGroup: async () =>
deleted
? undefined
- : { recoupGroupId: "old-recoup", failedCoinPubs: ["rejected"] },
+ : {
+ recoupGroupId: "old-recoup",
+ operationStatus: R.RecoupOperationStatus.Failed,
+ failedCoinPubs: ["rejected"],
+ },
deleteRecoupGroup: async () => {
deleted = true;
},
diff --git a/packages/taler-wallet-core/src/recoup.ts b/packages/taler-wallet-core/src/recoup.ts
@@ -52,7 +52,6 @@ import {
TransactionMajorState,
TransactionState,
TransactionType,
- WalletNotification,
NotificationType,
checkDbInvariant,
encodeCrock,
@@ -756,9 +755,18 @@ export class RecoupTransactionContext implements TransactionContext {
if (rec?.operationStatus !== RecoupOperationStatus.Pending) {
return;
}
+ const oldTxState = computeRecoupTransactionState(rec);
rec.operationStatus = RecoupOperationStatus.Suspended;
await tx.upsertRecoupGroup(rec);
await this.updateTransactionMeta(tx);
+ tx.notify({
+ type: NotificationType.TransactionStateTransition,
+ causeHint: "suspend",
+ transactionId: this.transactionId,
+ oldTxState,
+ newTxState: computeRecoupTransactionState(rec),
+ newStId: rec.operationStatus,
+ });
});
this.wex.taskScheduler.stopShepherdTask(this.taskId);
}
@@ -769,9 +777,18 @@ export class RecoupTransactionContext implements TransactionContext {
if (rec?.operationStatus !== RecoupOperationStatus.Suspended) {
return;
}
+ const oldTxState = computeRecoupTransactionState(rec);
rec.operationStatus = RecoupOperationStatus.Pending;
await tx.upsertRecoupGroup(rec);
await this.updateTransactionMeta(tx);
+ tx.notify({
+ type: NotificationType.TransactionStateTransition,
+ causeHint: "resume",
+ transactionId: this.transactionId,
+ oldTxState,
+ newTxState: computeRecoupTransactionState(rec),
+ newStId: rec.operationStatus,
+ });
});
await this.wex.taskScheduler.resetTask(this.taskId);
}
@@ -781,21 +798,13 @@ export class RecoupTransactionContext implements TransactionContext {
}
async userDeleteTransaction(): Promise<void> {
- const res = await this.wex.runWalletDbTx(async (tx) => {
- return this.deleteTransactionInTx(tx);
- });
- for (const notif of res.notifs) {
- this.wex.ws.notify(notif);
- }
+ await this.wex.runWalletDbTx((tx) => this.deleteTransactionInTx(tx));
}
- async deleteTransactionInTx(
- tx: WalletDbTransaction,
- ): Promise<{ notifs: WalletNotification[] }> {
- const notifs: WalletNotification[] = [];
+ async deleteTransactionInTx(tx: WalletDbTransaction): Promise<void> {
const rec = await tx.getRecoupGroup(this.recoupGroupId);
if (!rec) {
- return { notifs };
+ return;
}
// Retain terminal rejections even when deleting a pre-upgrade group.
for (const coin of await tx.getCoinsByPubs(rec.failedCoinPubs ?? [])) {
@@ -806,7 +815,14 @@ export class RecoupTransactionContext implements TransactionContext {
}
await tx.deleteRecoupGroup(this.recoupGroupId);
await this.updateTransactionMeta(tx);
- return { notifs };
+ tx.notify({
+ type: NotificationType.TransactionStateTransition,
+ causeHint: "delete",
+ transactionId: this.transactionId,
+ oldTxState: computeRecoupTransactionState(rec),
+ newTxState: { major: TransactionMajorState.Deleted },
+ newStId: -1,
+ });
}
async lookupFullTransaction(