diff options
Diffstat (limited to 'packages/taler-wallet-core/src/operations/pay-peer-pull-debit.ts')
-rw-r--r-- | packages/taler-wallet-core/src/operations/pay-peer-pull-debit.ts | 178 |
1 files changed, 89 insertions, 89 deletions
diff --git a/packages/taler-wallet-core/src/operations/pay-peer-pull-debit.ts b/packages/taler-wallet-core/src/operations/pay-peer-pull-debit.ts index 0de91bf97..f357c41d5 100644 --- a/packages/taler-wallet-core/src/operations/pay-peer-pull-debit.ts +++ b/packages/taler-wallet-core/src/operations/pay-peer-pull-debit.ts @@ -140,10 +140,10 @@ async function handlePurseCreationConflict( ); await ws.db - .mktx((x) => [x.peerPullPaymentIncoming]) + .mktx((x) => [x.peerPullDebit]) .runReadWrite(async (tx) => { - const myPpi = await tx.peerPullPaymentIncoming.get( - peerPullInc.peerPullPaymentIncomingId, + const myPpi = await tx.peerPullDebit.get( + peerPullInc.peerPullDebitId, ); if (!myPpi) { return; @@ -162,7 +162,7 @@ async function handlePurseCreationConflict( default: return; } - await tx.peerPullPaymentIncoming.put(myPpi); + await tx.peerPullDebit.put(myPpi); }); return TaskRunResult.finished(); } @@ -171,7 +171,7 @@ async function processPeerPullDebitPendingDeposit( ws: InternalWalletState, peerPullInc: PeerPullPaymentIncomingRecord, ): Promise<TaskRunResult> { - const peerPullPaymentIncomingId = peerPullInc.peerPullPaymentIncomingId; + const peerPullDebitId = peerPullInc.peerPullDebitId; const pursePub = peerPullInc.pursePub; const coinSel = peerPullInc.coinSel; @@ -202,7 +202,7 @@ async function processPeerPullDebitPendingDeposit( const transactionId = constructTransactionIdentifier({ tag: TransactionType.PeerPullDebit, - peerPullPaymentIncomingId, + peerPullDebitId, }); const httpResp = await ws.http.fetch(purseDepositUrl.href, { @@ -218,10 +218,10 @@ async function processPeerPullDebitPendingDeposit( logger.trace(`purse deposit response: ${j2s(resp)}`); const transitionInfo = await ws.db - .mktx((x) => [x.peerPullPaymentIncoming]) + .mktx((x) => [x.peerPullDebit]) .runReadWrite(async (tx) => { - const pi = await tx.peerPullPaymentIncoming.get( - peerPullPaymentIncomingId, + const pi = await tx.peerPullDebit.get( + peerPullDebitId, ); if (!pi) { throw Error("peer pull payment not found anymore"); @@ -230,9 +230,9 @@ async function processPeerPullDebitPendingDeposit( return; } const oldTxState = computePeerPullDebitTransactionState(pi); - pi.status = PeerPullDebitRecordStatus.DonePaid; + pi.status = PeerPullDebitRecordStatus.Done; const newTxState = computePeerPullDebitTransactionState(pi); - await tx.peerPullPaymentIncoming.put(pi); + await tx.peerPullDebit.put(pi); return { oldTxState, newTxState }; }); notifyTransition(ws, transactionId, transitionInfo); @@ -241,15 +241,15 @@ async function processPeerPullDebitPendingDeposit( case HttpStatusCode.Gone: { const transitionInfo = await ws.db .mktx((x) => [ - x.peerPullPaymentIncoming, + x.peerPullDebit, x.refreshGroups, x.denominations, x.coinAvailability, x.coins, ]) .runReadWrite(async (tx) => { - const pi = await tx.peerPullPaymentIncoming.get( - peerPullPaymentIncomingId, + const pi = await tx.peerPullDebit.get( + peerPullDebitId, ); if (!pi) { throw Error("peer pull payment not found anymore"); @@ -284,7 +284,7 @@ async function processPeerPullDebitPendingDeposit( pi.status = PeerPullDebitRecordStatus.AbortingRefresh; pi.abortRefreshGroupId = refresh.refreshGroupId; const newTxState = computePeerPullDebitTransactionState(pi); - await tx.peerPullPaymentIncoming.put(pi); + await tx.peerPullDebit.put(pi); return { oldTxState, newTxState }; }); notifyTransition(ws, transactionId, transitionInfo); @@ -308,15 +308,15 @@ async function processPeerPullDebitAbortingRefresh( ws: InternalWalletState, peerPullInc: PeerPullPaymentIncomingRecord, ): Promise<TaskRunResult> { - const peerPullPaymentIncomingId = peerPullInc.peerPullPaymentIncomingId; + const peerPullDebitId = peerPullInc.peerPullDebitId; const abortRefreshGroupId = peerPullInc.abortRefreshGroupId; checkLogicInvariant(!!abortRefreshGroupId); const transactionId = constructTransactionIdentifier({ tag: TransactionType.PeerPullDebit, - peerPullPaymentIncomingId, + peerPullDebitId, }); const transitionInfo = await ws.db - .mktx((x) => [x.refreshGroups, x.peerPullPaymentIncoming]) + .mktx((x) => [x.refreshGroups, x.peerPullDebit]) .runReadWrite(async (tx) => { const refreshGroup = await tx.refreshGroups.get(abortRefreshGroupId); let newOpState: PeerPullDebitRecordStatus | undefined; @@ -335,8 +335,8 @@ async function processPeerPullDebitAbortingRefresh( } } if (newOpState) { - const newDg = await tx.peerPullPaymentIncoming.get( - peerPullPaymentIncomingId, + const newDg = await tx.peerPullDebit.get( + peerPullDebitId, ); if (!newDg) { return; @@ -344,7 +344,7 @@ async function processPeerPullDebitAbortingRefresh( const oldTxState = computePeerPullDebitTransactionState(newDg); newDg.status = newOpState; const newTxState = computePeerPullDebitTransactionState(newDg); - await tx.peerPullPaymentIncoming.put(newDg); + await tx.peerPullDebit.put(newDg); return { oldTxState, newTxState }; } return undefined; @@ -356,12 +356,12 @@ async function processPeerPullDebitAbortingRefresh( export async function processPeerPullDebit( ws: InternalWalletState, - peerPullPaymentIncomingId: string, + peerPullDebitId: string, ): Promise<TaskRunResult> { const peerPullInc = await ws.db - .mktx((x) => [x.peerPullPaymentIncoming]) + .mktx((x) => [x.peerPullDebit]) .runReadOnly(async (tx) => { - return tx.peerPullPaymentIncoming.get(peerPullPaymentIncomingId); + return tx.peerPullDebit.get(peerPullDebitId); }); if (!peerPullInc) { throw Error("peer pull debit not found"); @@ -380,31 +380,31 @@ export async function confirmPeerPullDebit( ws: InternalWalletState, req: ConfirmPeerPullDebitRequest, ): Promise<AcceptPeerPullPaymentResponse> { - let peerPullPaymentIncomingId: string; + let peerPullDebitId: string; if (req.transactionId) { const parsedTx = parseTransactionIdentifier(req.transactionId); if (!parsedTx || parsedTx.tag !== TransactionType.PeerPullDebit) { throw Error("invalid peer-pull-debit transaction identifier"); } - peerPullPaymentIncomingId = parsedTx.peerPullPaymentIncomingId; - } else if (req.peerPullPaymentIncomingId) { - peerPullPaymentIncomingId = req.peerPullPaymentIncomingId; + peerPullDebitId = parsedTx.peerPullDebitId; + } else if (req.peerPullDebitId) { + peerPullDebitId = req.peerPullDebitId; } else { throw Error( - "invalid request, transactionId or peerPullPaymentIncomingId required", + "invalid request, transactionId or peerPullDebitId required", ); } const peerPullInc = await ws.db - .mktx((x) => [x.peerPullPaymentIncoming]) + .mktx((x) => [x.peerPullDebit]) .runReadOnly(async (tx) => { - return tx.peerPullPaymentIncoming.get(peerPullPaymentIncomingId); + return tx.peerPullDebit.get(peerPullDebitId); }); if (!peerPullInc) { throw Error( - `can't accept unknown incoming p2p pull payment (${req.peerPullPaymentIncomingId})`, + `can't accept unknown incoming p2p pull payment (${req.peerPullDebitId})`, ); } @@ -437,15 +437,15 @@ export async function confirmPeerPullDebit( x.coins, x.denominations, x.refreshGroups, - x.peerPullPaymentIncoming, + x.peerPullDebit, x.coinAvailability, ]) .runReadWrite(async (tx) => { await spendCoins(ws, tx, { - // allocationId: `txn:peer-pull-debit:${req.peerPullPaymentIncomingId}`, + // allocationId: `txn:peer-pull-debit:${req.peerPullDebitId}`, allocationId: constructTransactionIdentifier({ tag: TransactionType.PeerPullDebit, - peerPullPaymentIncomingId, + peerPullDebitId, }), coinPubs: sel.coins.map((x) => x.coinPub), contributions: sel.coins.map((x) => @@ -454,8 +454,8 @@ export async function confirmPeerPullDebit( refreshReason: RefreshReason.PayPeerPull, }); - const pi = await tx.peerPullPaymentIncoming.get( - peerPullPaymentIncomingId, + const pi = await tx.peerPullDebit.get( + peerPullDebitId, ); if (!pi) { throw Error(); @@ -468,7 +468,7 @@ export async function confirmPeerPullDebit( totalCost: Amounts.stringify(totalAmount), }; } - await tx.peerPullPaymentIncoming.put(pi); + await tx.peerPullDebit.put(pi); return pi; }); @@ -476,7 +476,7 @@ export async function confirmPeerPullDebit( const transactionId = constructTransactionIdentifier({ tag: TransactionType.PeerPullDebit, - peerPullPaymentIncomingId, + peerPullDebitId, }); return { @@ -499,9 +499,9 @@ export async function preparePeerPullDebit( } const existingPullIncomingRecord = await ws.db - .mktx((x) => [x.peerPullPaymentIncoming]) + .mktx((x) => [x.peerPullDebit]) .runReadOnly(async (tx) => { - return tx.peerPullPaymentIncoming.indexes.byExchangeAndContractPriv.get([ + return tx.peerPullDebit.indexes.byExchangeAndContractPriv.get([ uri.exchangeBaseUrl, uri.contractPriv, ]); @@ -513,12 +513,12 @@ export async function preparePeerPullDebit( amountRaw: existingPullIncomingRecord.contractTerms.amount, amountEffective: existingPullIncomingRecord.totalCostEstimated, contractTerms: existingPullIncomingRecord.contractTerms, - peerPullPaymentIncomingId: - existingPullIncomingRecord.peerPullPaymentIncomingId, + peerPullDebitId: + existingPullIncomingRecord.peerPullDebitId, transactionId: constructTransactionIdentifier({ tag: TransactionType.PeerPullDebit, - peerPullPaymentIncomingId: - existingPullIncomingRecord.peerPullPaymentIncomingId, + peerPullDebitId: + existingPullIncomingRecord.peerPullDebitId, }), }; } @@ -553,7 +553,7 @@ export async function preparePeerPullDebit( codecForExchangePurseStatus(), ); - const peerPullPaymentIncomingId = encodeCrock(getRandomBytes(32)); + const peerPullDebitId = encodeCrock(getRandomBytes(32)); let contractTerms: PeerContractTerms; @@ -588,10 +588,10 @@ export async function preparePeerPullDebit( ); await ws.db - .mktx((x) => [x.peerPullPaymentIncoming]) + .mktx((x) => [x.peerPullDebit]) .runReadWrite(async (tx) => { - await tx.peerPullPaymentIncoming.add({ - peerPullPaymentIncomingId, + await tx.peerPullDebit.add({ + peerPullDebitId, contractPriv: contractPriv, exchangeBaseUrl: exchangeBaseUrl, pursePub: pursePub, @@ -607,42 +607,42 @@ export async function preparePeerPullDebit( amountEffective: Amounts.stringify(totalAmount), amountRaw: contractTerms.amount, contractTerms: contractTerms, - peerPullPaymentIncomingId, + peerPullDebitId, transactionId: constructTransactionIdentifier({ tag: TransactionType.PeerPullDebit, - peerPullPaymentIncomingId: peerPullPaymentIncomingId, + peerPullDebitId: peerPullDebitId, }), }; } export async function suspendPeerPullDebitTransaction( ws: InternalWalletState, - peerPullPaymentIncomingId: string, + peerPullDebitId: string, ) { const taskId = constructTaskIdentifier({ tag: PendingTaskType.PeerPullDebit, - peerPullPaymentIncomingId, + peerPullDebitId, }); const transactionId = constructTransactionIdentifier({ tag: TransactionType.PeerPullDebit, - peerPullPaymentIncomingId, + peerPullDebitId, }); stopLongpolling(ws, taskId); const transitionInfo = await ws.db - .mktx((x) => [x.peerPullPaymentIncoming]) + .mktx((x) => [x.peerPullDebit]) .runReadWrite(async (tx) => { - const pullDebitRec = await tx.peerPullPaymentIncoming.get( - peerPullPaymentIncomingId, + const pullDebitRec = await tx.peerPullDebit.get( + peerPullDebitId, ); if (!pullDebitRec) { - logger.warn(`peer pull debit ${peerPullPaymentIncomingId} not found`); + logger.warn(`peer pull debit ${peerPullDebitId} not found`); return; } let newStatus: PeerPullDebitRecordStatus | undefined = undefined; switch (pullDebitRec.status) { case PeerPullDebitRecordStatus.DialogProposed: break; - case PeerPullDebitRecordStatus.DonePaid: + case PeerPullDebitRecordStatus.Done: break; case PeerPullDebitRecordStatus.PendingDeposit: newStatus = PeerPullDebitRecordStatus.SuspendedDeposit; @@ -665,7 +665,7 @@ export async function suspendPeerPullDebitTransaction( const oldTxState = computePeerPullDebitTransactionState(pullDebitRec); pullDebitRec.status = newStatus; const newTxState = computePeerPullDebitTransactionState(pullDebitRec); - await tx.peerPullPaymentIncoming.put(pullDebitRec); + await tx.peerPullDebit.put(pullDebitRec); return { oldTxState, newTxState, @@ -678,25 +678,25 @@ export async function suspendPeerPullDebitTransaction( export async function abortPeerPullDebitTransaction( ws: InternalWalletState, - peerPullPaymentIncomingId: string, + peerPullDebitId: string, ) { const taskId = constructTaskIdentifier({ tag: PendingTaskType.PeerPullDebit, - peerPullPaymentIncomingId, + peerPullDebitId, }); const transactionId = constructTransactionIdentifier({ tag: TransactionType.PeerPullDebit, - peerPullPaymentIncomingId, + peerPullDebitId, }); stopLongpolling(ws, taskId); const transitionInfo = await ws.db - .mktx((x) => [x.peerPullPaymentIncoming]) + .mktx((x) => [x.peerPullDebit]) .runReadWrite(async (tx) => { - const pullDebitRec = await tx.peerPullPaymentIncoming.get( - peerPullPaymentIncomingId, + const pullDebitRec = await tx.peerPullDebit.get( + peerPullDebitId, ); if (!pullDebitRec) { - logger.warn(`peer pull debit ${peerPullPaymentIncomingId} not found`); + logger.warn(`peer pull debit ${peerPullDebitId} not found`); return; } let newStatus: PeerPullDebitRecordStatus | undefined = undefined; @@ -704,7 +704,7 @@ export async function abortPeerPullDebitTransaction( case PeerPullDebitRecordStatus.DialogProposed: newStatus = PeerPullDebitRecordStatus.Aborted; break; - case PeerPullDebitRecordStatus.DonePaid: + case PeerPullDebitRecordStatus.Done: break; case PeerPullDebitRecordStatus.PendingDeposit: newStatus = PeerPullDebitRecordStatus.AbortingRefresh; @@ -726,7 +726,7 @@ export async function abortPeerPullDebitTransaction( const oldTxState = computePeerPullDebitTransactionState(pullDebitRec); pullDebitRec.status = newStatus; const newTxState = computePeerPullDebitTransactionState(pullDebitRec); - await tx.peerPullPaymentIncoming.put(pullDebitRec); + await tx.peerPullDebit.put(pullDebitRec); return { oldTxState, newTxState, @@ -739,25 +739,25 @@ export async function abortPeerPullDebitTransaction( export async function failPeerPullDebitTransaction( ws: InternalWalletState, - peerPullPaymentIncomingId: string, + peerPullDebitId: string, ) { const taskId = constructTaskIdentifier({ tag: PendingTaskType.PeerPullDebit, - peerPullPaymentIncomingId, + peerPullDebitId, }); const transactionId = constructTransactionIdentifier({ tag: TransactionType.PeerPullDebit, - peerPullPaymentIncomingId, + peerPullDebitId, }); stopLongpolling(ws, taskId); const transitionInfo = await ws.db - .mktx((x) => [x.peerPullPaymentIncoming]) + .mktx((x) => [x.peerPullDebit]) .runReadWrite(async (tx) => { - const pullDebitRec = await tx.peerPullPaymentIncoming.get( - peerPullPaymentIncomingId, + const pullDebitRec = await tx.peerPullDebit.get( + peerPullDebitId, ); if (!pullDebitRec) { - logger.warn(`peer pull debit ${peerPullPaymentIncomingId} not found`); + logger.warn(`peer pull debit ${peerPullDebitId} not found`); return; } let newStatus: PeerPullDebitRecordStatus | undefined = undefined; @@ -765,7 +765,7 @@ export async function failPeerPullDebitTransaction( case PeerPullDebitRecordStatus.DialogProposed: newStatus = PeerPullDebitRecordStatus.Aborted; break; - case PeerPullDebitRecordStatus.DonePaid: + case PeerPullDebitRecordStatus.Done: break; case PeerPullDebitRecordStatus.PendingDeposit: break; @@ -787,7 +787,7 @@ export async function failPeerPullDebitTransaction( const oldTxState = computePeerPullDebitTransactionState(pullDebitRec); pullDebitRec.status = newStatus; const newTxState = computePeerPullDebitTransactionState(pullDebitRec); - await tx.peerPullPaymentIncoming.put(pullDebitRec); + await tx.peerPullDebit.put(pullDebitRec); return { oldTxState, newTxState, @@ -800,31 +800,31 @@ export async function failPeerPullDebitTransaction( export async function resumePeerPullDebitTransaction( ws: InternalWalletState, - peerPullPaymentIncomingId: string, + peerPullDebitId: string, ) { const taskId = constructTaskIdentifier({ tag: PendingTaskType.PeerPullDebit, - peerPullPaymentIncomingId, + peerPullDebitId, }); const transactionId = constructTransactionIdentifier({ tag: TransactionType.PeerPullDebit, - peerPullPaymentIncomingId, + peerPullDebitId, }); stopLongpolling(ws, taskId); const transitionInfo = await ws.db - .mktx((x) => [x.peerPullPaymentIncoming]) + .mktx((x) => [x.peerPullDebit]) .runReadWrite(async (tx) => { - const pullDebitRec = await tx.peerPullPaymentIncoming.get( - peerPullPaymentIncomingId, + const pullDebitRec = await tx.peerPullDebit.get( + peerPullDebitId, ); if (!pullDebitRec) { - logger.warn(`peer pull debit ${peerPullPaymentIncomingId} not found`); + logger.warn(`peer pull debit ${peerPullDebitId} not found`); return; } let newStatus: PeerPullDebitRecordStatus | undefined = undefined; switch (pullDebitRec.status) { case PeerPullDebitRecordStatus.DialogProposed: - case PeerPullDebitRecordStatus.DonePaid: + case PeerPullDebitRecordStatus.Done: case PeerPullDebitRecordStatus.PendingDeposit: break; case PeerPullDebitRecordStatus.SuspendedDeposit: @@ -846,7 +846,7 @@ export async function resumePeerPullDebitTransaction( const oldTxState = computePeerPullDebitTransactionState(pullDebitRec); pullDebitRec.status = newStatus; const newTxState = computePeerPullDebitTransactionState(pullDebitRec); - await tx.peerPullPaymentIncoming.put(pullDebitRec); + await tx.peerPullDebit.put(pullDebitRec); return { oldTxState, newTxState, @@ -872,7 +872,7 @@ export function computePeerPullDebitTransactionState( major: TransactionMajorState.Pending, minor: TransactionMinorState.Deposit, }; - case PeerPullDebitRecordStatus.DonePaid: + case PeerPullDebitRecordStatus.Done: return { major: TransactionMajorState.Done, }; @@ -910,7 +910,7 @@ export function computePeerPullDebitTransactionActions( return []; case PeerPullDebitRecordStatus.PendingDeposit: return [TransactionAction.Abort, TransactionAction.Suspend]; - case PeerPullDebitRecordStatus.DonePaid: + case PeerPullDebitRecordStatus.Done: return [TransactionAction.Delete]; case PeerPullDebitRecordStatus.SuspendedDeposit: return [TransactionAction.Resume, TransactionAction.Abort]; |