diff options
author | Florian Dold <florian@dold.me> | 2023-02-20 00:36:02 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-02-20 00:38:24 +0100 |
commit | 30b3949d2bd9da6bceddb40f3d1921b95fa80316 (patch) | |
tree | 6163df600f17eadc94f7f3e51cc220bc8122ee8a /packages/taler-wallet-core/src/operations/pending.ts | |
parent | e6ed901626a5219a1d091f4f41654365d2c29531 (diff) | |
download | wallet-core-30b3949d2bd9da6bceddb40f3d1921b95fa80316.tar.xz |
wallet-core: pending operation for peer push credit, save withdrawalGroupId
Diffstat (limited to 'packages/taler-wallet-core/src/operations/pending.ts')
-rw-r--r-- | packages/taler-wallet-core/src/operations/pending.ts | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/packages/taler-wallet-core/src/operations/pending.ts b/packages/taler-wallet-core/src/operations/pending.ts index d1d1bb03a..554766c04 100644 --- a/packages/taler-wallet-core/src/operations/pending.ts +++ b/packages/taler-wallet-core/src/operations/pending.ts @@ -30,6 +30,7 @@ import { OperationStatusRange, PeerPushPaymentInitiationStatus, PeerPullPaymentIncomingStatus, + PeerPushPaymentIncomingStatus, } from "../db.js"; import { PendingOperationsResponse, @@ -430,6 +431,35 @@ async function gatherPeerPushInitiationPending( }); } +async function gatherPeerPushCreditPending( + ws: InternalWalletState, + tx: GetReadOnlyAccess<{ + peerPushPaymentIncoming: typeof WalletStoresV1.peerPushPaymentIncoming; + operationRetries: typeof WalletStoresV1.operationRetries; + }>, + now: AbsoluteTime, + resp: PendingOperationsResponse, +): Promise<void> { + await tx.peerPushPaymentIncoming.iter().forEachAsync(async (pi) => { + switch (pi.status) { + case PeerPushPaymentIncomingStatus.Accepted: + return; + case PeerPushPaymentIncomingStatus.WithdrawalCreated: + return; + } + const opId = RetryTags.forPeerPushCredit(pi); + const retryRecord = await tx.operationRetries.get(opId); + const timestampDue = retryRecord?.retryInfo.nextRetry ?? AbsoluteTime.now(); + resp.pendingOperations.push({ + type: PendingTaskType.PeerPushCredit, + ...getPendingCommon(ws, opId, timestampDue), + givesLifeness: true, + retryInfo: retryRecord?.retryInfo, + peerPushPaymentIncomingId: pi.peerPushPaymentIncomingId, + }); + }); +} + export async function getPendingOperations( ws: InternalWalletState, ): Promise<PendingOperationsResponse> { @@ -451,6 +481,7 @@ export async function getPendingOperations( x.peerPullPaymentInitiations, x.peerPushPaymentInitiations, x.peerPullPaymentIncoming, + x.peerPushPaymentIncoming, ]) .runReadWrite(async (tx) => { const resp: PendingOperationsResponse = { @@ -467,6 +498,7 @@ export async function getPendingOperations( await gatherPeerPushInitiationPending(ws, tx, now, resp); await gatherPeerPullInitiationPending(ws, tx, now, resp); await gatherPeerPullDebitPending(ws, tx, now, resp); + await gatherPeerPushCreditPending(ws, tx, now, resp); return resp; }); } |