diff options
author | Florian Dold <florian@dold.me> | 2023-01-12 16:57:51 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-01-12 16:57:51 +0100 |
commit | 1e378e4499906e466e933e40464727fb1c1cbf5e (patch) | |
tree | 49f01bfe3a505208f1463e00f9bbe77f15a9d0cd /packages/taler-wallet-core/src/operations/pending.ts | |
parent | 24694eae736763ea6e026c8839b7ba119db10bb4 (diff) | |
download | wallet-core-1e378e4499906e466e933e40464727fb1c1cbf5e.tar.xz |
wallet-core: retries for peer pull payments
Diffstat (limited to 'packages/taler-wallet-core/src/operations/pending.ts')
-rw-r--r-- | packages/taler-wallet-core/src/operations/pending.ts | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/packages/taler-wallet-core/src/operations/pending.ts b/packages/taler-wallet-core/src/operations/pending.ts index d2066d4fc..d9d62ec65 100644 --- a/packages/taler-wallet-core/src/operations/pending.ts +++ b/packages/taler-wallet-core/src/operations/pending.ts @@ -28,6 +28,7 @@ import { RefreshCoinStatus, OperationStatus, OperationStatusRange, + PeerPushPaymentInitiationStatus, } from "../db.js"; import { PendingOperationsResponse, @@ -341,6 +342,58 @@ async function gatherBackupPending( }); } +async function gatherPeerPullInitiationPending( + ws: InternalWalletState, + tx: GetReadOnlyAccess<{ + peerPullPaymentInitiations: typeof WalletStoresV1.peerPullPaymentInitiations; + operationRetries: typeof WalletStoresV1.operationRetries; + }>, + now: AbsoluteTime, + resp: PendingOperationsResponse, +): Promise<void> { + await tx.peerPullPaymentInitiations.iter().forEachAsync(async (pi) => { + if (pi.status === OperationStatus.Finished) { + return; + } + const opId = RetryTags.forPeerPullPaymentInitiation(pi); + const retryRecord = await tx.operationRetries.get(opId); + const timestampDue = retryRecord?.retryInfo.nextRetry ?? AbsoluteTime.now(); + resp.pendingOperations.push({ + type: PendingTaskType.PeerPullInitiation, + ...getPendingCommon(ws, opId, timestampDue), + givesLifeness: true, + retryInfo: retryRecord?.retryInfo, + pursePub: pi.pursePub, + }); + }); +} + +async function gatherPeerPushInitiationPending( + ws: InternalWalletState, + tx: GetReadOnlyAccess<{ + peerPushPaymentInitiations: typeof WalletStoresV1.peerPushPaymentInitiations; + operationRetries: typeof WalletStoresV1.operationRetries; + }>, + now: AbsoluteTime, + resp: PendingOperationsResponse, +): Promise<void> { + await tx.peerPushPaymentInitiations.iter().forEachAsync(async (pi) => { + if (pi.status === PeerPushPaymentInitiationStatus.PurseCreated) { + return; + } + const opId = RetryTags.forPeerPushPaymentInitiation(pi); + const retryRecord = await tx.operationRetries.get(opId); + const timestampDue = retryRecord?.retryInfo.nextRetry ?? AbsoluteTime.now(); + resp.pendingOperations.push({ + type: PendingTaskType.PeerPushInitiation, + ...getPendingCommon(ws, opId, timestampDue), + givesLifeness: true, + retryInfo: retryRecord?.retryInfo, + pursePub: pi.pursePub, + }); + }); +} + export async function getPendingOperations( ws: InternalWalletState, ): Promise<PendingOperationsResponse> { @@ -359,6 +412,8 @@ export async function getPendingOperations( x.depositGroups, x.recoupGroups, x.operationRetries, + x.peerPullPaymentInitiations, + x.peerPushPaymentInitiations, ]) .runReadWrite(async (tx) => { const resp: PendingOperationsResponse = { @@ -372,6 +427,8 @@ export async function getPendingOperations( await gatherPurchasePending(ws, tx, now, resp); await gatherRecoupPending(ws, tx, now, resp); await gatherBackupPending(ws, tx, now, resp); + await gatherPeerPushInitiationPending(ws, tx, now, resp); + await gatherPeerPullInitiationPending(ws, tx, now, resp); return resp; }); } |