aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/withdraw.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2023-02-20 21:26:08 +0100
committerFlorian Dold <florian@dold.me>2023-02-20 21:26:08 +0100
commita49959d2c8bf82575c5d232217a33d91e7b008e8 (patch)
tree03dbbfd397a83dffaaa53580102f3d7108a7b70d /packages/taler-wallet-core/src/operations/withdraw.ts
parente8b5f26ab6407fbcecfe464f5aba8d1db9e487cd (diff)
downloadwallet-core-a49959d2c8bf82575c5d232217a33d91e7b008e8.tar.xz
wallet-core: support long-polling for peer push credit
Diffstat (limited to 'packages/taler-wallet-core/src/operations/withdraw.ts')
-rw-r--r--packages/taler-wallet-core/src/operations/withdraw.ts56
1 files changed, 22 insertions, 34 deletions
diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts b/packages/taler-wallet-core/src/operations/withdraw.ts
index 5729b8458..aba2948cd 100644
--- a/packages/taler-wallet-core/src/operations/withdraw.ts
+++ b/packages/taler-wallet-core/src/operations/withdraw.ts
@@ -90,6 +90,7 @@ import { InternalWalletState } from "../internal-wallet-state.js";
import {
makeCoinAvailable,
makeExchangeListItem,
+ runLongpollAsync,
runOperationWithErrorReporting,
} from "../operations/common.js";
import { walletCoreDebugFlags } from "../util/debugFlags.js";
@@ -1022,8 +1023,7 @@ export interface WithdrawalGroupContext {
export async function processWithdrawalGroup(
ws: InternalWalletState,
withdrawalGroupId: string,
- options: {
- } = {},
+ options: {} = {},
): Promise<OperationAttemptResult> {
logger.trace("processing withdrawal group", withdrawalGroupId);
const withdrawalGroup = await ws.db
@@ -1053,38 +1053,9 @@ export async function processWithdrawalGroup(
forceNow: true,
});
case WithdrawalGroupStatus.QueryingStatus: {
- const doQueryAsync = async () => {
- if (ws.stopped) {
- logger.trace("not long-polling reserve, wallet already stopped");
- await storeOperationPending(ws, retryTag);
- return;
- }
- const cts = CancellationToken.create();
- let res: { ready: boolean } | undefined = undefined;
- try {
- ws.activeLongpoll[retryTag] = {
- cancel: () => {
- logger.trace("cancel of reserve longpoll requested");
- cts.cancel();
- },
- };
- res = await queryReserve(ws, withdrawalGroupId, cts.token);
- } catch (e) {
- await storeOperationError(
- ws,
- retryTag,
- getErrorDetailFromException(e),
- );
- return;
- } finally {
- delete ws.activeLongpoll[retryTag];
- }
- if (!res.ready) {
- await storeOperationPending(ws, retryTag);
- }
- ws.latch.trigger();
- };
- doQueryAsync();
+ runLongpollAsync(ws, retryTag, (ct) => {
+ return queryReserve(ws, withdrawalGroupId, ct);
+ });
logger.trace(
"returning early from withdrawal for long-polling in background",
);
@@ -1832,6 +1803,14 @@ async function processReserveBankStatus(
}
}
+/**
+ * Create a withdrawal group.
+ *
+ * If a forcedWithdrawalGroupId is given and a
+ * withdrawal group with this ID already exists,
+ * the existing one is returned. No conflict checking
+ * of the other arguments is done in that case.
+ */
export async function internalCreateWithdrawalGroup(
ws: InternalWalletState,
args: {
@@ -1856,6 +1835,15 @@ export async function internalCreateWithdrawalGroup(
if (args.forcedWithdrawalGroupId) {
withdrawalGroupId = args.forcedWithdrawalGroupId;
+ const wgId = withdrawalGroupId;
+ const existingWg = await ws.db
+ .mktx((x) => [x.withdrawalGroups])
+ .runReadOnly(async (tx) => {
+ return tx.withdrawalGroups.get(wgId);
+ });
+ if (existingWg) {
+ return existingWg;
+ }
} else {
withdrawalGroupId = encodeCrock(getRandomBytes(32));
}