aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/exchanges.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-core/src/operations/exchanges.ts')
-rw-r--r--packages/taler-wallet-core/src/operations/exchanges.ts60
1 files changed, 33 insertions, 27 deletions
diff --git a/packages/taler-wallet-core/src/operations/exchanges.ts b/packages/taler-wallet-core/src/operations/exchanges.ts
index 56ef672dc..c0373704a 100644
--- a/packages/taler-wallet-core/src/operations/exchanges.ts
+++ b/packages/taler-wallet-core/src/operations/exchanges.ts
@@ -76,11 +76,10 @@ import {
} from "../util/query.js";
import { WALLET_EXCHANGE_PROTOCOL_VERSION } from "../versions.js";
import {
- OperationAttemptResult,
- OperationAttemptResultType,
+ TaskRunResultType,
runTaskWithErrorReporting,
TaskIdentifiers,
- unwrapOperationHandlerResultOrThrow,
+ TaskRunResult,
} from "./common.js";
const logger = new Logger("exchanges.ts");
@@ -559,13 +558,34 @@ export async function updateExchangeFromUrl(
exchangeDetails: ExchangeDetailsRecord;
}> {
const canonUrl = canonicalizeBaseUrl(baseUrl);
- return unwrapOperationHandlerResultOrThrow(
- await runTaskWithErrorReporting(
- ws,
- TaskIdentifiers.forExchangeUpdateFromUrl(canonUrl),
- () => updateExchangeFromUrlHandler(ws, canonUrl, options),
- ),
+ const res = await runTaskWithErrorReporting(
+ ws,
+ TaskIdentifiers.forExchangeUpdateFromUrl(canonUrl),
+ () => updateExchangeFromUrlHandler(ws, canonUrl, options),
);
+ switch (res.type) {
+ case TaskRunResultType.Finished: {
+ const now = AbsoluteTime.now();
+ const { exchange, exchangeDetails } = await ws.db
+ .mktx((x) => [x.exchanges, x.exchangeDetails])
+ .runReadWrite(async (tx) => {
+ let exchange = await tx.exchanges.get(canonUrl);
+ const exchangeDetails = await getExchangeDetails(tx, baseUrl);
+ return { exchange, exchangeDetails };
+ });
+ if (!exchange) {
+ throw Error("exchange not found");
+ }
+ if (!exchangeDetails) {
+ throw Error("exchange details not found");
+ }
+ return { exchange, exchangeDetails };
+ }
+ case TaskRunResultType.Error:
+ throw TalerError.fromUncheckedDetail(res.errorDetail);
+ default:
+ throw Error(`unexpected operation result (${res.type})`);
+ }
}
/**
@@ -581,12 +601,7 @@ export async function updateExchangeFromUrlHandler(
forceNow?: boolean;
cancellationToken?: CancellationToken;
} = {},
-): Promise<
- OperationAttemptResult<{
- exchange: ExchangeRecord;
- exchangeDetails: ExchangeDetailsRecord;
- }>
-> {
+): Promise<TaskRunResult> {
const forceNow = options.forceNow ?? false;
logger.trace(
`updating exchange info for ${exchangeBaseUrl}, forced: ${forceNow}`,
@@ -620,10 +635,7 @@ export async function updateExchangeFromUrlHandler(
}
}
- return {
- type: OperationAttemptResultType.Finished,
- result: { exchange, exchangeDetails },
- };
+ return TaskRunResult.finished();
}
logger.info("updating exchange /keys info");
@@ -679,7 +691,7 @@ export async function updateExchangeFromUrlHandler(
},
);
return {
- type: OperationAttemptResultType.Error,
+ type: TaskRunResultType.Error,
errorDetail,
};
}
@@ -911,13 +923,7 @@ export async function updateExchangeFromUrlHandler(
});
}
- return {
- type: OperationAttemptResultType.Finished,
- result: {
- exchange: updated.exchange,
- exchangeDetails: updated.exchangeDetails,
- },
- };
+ return TaskRunResult.finished();
}
/**