aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/refresh.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2024-02-21 14:23:01 +0100
committerFlorian Dold <florian@dold.me>2024-02-21 14:23:01 +0100
commit52a1f63e0a8cc2ca78910e8b56326376eb1d75d0 (patch)
treee59e898731a9eb76a9af3cec75256b5a07adf893 /packages/taler-wallet-core/src/refresh.ts
parent612b85c18fc17af412d08e075e1fddaa67aa7bf0 (diff)
downloadwallet-core-52a1f63e0a8cc2ca78910e8b56326376eb1d75d0.tar.xz
wallet-core: use cancellation tokens when possible
Diffstat (limited to 'packages/taler-wallet-core/src/refresh.ts')
-rw-r--r--packages/taler-wallet-core/src/refresh.ts59
1 files changed, 34 insertions, 25 deletions
diff --git a/packages/taler-wallet-core/src/refresh.ts b/packages/taler-wallet-core/src/refresh.ts
index 3b75ae2f3..f1ee84f3e 100644
--- a/packages/taler-wallet-core/src/refresh.ts
+++ b/packages/taler-wallet-core/src/refresh.ts
@@ -52,6 +52,7 @@ import {
TalerErrorDetail,
TalerPreciseTimestamp,
TransactionAction,
+ TransactionIdStr,
TransactionMajorState,
TransactionState,
TransactionType,
@@ -68,7 +69,7 @@ import {
makeCoinAvailable,
makeCoinsVisible,
PendingTaskType,
- TaskId,
+ TaskIdStr,
TaskRunResult,
TaskRunResultType,
TombstoneTag,
@@ -104,8 +105,8 @@ import { getCandidateWithdrawalDenomsTx } from "./withdraw.js";
const logger = new Logger("refresh.ts");
export class RefreshTransactionContext implements TransactionContext {
- public transactionId: string;
- readonly taskId: TaskId;
+ public transactionId: TransactionIdStr;
+ readonly taskId: TaskIdStr;
constructor(
public ws: InternalWalletState,
@@ -493,6 +494,7 @@ async function refreshMelt(
ws: InternalWalletState,
refreshGroupId: string,
coinIndex: number,
+ cancellationToken: CancellationToken,
): Promise<void> {
const d = await ws.db.runReadWriteTx(
["refreshGroups", "refreshSessions", "coins", "denominations"],
@@ -606,6 +608,7 @@ async function refreshMelt(
method: "POST",
body: meltReqBody,
timeout: getRefreshRequestTimeout(refreshGroup),
+ cancellationToken,
});
});
@@ -687,6 +690,7 @@ async function refreshMelt(
headers: {
"Taler-Coin-History-Signature": historySig.sig,
},
+ cancellationToken,
});
const historyJson = await historyResp.json();
@@ -789,6 +793,7 @@ async function refreshReveal(
ws: InternalWalletState,
refreshGroupId: string,
coinIndex: number,
+ cancellationToken: CancellationToken,
): Promise<void> {
logger.trace(
`doing refresh reveal for ${refreshGroupId} (old coin ${coinIndex})`,
@@ -913,6 +918,7 @@ async function refreshReveal(
body: req,
method: "POST",
timeout: getRefreshRequestTimeout(refreshGroup),
+ cancellationToken,
});
});
@@ -1026,26 +1032,28 @@ export async function processRefreshGroup(
let errors: TalerErrorDetail[] = [];
let inShutdown = false;
const ps = refreshGroup.oldCoinPubs.map((x, i) =>
- processRefreshSession(ws, refreshGroupId, i).catch((x) => {
- if (x instanceof CryptoApiStoppedError) {
- inShutdown = true;
- logger.info(
- "crypto API stopped while processing refresh group, probably the wallet is currently shutting down.",
- );
- return;
- }
- if (x instanceof TalerError) {
- logger.warn("process refresh session got exception (TalerError)");
- logger.warn(`exc ${x}`);
- logger.warn(`exc stack ${x.stack}`);
- logger.warn(`error detail: ${j2s(x.errorDetail)}`);
- } else {
- logger.warn("process refresh session got exception");
- logger.warn(`exc ${x}`);
- logger.warn(`exc stack ${x.stack}`);
- }
- errors.push(getErrorDetailFromException(x));
- }),
+ processRefreshSession(ws, refreshGroupId, i, cancellationToken).catch(
+ (x) => {
+ if (x instanceof CryptoApiStoppedError) {
+ inShutdown = true;
+ logger.info(
+ "crypto API stopped while processing refresh group, probably the wallet is currently shutting down.",
+ );
+ return;
+ }
+ if (x instanceof TalerError) {
+ logger.warn("process refresh session got exception (TalerError)");
+ logger.warn(`exc ${x}`);
+ logger.warn(`exc stack ${x.stack}`);
+ logger.warn(`error detail: ${j2s(x.errorDetail)}`);
+ } else {
+ logger.warn("process refresh session got exception");
+ logger.warn(`exc ${x}`);
+ logger.warn(`exc stack ${x.stack}`);
+ }
+ errors.push(getErrorDetailFromException(x));
+ },
+ ),
);
try {
logger.info("waiting for refreshes");
@@ -1078,6 +1086,7 @@ async function processRefreshSession(
ws: InternalWalletState,
refreshGroupId: string,
coinIndex: number,
+ cancellationToken: CancellationToken,
): Promise<void> {
logger.trace(
`processing refresh session for coin ${coinIndex} of group ${refreshGroupId}`,
@@ -1109,9 +1118,9 @@ async function processRefreshSession(
return;
}
if (refreshSession.norevealIndex === undefined) {
- await refreshMelt(ws, refreshGroupId, coinIndex);
+ await refreshMelt(ws, refreshGroupId, coinIndex, cancellationToken);
}
- await refreshReveal(ws, refreshGroupId, coinIndex);
+ await refreshReveal(ws, refreshGroupId, coinIndex, cancellationToken);
}
export interface RefreshOutputInfo {