diff options
Diffstat (limited to 'packages/taler-wallet-core/src/operations/pay-peer-pull-credit.ts')
-rw-r--r-- | packages/taler-wallet-core/src/operations/pay-peer-pull-credit.ts | 328 |
1 files changed, 164 insertions, 164 deletions
diff --git a/packages/taler-wallet-core/src/operations/pay-peer-pull-credit.ts b/packages/taler-wallet-core/src/operations/pay-peer-pull-credit.ts index 29c0fff9e..edadad1fc 100644 --- a/packages/taler-wallet-core/src/operations/pay-peer-pull-credit.ts +++ b/packages/taler-wallet-core/src/operations/pay-peer-pull-credit.ts @@ -55,8 +55,8 @@ import { import { KycPendingInfo, KycUserType, - PeerPullPaymentInitiationRecord, - PeerPullPaymentInitiationStatus, + PeerPullCreditRecord, + PeerPullPaymentCreditStatus, WithdrawalGroupStatus, WithdrawalRecordType, updateExchangeFromUrl, @@ -90,7 +90,7 @@ const logger = new Logger("pay-peer-pull-credit.ts"); async function queryPurseForPeerPullCredit( ws: InternalWalletState, - pullIni: PeerPullPaymentInitiationRecord, + pullIni: PeerPullCreditRecord, cancellationToken: CancellationToken, ): Promise<LongpollResult> { const purseDepositUrl = new URL( @@ -159,18 +159,18 @@ async function queryPurseForPeerPullCredit( pursePub: pullIni.pursePub, }); const transitionInfo = await ws.db - .mktx((x) => [x.peerPullPaymentInitiations]) + .mktx((x) => [x.peerPullCredit]) .runReadWrite(async (tx) => { - const finPi = await tx.peerPullPaymentInitiations.get(pullIni.pursePub); + const finPi = await tx.peerPullCredit.get(pullIni.pursePub); if (!finPi) { - logger.warn("peerPullPaymentInitiation not found anymore"); + logger.warn("peerPullCredit not found anymore"); return; } const oldTxState = computePeerPullCreditTransactionState(finPi); - if (finPi.status === PeerPullPaymentInitiationStatus.PendingReady) { - finPi.status = PeerPullPaymentInitiationStatus.PendingWithdrawing; + if (finPi.status === PeerPullPaymentCreditStatus.PendingReady) { + finPi.status = PeerPullPaymentCreditStatus.PendingWithdrawing; } - await tx.peerPullPaymentInitiations.put(finPi); + await tx.peerPullCredit.put(finPi); const newTxState = computePeerPullCreditTransactionState(finPi); return { oldTxState, newTxState }; }); @@ -214,22 +214,22 @@ async function longpollKycStatus( kycStatusRes.status === HttpStatusCode.NoContent ) { const transitionInfo = await ws.db - .mktx((x) => [x.peerPullPaymentInitiations]) + .mktx((x) => [x.peerPullCredit]) .runReadWrite(async (tx) => { - const peerIni = await tx.peerPullPaymentInitiations.get(pursePub); + const peerIni = await tx.peerPullCredit.get(pursePub); if (!peerIni) { return; } if ( peerIni.status !== - PeerPullPaymentInitiationStatus.PendingMergeKycRequired + PeerPullPaymentCreditStatus.PendingMergeKycRequired ) { return; } const oldTxState = computePeerPullCreditTransactionState(peerIni); - peerIni.status = PeerPullPaymentInitiationStatus.PendingCreatePurse; + peerIni.status = PeerPullPaymentCreditStatus.PendingCreatePurse; const newTxState = computePeerPullCreditTransactionState(peerIni); - await tx.peerPullPaymentInitiations.put(peerIni); + await tx.peerPullCredit.put(peerIni); return { oldTxState, newTxState }; }); notifyTransition(ws, transactionId, transitionInfo); @@ -250,7 +250,7 @@ async function longpollKycStatus( async function processPeerPullCreditAbortingDeletePurse( ws: InternalWalletState, - peerPullIni: PeerPullPaymentInitiationRecord, + peerPullIni: PeerPullCreditRecord, ): Promise<TaskRunResult> { const { pursePub, pursePriv } = peerPullIni; const transactionId = constructTransactionIdentifier({ @@ -272,24 +272,24 @@ async function processPeerPullCreditAbortingDeletePurse( const transitionInfo = await ws.db .mktx((x) => [ - x.peerPullPaymentInitiations, + x.peerPullCredit, x.refreshGroups, x.denominations, x.coinAvailability, x.coins, ]) .runReadWrite(async (tx) => { - const ppiRec = await tx.peerPullPaymentInitiations.get(pursePub); + const ppiRec = await tx.peerPullCredit.get(pursePub); if (!ppiRec) { return undefined; } if ( - ppiRec.status !== PeerPullPaymentInitiationStatus.AbortingDeletePurse + ppiRec.status !== PeerPullPaymentCreditStatus.AbortingDeletePurse ) { return undefined; } const oldTxState = computePeerPullCreditTransactionState(ppiRec); - ppiRec.status = PeerPullPaymentInitiationStatus.Aborted; + ppiRec.status = PeerPullPaymentCreditStatus.Aborted; const newTxState = computePeerPullCreditTransactionState(ppiRec); return { oldTxState, @@ -303,7 +303,7 @@ async function processPeerPullCreditAbortingDeletePurse( async function handlePeerPullCreditWithdrawing( ws: InternalWalletState, - pullIni: PeerPullPaymentInitiationRecord, + pullIni: PeerPullCreditRecord, ): Promise<TaskRunResult> { if (!pullIni.withdrawalGroupId) { throw Error("invalid db state (withdrawing, but no withdrawal group ID"); @@ -315,14 +315,14 @@ async function handlePeerPullCreditWithdrawing( const wgId = pullIni.withdrawalGroupId; let finished: boolean = false; const transitionInfo = await ws.db - .mktx((x) => [x.peerPullPaymentInitiations, x.withdrawalGroups]) + .mktx((x) => [x.peerPullCredit, x.withdrawalGroups]) .runReadWrite(async (tx) => { - const ppi = await tx.peerPullPaymentInitiations.get(pullIni.pursePub); + const ppi = await tx.peerPullCredit.get(pullIni.pursePub); if (!ppi) { finished = true; return; } - if (ppi.status !== PeerPullPaymentInitiationStatus.PendingWithdrawing) { + if (ppi.status !== PeerPullPaymentCreditStatus.PendingWithdrawing) { finished = true; return; } @@ -333,13 +333,13 @@ async function handlePeerPullCreditWithdrawing( return undefined; } switch (wg.status) { - case WithdrawalGroupStatus.Finished: + case WithdrawalGroupStatus.Done: finished = true; - ppi.status = PeerPullPaymentInitiationStatus.Done; + ppi.status = PeerPullPaymentCreditStatus.Done; break; // FIXME: Also handle other final states! } - await tx.peerPullPaymentInitiations.put(ppi); + await tx.peerPullCredit.put(ppi); const newTxState = computePeerPullCreditTransactionState(ppi); return { oldTxState, @@ -357,7 +357,7 @@ async function handlePeerPullCreditWithdrawing( async function handlePeerPullCreditCreatePurse( ws: InternalWalletState, - pullIni: PeerPullPaymentInitiationRecord, + pullIni: PeerPullCreditRecord, ): Promise<TaskRunResult> { const purseFee = Amounts.stringify(Amounts.zeroOfAmount(pullIni.amount)); const pursePub = pullIni.pursePub; @@ -444,15 +444,15 @@ async function handlePeerPullCreditCreatePurse( }); const transitionInfo = await ws.db - .mktx((x) => [x.peerPullPaymentInitiations]) + .mktx((x) => [x.peerPullCredit]) .runReadWrite(async (tx) => { - const pi2 = await tx.peerPullPaymentInitiations.get(pursePub); + const pi2 = await tx.peerPullCredit.get(pursePub); if (!pi2) { return; } const oldTxState = computePeerPullCreditTransactionState(pi2); - pi2.status = PeerPullPaymentInitiationStatus.PendingReady; - await tx.peerPullPaymentInitiations.put(pi2); + pi2.status = PeerPullPaymentCreditStatus.PendingReady; + await tx.peerPullCredit.put(pi2); const newTxState = computePeerPullCreditTransactionState(pi2); return { oldTxState, newTxState }; }); @@ -466,9 +466,9 @@ export async function processPeerPullCredit( pursePub: string, ): Promise<TaskRunResult> { const pullIni = await ws.db - .mktx((x) => [x.peerPullPaymentInitiations]) + .mktx((x) => [x.peerPullCredit]) .runReadOnly(async (tx) => { - return tx.peerPullPaymentInitiations.get(pursePub); + return tx.peerPullCredit.get(pursePub); }); if (!pullIni) { throw Error("peer pull payment initiation not found in database"); @@ -490,10 +490,10 @@ export async function processPeerPullCredit( logger.trace(`processing ${retryTag}, status=${pullIni.status}`); switch (pullIni.status) { - case PeerPullPaymentInitiationStatus.Done: { + case PeerPullPaymentCreditStatus.Done: { return TaskRunResult.finished(); } - case PeerPullPaymentInitiationStatus.PendingReady: + case PeerPullPaymentCreditStatus.PendingReady: runLongpollAsync(ws, retryTag, async (cancellationToken) => queryPurseForPeerPullCredit(ws, pullIni, cancellationToken), ); @@ -503,7 +503,7 @@ export async function processPeerPullCredit( return { type: TaskRunResultType.Longpoll, }; - case PeerPullPaymentInitiationStatus.PendingMergeKycRequired: { + case PeerPullPaymentCreditStatus.PendingMergeKycRequired: { if (!pullIni.kycInfo) { throw Error("invalid state, kycInfo required"); } @@ -515,19 +515,19 @@ export async function processPeerPullCredit( "individual", ); } - case PeerPullPaymentInitiationStatus.PendingCreatePurse: + case PeerPullPaymentCreditStatus.PendingCreatePurse: return handlePeerPullCreditCreatePurse(ws, pullIni); - case PeerPullPaymentInitiationStatus.AbortingDeletePurse: + case PeerPullPaymentCreditStatus.AbortingDeletePurse: return await processPeerPullCreditAbortingDeletePurse(ws, pullIni); - case PeerPullPaymentInitiationStatus.PendingWithdrawing: + case PeerPullPaymentCreditStatus.PendingWithdrawing: return handlePeerPullCreditWithdrawing(ws, pullIni); - case PeerPullPaymentInitiationStatus.Aborted: - case PeerPullPaymentInitiationStatus.Failed: - case PeerPullPaymentInitiationStatus.SuspendedAbortingDeletePurse: - case PeerPullPaymentInitiationStatus.SuspendedCreatePurse: - case PeerPullPaymentInitiationStatus.SuspendedMergeKycRequired: - case PeerPullPaymentInitiationStatus.SuspendedReady: - case PeerPullPaymentInitiationStatus.SuspendedWithdrawing: + case PeerPullPaymentCreditStatus.Aborted: + case PeerPullPaymentCreditStatus.Failed: + case PeerPullPaymentCreditStatus.SuspendedAbortingDeletePurse: + case PeerPullPaymentCreditStatus.SuspendedCreatePurse: + case PeerPullPaymentCreditStatus.SuspendedMergeKycRequired: + case PeerPullPaymentCreditStatus.SuspendedReady: + case PeerPullPaymentCreditStatus.SuspendedWithdrawing: break; default: assertUnreachable(pullIni.status); @@ -538,7 +538,7 @@ export async function processPeerPullCredit( async function processPeerPullCreditKycRequired( ws: InternalWalletState, - peerIni: PeerPullPaymentInitiationRecord, + peerIni: PeerPullCreditRecord, kycPending: WalletKycUuid, ): Promise<TaskRunResult> { const transactionId = constructTransactionIdentifier({ @@ -570,9 +570,9 @@ async function processPeerPullCreditKycRequired( const kycStatus = await kycStatusRes.json(); logger.info(`kyc status: ${j2s(kycStatus)}`); const { transitionInfo, result } = await ws.db - .mktx((x) => [x.peerPullPaymentInitiations]) + .mktx((x) => [x.peerPullCredit]) .runReadWrite(async (tx) => { - const peerInc = await tx.peerPullPaymentInitiations.get(pursePub); + const peerInc = await tx.peerPullCredit.get(pursePub); if (!peerInc) { return { transitionInfo: undefined, @@ -586,9 +586,9 @@ async function processPeerPullCreditKycRequired( }; peerInc.kycUrl = kycStatus.kyc_url; peerInc.status = - PeerPullPaymentInitiationStatus.PendingMergeKycRequired; + PeerPullPaymentCreditStatus.PendingMergeKycRequired; const newTxState = computePeerPullCreditTransactionState(peerInc); - await tx.peerPullPaymentInitiations.put(peerInc); + await tx.peerPullCredit.put(peerInc); // We'll remove this eventually! New clients should rely on the // kycUrl field of the transaction, not the error code. const res: TaskRunResult = { @@ -758,9 +758,9 @@ export async function initiatePeerPullPayment( ); const transitionInfo = await ws.db - .mktx((x) => [x.peerPullPaymentInitiations, x.contractTerms]) + .mktx((x) => [x.peerPullCredit, x.contractTerms]) .runReadWrite(async (tx) => { - const ppi: PeerPullPaymentInitiationRecord = { + const ppi: PeerPullCreditRecord = { amount: req.partialContractTerms.amount, contractTermsHash: hContractTerms, exchangeBaseUrl: exchangeBaseUrl, @@ -768,7 +768,7 @@ export async function initiatePeerPullPayment( pursePub: pursePair.pub, mergePriv: mergePair.priv, mergePub: mergePair.pub, - status: PeerPullPaymentInitiationStatus.PendingCreatePurse, + status: PeerPullPaymentCreditStatus.PendingCreatePurse, contractTerms: contractTerms, mergeTimestamp, contractEncNonce, @@ -778,7 +778,7 @@ export async function initiatePeerPullPayment( withdrawalGroupId, estimatedAmountEffective: wi.withdrawalAmountEffective, }; - await tx.peerPullPaymentInitiations.put(ppi); + await tx.peerPullCredit.put(ppi); const oldTxState: TransactionState = { major: TransactionMajorState.None, }; @@ -826,39 +826,39 @@ export async function suspendPeerPullCreditTransaction( }); stopLongpolling(ws, taskId); const transitionInfo = await ws.db - .mktx((x) => [x.peerPullPaymentInitiations]) + .mktx((x) => [x.peerPullCredit]) .runReadWrite(async (tx) => { - const pullCreditRec = await tx.peerPullPaymentInitiations.get(pursePub); + const pullCreditRec = await tx.peerPullCredit.get(pursePub); if (!pullCreditRec) { logger.warn(`peer pull credit ${pursePub} not found`); return; } - let newStatus: PeerPullPaymentInitiationStatus | undefined = undefined; + let newStatus: PeerPullPaymentCreditStatus | undefined = undefined; switch (pullCreditRec.status) { - case PeerPullPaymentInitiationStatus.PendingCreatePurse: - newStatus = PeerPullPaymentInitiationStatus.SuspendedCreatePurse; + case PeerPullPaymentCreditStatus.PendingCreatePurse: + newStatus = PeerPullPaymentCreditStatus.SuspendedCreatePurse; break; - case PeerPullPaymentInitiationStatus.PendingMergeKycRequired: - newStatus = PeerPullPaymentInitiationStatus.SuspendedMergeKycRequired; + case PeerPullPaymentCreditStatus.PendingMergeKycRequired: + newStatus = PeerPullPaymentCreditStatus.SuspendedMergeKycRequired; break; - case PeerPullPaymentInitiationStatus.PendingWithdrawing: - newStatus = PeerPullPaymentInitiationStatus.SuspendedWithdrawing; + case PeerPullPaymentCreditStatus.PendingWithdrawing: + newStatus = PeerPullPaymentCreditStatus.SuspendedWithdrawing; break; - case PeerPullPaymentInitiationStatus.PendingReady: - newStatus = PeerPullPaymentInitiationStatus.SuspendedReady; + case PeerPullPaymentCreditStatus.PendingReady: + newStatus = PeerPullPaymentCreditStatus.SuspendedReady; break; - case PeerPullPaymentInitiationStatus.AbortingDeletePurse: + case PeerPullPaymentCreditStatus.AbortingDeletePurse: newStatus = - PeerPullPaymentInitiationStatus.SuspendedAbortingDeletePurse; + PeerPullPaymentCreditStatus.SuspendedAbortingDeletePurse; break; - case PeerPullPaymentInitiationStatus.Done: - case PeerPullPaymentInitiationStatus.SuspendedCreatePurse: - case PeerPullPaymentInitiationStatus.SuspendedMergeKycRequired: - case PeerPullPaymentInitiationStatus.SuspendedReady: - case PeerPullPaymentInitiationStatus.SuspendedWithdrawing: - case PeerPullPaymentInitiationStatus.Aborted: - case PeerPullPaymentInitiationStatus.Failed: - case PeerPullPaymentInitiationStatus.SuspendedAbortingDeletePurse: + case PeerPullPaymentCreditStatus.Done: + case PeerPullPaymentCreditStatus.SuspendedCreatePurse: + case PeerPullPaymentCreditStatus.SuspendedMergeKycRequired: + case PeerPullPaymentCreditStatus.SuspendedReady: + case PeerPullPaymentCreditStatus.SuspendedWithdrawing: + case PeerPullPaymentCreditStatus.Aborted: + case PeerPullPaymentCreditStatus.Failed: + case PeerPullPaymentCreditStatus.SuspendedAbortingDeletePurse: break; default: assertUnreachable(pullCreditRec.status); @@ -867,7 +867,7 @@ export async function suspendPeerPullCreditTransaction( const oldTxState = computePeerPullCreditTransactionState(pullCreditRec); pullCreditRec.status = newStatus; const newTxState = computePeerPullCreditTransactionState(pullCreditRec); - await tx.peerPullPaymentInitiations.put(pullCreditRec); + await tx.peerPullCredit.put(pullCreditRec); return { oldTxState, newTxState, @@ -892,33 +892,33 @@ export async function abortPeerPullCreditTransaction( }); stopLongpolling(ws, taskId); const transitionInfo = await ws.db - .mktx((x) => [x.peerPullPaymentInitiations]) + .mktx((x) => [x.peerPullCredit]) .runReadWrite(async (tx) => { - const pullCreditRec = await tx.peerPullPaymentInitiations.get(pursePub); + const pullCreditRec = await tx.peerPullCredit.get(pursePub); if (!pullCreditRec) { logger.warn(`peer pull credit ${pursePub} not found`); return; } - let newStatus: PeerPullPaymentInitiationStatus | undefined = undefined; + let newStatus: PeerPullPaymentCreditStatus | undefined = undefined; switch (pullCreditRec.status) { - case PeerPullPaymentInitiationStatus.PendingCreatePurse: - case PeerPullPaymentInitiationStatus.PendingMergeKycRequired: - newStatus = PeerPullPaymentInitiationStatus.AbortingDeletePurse; + case PeerPullPaymentCreditStatus.PendingCreatePurse: + case PeerPullPaymentCreditStatus.PendingMergeKycRequired: + newStatus = PeerPullPaymentCreditStatus.AbortingDeletePurse; break; - case PeerPullPaymentInitiationStatus.PendingWithdrawing: + case PeerPullPaymentCreditStatus.PendingWithdrawing: throw Error("can't abort anymore"); - case PeerPullPaymentInitiationStatus.PendingReady: - newStatus = PeerPullPaymentInitiationStatus.AbortingDeletePurse; + case PeerPullPaymentCreditStatus.PendingReady: + newStatus = PeerPullPaymentCreditStatus.AbortingDeletePurse; break; - case PeerPullPaymentInitiationStatus.Done: - case PeerPullPaymentInitiationStatus.SuspendedCreatePurse: - case PeerPullPaymentInitiationStatus.SuspendedMergeKycRequired: - case PeerPullPaymentInitiationStatus.SuspendedReady: - case PeerPullPaymentInitiationStatus.SuspendedWithdrawing: - case PeerPullPaymentInitiationStatus.Aborted: - case PeerPullPaymentInitiationStatus.AbortingDeletePurse: - case PeerPullPaymentInitiationStatus.Failed: - case PeerPullPaymentInitiationStatus.SuspendedAbortingDeletePurse: + case PeerPullPaymentCreditStatus.Done: + case PeerPullPaymentCreditStatus.SuspendedCreatePurse: + case PeerPullPaymentCreditStatus.SuspendedMergeKycRequired: + case PeerPullPaymentCreditStatus.SuspendedReady: + case PeerPullPaymentCreditStatus.SuspendedWithdrawing: + case PeerPullPaymentCreditStatus.Aborted: + case PeerPullPaymentCreditStatus.AbortingDeletePurse: + case PeerPullPaymentCreditStatus.Failed: + case PeerPullPaymentCreditStatus.SuspendedAbortingDeletePurse: break; default: assertUnreachable(pullCreditRec.status); @@ -927,7 +927,7 @@ export async function abortPeerPullCreditTransaction( const oldTxState = computePeerPullCreditTransactionState(pullCreditRec); pullCreditRec.status = newStatus; const newTxState = computePeerPullCreditTransactionState(pullCreditRec); - await tx.peerPullPaymentInitiations.put(pullCreditRec); + await tx.peerPullCredit.put(pullCreditRec); return { oldTxState, newTxState, @@ -952,30 +952,30 @@ export async function failPeerPullCreditTransaction( }); stopLongpolling(ws, taskId); const transitionInfo = await ws.db - .mktx((x) => [x.peerPullPaymentInitiations]) + .mktx((x) => [x.peerPullCredit]) .runReadWrite(async (tx) => { - const pullCreditRec = await tx.peerPullPaymentInitiations.get(pursePub); + const pullCreditRec = await tx.peerPullCredit.get(pursePub); if (!pullCreditRec) { logger.warn(`peer pull credit ${pursePub} not found`); return; } - let newStatus: PeerPullPaymentInitiationStatus | undefined = undefined; + let newStatus: PeerPullPaymentCreditStatus | undefined = undefined; switch (pullCreditRec.status) { - case PeerPullPaymentInitiationStatus.PendingCreatePurse: - case PeerPullPaymentInitiationStatus.PendingMergeKycRequired: - case PeerPullPaymentInitiationStatus.PendingWithdrawing: - case PeerPullPaymentInitiationStatus.PendingReady: - case PeerPullPaymentInitiationStatus.Done: - case PeerPullPaymentInitiationStatus.SuspendedCreatePurse: - case PeerPullPaymentInitiationStatus.SuspendedMergeKycRequired: - case PeerPullPaymentInitiationStatus.SuspendedReady: - case PeerPullPaymentInitiationStatus.SuspendedWithdrawing: - case PeerPullPaymentInitiationStatus.Aborted: - case PeerPullPaymentInitiationStatus.Failed: + case PeerPullPaymentCreditStatus.PendingCreatePurse: + case PeerPullPaymentCreditStatus.PendingMergeKycRequired: + case PeerPullPaymentCreditStatus.PendingWithdrawing: + case PeerPullPaymentCreditStatus.PendingReady: + case PeerPullPaymentCreditStatus.Done: + case PeerPullPaymentCreditStatus.SuspendedCreatePurse: + case PeerPullPaymentCreditStatus.SuspendedMergeKycRequired: + case PeerPullPaymentCreditStatus.SuspendedReady: + case PeerPullPaymentCreditStatus.SuspendedWithdrawing: + case PeerPullPaymentCreditStatus.Aborted: + case PeerPullPaymentCreditStatus.Failed: break; - case PeerPullPaymentInitiationStatus.AbortingDeletePurse: - case PeerPullPaymentInitiationStatus.SuspendedAbortingDeletePurse: - newStatus = PeerPullPaymentInitiationStatus.Failed; + case PeerPullPaymentCreditStatus.AbortingDeletePurse: + case PeerPullPaymentCreditStatus.SuspendedAbortingDeletePurse: + newStatus = PeerPullPaymentCreditStatus.Failed; break; default: assertUnreachable(pullCreditRec.status); @@ -984,7 +984,7 @@ export async function failPeerPullCreditTransaction( const oldTxState = computePeerPullCreditTransactionState(pullCreditRec); pullCreditRec.status = newStatus; const newTxState = computePeerPullCreditTransactionState(pullCreditRec); - await tx.peerPullPaymentInitiations.put(pullCreditRec); + await tx.peerPullCredit.put(pullCreditRec); return { oldTxState, newTxState, @@ -1009,38 +1009,38 @@ export async function resumePeerPullCreditTransaction( }); stopLongpolling(ws, taskId); const transitionInfo = await ws.db - .mktx((x) => [x.peerPullPaymentInitiations]) + .mktx((x) => [x.peerPullCredit]) .runReadWrite(async (tx) => { - const pullCreditRec = await tx.peerPullPaymentInitiations.get(pursePub); + const pullCreditRec = await tx.peerPullCredit.get(pursePub); if (!pullCreditRec) { logger.warn(`peer pull credit ${pursePub} not found`); return; } - let newStatus: PeerPullPaymentInitiationStatus | undefined = undefined; + let newStatus: PeerPullPaymentCreditStatus | undefined = undefined; switch (pullCreditRec.status) { - case PeerPullPaymentInitiationStatus.PendingCreatePurse: - case PeerPullPaymentInitiationStatus.PendingMergeKycRequired: - case PeerPullPaymentInitiationStatus.PendingWithdrawing: - case PeerPullPaymentInitiationStatus.PendingReady: - case PeerPullPaymentInitiationStatus.AbortingDeletePurse: - case PeerPullPaymentInitiationStatus.Done: - case PeerPullPaymentInitiationStatus.Failed: - case PeerPullPaymentInitiationStatus.Aborted: + case PeerPullPaymentCreditStatus.PendingCreatePurse: + case PeerPullPaymentCreditStatus.PendingMergeKycRequired: + case PeerPullPaymentCreditStatus.PendingWithdrawing: + case PeerPullPaymentCreditStatus.PendingReady: + case PeerPullPaymentCreditStatus.AbortingDeletePurse: + case PeerPullPaymentCreditStatus.Done: + case PeerPullPaymentCreditStatus.Failed: + case PeerPullPaymentCreditStatus.Aborted: break; - case PeerPullPaymentInitiationStatus.SuspendedCreatePurse: - newStatus = PeerPullPaymentInitiationStatus.PendingCreatePurse; + case PeerPullPaymentCreditStatus.SuspendedCreatePurse: + newStatus = PeerPullPaymentCreditStatus.PendingCreatePurse; break; - case PeerPullPaymentInitiationStatus.SuspendedMergeKycRequired: - newStatus = PeerPullPaymentInitiationStatus.PendingMergeKycRequired; + case PeerPullPaymentCreditStatus.SuspendedMergeKycRequired: + newStatus = PeerPullPaymentCreditStatus.PendingMergeKycRequired; break; - case PeerPullPaymentInitiationStatus.SuspendedReady: - newStatus = PeerPullPaymentInitiationStatus.PendingReady; + case PeerPullPaymentCreditStatus.SuspendedReady: + newStatus = PeerPullPaymentCreditStatus.PendingReady; break; - case PeerPullPaymentInitiationStatus.SuspendedWithdrawing: - newStatus = PeerPullPaymentInitiationStatus.PendingWithdrawing; + case PeerPullPaymentCreditStatus.SuspendedWithdrawing: + newStatus = PeerPullPaymentCreditStatus.PendingWithdrawing; break; - case PeerPullPaymentInitiationStatus.SuspendedAbortingDeletePurse: - newStatus = PeerPullPaymentInitiationStatus.AbortingDeletePurse; + case PeerPullPaymentCreditStatus.SuspendedAbortingDeletePurse: + newStatus = PeerPullPaymentCreditStatus.AbortingDeletePurse; break; default: assertUnreachable(pullCreditRec.status); @@ -1049,7 +1049,7 @@ export async function resumePeerPullCreditTransaction( const oldTxState = computePeerPullCreditTransactionState(pullCreditRec); pullCreditRec.status = newStatus; const newTxState = computePeerPullCreditTransactionState(pullCreditRec); - await tx.peerPullPaymentInitiations.put(pullCreditRec); + await tx.peerPullCredit.put(pullCreditRec); return { oldTxState, newTxState, @@ -1062,67 +1062,67 @@ export async function resumePeerPullCreditTransaction( } export function computePeerPullCreditTransactionState( - pullCreditRecord: PeerPullPaymentInitiationRecord, + pullCreditRecord: PeerPullCreditRecord, ): TransactionState { switch (pullCreditRecord.status) { - case PeerPullPaymentInitiationStatus.PendingCreatePurse: + case PeerPullPaymentCreditStatus.PendingCreatePurse: return { major: TransactionMajorState.Pending, minor: TransactionMinorState.CreatePurse, }; - case PeerPullPaymentInitiationStatus.PendingMergeKycRequired: + case PeerPullPaymentCreditStatus.PendingMergeKycRequired: return { major: TransactionMajorState.Pending, minor: TransactionMinorState.MergeKycRequired, }; - case PeerPullPaymentInitiationStatus.PendingReady: + case PeerPullPaymentCreditStatus.PendingReady: return { major: TransactionMajorState.Pending, minor: TransactionMinorState.Ready, }; - case PeerPullPaymentInitiationStatus.Done: + case PeerPullPaymentCreditStatus.Done: return { major: TransactionMajorState.Done, }; - case PeerPullPaymentInitiationStatus.PendingWithdrawing: + case PeerPullPaymentCreditStatus.PendingWithdrawing: return { major: TransactionMajorState.Pending, minor: TransactionMinorState.Withdraw, }; - case PeerPullPaymentInitiationStatus.SuspendedCreatePurse: + case PeerPullPaymentCreditStatus.SuspendedCreatePurse: return { major: TransactionMajorState.Suspended, minor: TransactionMinorState.CreatePurse, }; - case PeerPullPaymentInitiationStatus.SuspendedReady: + case PeerPullPaymentCreditStatus.SuspendedReady: return { major: TransactionMajorState.Suspended, minor: TransactionMinorState.Ready, }; - case PeerPullPaymentInitiationStatus.SuspendedWithdrawing: + case PeerPullPaymentCreditStatus.SuspendedWithdrawing: return { major: TransactionMajorState.Pending, minor: TransactionMinorState.Withdraw, }; - case PeerPullPaymentInitiationStatus.SuspendedMergeKycRequired: + case PeerPullPaymentCreditStatus.SuspendedMergeKycRequired: return { major: TransactionMajorState.Suspended, minor: TransactionMinorState.MergeKycRequired, }; - case PeerPullPaymentInitiationStatus.Aborted: + case PeerPullPaymentCreditStatus.Aborted: return { major: TransactionMajorState.Aborted, }; - case PeerPullPaymentInitiationStatus.AbortingDeletePurse: + case PeerPullPaymentCreditStatus.AbortingDeletePurse: return { major: TransactionMajorState.Aborting, minor: TransactionMinorState.DeletePurse, }; - case PeerPullPaymentInitiationStatus.Failed: + case PeerPullPaymentCreditStatus.Failed: return { major: TransactionMajorState.Failed, }; - case PeerPullPaymentInitiationStatus.SuspendedAbortingDeletePurse: + case PeerPullPaymentCreditStatus.SuspendedAbortingDeletePurse: return { major: TransactionMajorState.Aborting, minor: TransactionMinorState.DeletePurse, @@ -1131,34 +1131,34 @@ export function computePeerPullCreditTransactionState( } export function computePeerPullCreditTransactionActions( - pullCreditRecord: PeerPullPaymentInitiationRecord, + pullCreditRecord: PeerPullCreditRecord, ): TransactionAction[] { switch (pullCreditRecord.status) { - case PeerPullPaymentInitiationStatus.PendingCreatePurse: + case PeerPullPaymentCreditStatus.PendingCreatePurse: return [TransactionAction.Abort, TransactionAction.Suspend]; - case PeerPullPaymentInitiationStatus.PendingMergeKycRequired: + case PeerPullPaymentCreditStatus.PendingMergeKycRequired: return [TransactionAction.Abort, TransactionAction.Suspend]; - case PeerPullPaymentInitiationStatus.PendingReady: + case PeerPullPaymentCreditStatus.PendingReady: return [TransactionAction.Abort, TransactionAction.Suspend]; - case PeerPullPaymentInitiationStatus.Done: + case PeerPullPaymentCreditStatus.Done: return [TransactionAction.Delete]; - case PeerPullPaymentInitiationStatus.PendingWithdrawing: + case PeerPullPaymentCreditStatus.PendingWithdrawing: return [TransactionAction.Abort, TransactionAction.Suspend]; - case PeerPullPaymentInitiationStatus.SuspendedCreatePurse: + case PeerPullPaymentCreditStatus.SuspendedCreatePurse: return [TransactionAction.Resume, TransactionAction.Abort]; - case PeerPullPaymentInitiationStatus.SuspendedReady: + case PeerPullPaymentCreditStatus.SuspendedReady: return [TransactionAction.Abort, TransactionAction.Resume]; - case PeerPullPaymentInitiationStatus.SuspendedWithdrawing: + case PeerPullPaymentCreditStatus.SuspendedWithdrawing: return [TransactionAction.Resume, TransactionAction.Fail]; - case PeerPullPaymentInitiationStatus.SuspendedMergeKycRequired: + case PeerPullPaymentCreditStatus.SuspendedMergeKycRequired: return [TransactionAction.Resume, TransactionAction.Fail]; - case PeerPullPaymentInitiationStatus.Aborted: + case PeerPullPaymentCreditStatus.Aborted: return [TransactionAction.Delete]; - case PeerPullPaymentInitiationStatus.AbortingDeletePurse: + case PeerPullPaymentCreditStatus.AbortingDeletePurse: return [TransactionAction.Suspend, TransactionAction.Fail]; - case PeerPullPaymentInitiationStatus.Failed: + case PeerPullPaymentCreditStatus.Failed: return [TransactionAction.Delete]; - case PeerPullPaymentInitiationStatus.SuspendedAbortingDeletePurse: + case PeerPullPaymentCreditStatus.SuspendedAbortingDeletePurse: return [TransactionAction.Resume, TransactionAction.Fail]; } } |