From e6ed901626a5219a1d091f4f41654365d2c29531 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Sun, 19 Feb 2023 23:13:44 +0100 Subject: wallet-core: various p2p payment fixes --- .../taler-wallet-core/src/operations/pending.ts | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'packages/taler-wallet-core/src/operations/pending.ts') diff --git a/packages/taler-wallet-core/src/operations/pending.ts b/packages/taler-wallet-core/src/operations/pending.ts index a73af528c..d1d1bb03a 100644 --- a/packages/taler-wallet-core/src/operations/pending.ts +++ b/packages/taler-wallet-core/src/operations/pending.ts @@ -29,6 +29,7 @@ import { OperationStatus, OperationStatusRange, PeerPushPaymentInitiationStatus, + PeerPullPaymentIncomingStatus, } from "../db.js"; import { PendingOperationsResponse, @@ -377,6 +378,32 @@ async function gatherPeerPullInitiationPending( }); } +async function gatherPeerPullDebitPending( + ws: InternalWalletState, + tx: GetReadOnlyAccess<{ + peerPullPaymentIncoming: typeof WalletStoresV1.peerPullPaymentIncoming; + operationRetries: typeof WalletStoresV1.operationRetries; + }>, + now: AbsoluteTime, + resp: PendingOperationsResponse, +): Promise { + await tx.peerPullPaymentIncoming.iter().forEachAsync(async (pi) => { + if (pi.status === PeerPullPaymentIncomingStatus.Paid) { + return; + } + const opId = RetryTags.forPeerPullPaymentDebit(pi); + const retryRecord = await tx.operationRetries.get(opId); + const timestampDue = retryRecord?.retryInfo.nextRetry ?? AbsoluteTime.now(); + resp.pendingOperations.push({ + type: PendingTaskType.PeerPullDebit, + ...getPendingCommon(ws, opId, timestampDue), + givesLifeness: true, + retryInfo: retryRecord?.retryInfo, + peerPullPaymentIncomingId: pi.peerPullPaymentIncomingId, + }); + }); +} + async function gatherPeerPushInitiationPending( ws: InternalWalletState, tx: GetReadOnlyAccess<{ @@ -423,6 +450,7 @@ export async function getPendingOperations( x.operationRetries, x.peerPullPaymentInitiations, x.peerPushPaymentInitiations, + x.peerPullPaymentIncoming, ]) .runReadWrite(async (tx) => { const resp: PendingOperationsResponse = { @@ -438,6 +466,7 @@ export async function getPendingOperations( await gatherBackupPending(ws, tx, now, resp); await gatherPeerPushInitiationPending(ws, tx, now, resp); await gatherPeerPullInitiationPending(ws, tx, now, resp); + await gatherPeerPullDebitPending(ws, tx, now, resp); return resp; }); } -- cgit v1.2.3