commit fc49a517dabe54831b4292f66ca79930972a2837
parent a8d66b9b095467f414a156dc12ec4f1d2ec3e1c7
Author: Florian Dold <florian@dold.me>
Date: Mon, 15 Jul 2024 15:52:02 +0200
wallet-core: support clientCancellationId for deposit
Diffstat:
2 files changed, 42 insertions(+), 0 deletions(-)
diff --git a/packages/taler-util/src/types-taler-wallet.ts b/packages/taler-util/src/types-taler-wallet.ts
@@ -2379,13 +2379,38 @@ export interface CreateDepositGroupRequest {
}
export interface PrepareDepositRequest {
+ /**
+ * Payto URI to identify the (bank) account that the exchange will wire
+ * the money to.
+ */
depositPaytoUri: string;
+
+ /**
+ * Amount that should be deposited.
+ *
+ * Raw amount, fees will be added on top.
+ */
amount: AmountString;
+
+ /**
+ * ID provided by the client to cancel the request.
+ *
+ * If the same request is made again with the same clientCancellationId,
+ * all previous requests are cancelled.
+ *
+ * The cancelled request will receive an error response with
+ * an error code that indicates the cancellation.
+ *
+ * The cancellation is best-effort, responses might still arrive.
+ */
+ clientCancellationId?: string;
}
+
export const codecForPrepareDepositRequest = (): Codec<PrepareDepositRequest> =>
buildCodecForObject<PrepareDepositRequest>()
.property("amount", codecForAmountString())
.property("depositPaytoUri", codecForString())
+ .property("clientCancellationId", codecOptional(codecForString()))
.build("PrepareDepositRequest");
export interface PrepareDepositResponse {
diff --git a/packages/taler-wallet-core/src/deposits.ts b/packages/taler-wallet-core/src/deposits.ts
@@ -80,6 +80,7 @@ import {
TombstoneTag,
TransactionContext,
constructTaskIdentifier,
+ runWithClientCancellation,
spendCoins,
} from "./common.js";
import {
@@ -1333,6 +1334,22 @@ export async function checkDepositGroup(
wex: WalletExecutionContext,
req: PrepareDepositRequest,
): Promise<PrepareDepositResponse> {
+ return await runWithClientCancellation(
+ wex,
+ "checkDepositGroup",
+ req.clientCancellationId,
+ () => internalCheckDepositGroup(wex, req),
+ );
+}
+
+/**
+ * Check if creating a deposit group is possible and calculate
+ * the associated fees.
+ */
+export async function internalCheckDepositGroup(
+ wex: WalletExecutionContext,
+ req: PrepareDepositRequest,
+): Promise<PrepareDepositResponse> {
const p = parsePaytoUri(req.depositPaytoUri);
if (!p) {
throw Error("invalid payto URI");