diff options
Diffstat (limited to 'packages/taler-wallet-core/src/operations/withdraw.ts')
-rw-r--r-- | packages/taler-wallet-core/src/operations/withdraw.ts | 56 |
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)); } |