From 2337ddab6126722b46a0ea0b6e244955a38b09df Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Fri, 23 Sep 2022 21:47:38 +0200 Subject: wallet-core: fix withdrawal state machine --- packages/taler-wallet-core/src/db.ts | 5 +++++ packages/taler-wallet-core/src/operations/withdraw.ts | 5 ++++- packages/taler-wallet-core/src/wallet.ts | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) (limited to 'packages/taler-wallet-core/src') diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts index 3bbe5f002..f8fddb255 100644 --- a/packages/taler-wallet-core/src/db.ts +++ b/packages/taler-wallet-core/src/db.ts @@ -126,6 +126,11 @@ export enum WithdrawalGroupStatus { */ QueryingStatus = OperationStatusRange.ACTIVE_START + 2, + /** + * Ready for withdrawal. + */ + Ready = OperationStatusRange.ACTIVE_START + 3, + /** * The corresponding withdraw record has been created. * No further processing is done, unless explicitly requested diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts b/packages/taler-wallet-core/src/operations/withdraw.ts index 4901fdc86..461b96079 100644 --- a/packages/taler-wallet-core/src/operations/withdraw.ts +++ b/packages/taler-wallet-core/src/operations/withdraw.ts @@ -1023,7 +1023,7 @@ async function queryReserve( logger.warn(`withdrawal group ${withdrawalGroupId} not found`); return; } - wg.status = WithdrawalGroupStatus.Finished; + wg.status = WithdrawalGroupStatus.Ready; await tx.withdrawalGroups.put(wg); }); @@ -1138,6 +1138,9 @@ export async function processWithdrawalGroup( case WithdrawalGroupStatus.Finished: // We can try to withdraw, nothing needs to be done with the reserve. break; + case WithdrawalGroupStatus.Ready: + // Continue with the actual withdrawal! + break; default: throw new InvariantViolatedError( `unknown reserve record status: ${withdrawalGroup.status}`, diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index 3b9a323a7..4323f68f5 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -492,6 +492,7 @@ async function runTaskLoop( ws: InternalWalletState, opts: RetryLoopOpts = {}, ): Promise { + logger.info(`running task loop opts=${j2s(opts)}`); let retriesExceeded = false; for (let iteration = 0; !ws.stopped; iteration++) { const pending = await getPendingOperations(ws); -- cgit v1.2.3