From bd9904f6a057a6722f5ede036879a118bf0520a0 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 20 Feb 2023 03:36:46 +0100 Subject: -implement getTransaction for p2p credit txns --- .../src/operations/transactions.ts | 81 +++++++++++++++++++--- 1 file changed, 72 insertions(+), 9 deletions(-) (limited to 'packages/taler-wallet-core/src') diff --git a/packages/taler-wallet-core/src/operations/transactions.ts b/packages/taler-wallet-core/src/operations/transactions.ts index c988e1e84..faac808b1 100644 --- a/packages/taler-wallet-core/src/operations/transactions.ts +++ b/packages/taler-wallet-core/src/operations/transactions.ts @@ -136,10 +136,7 @@ export async function getTransactionById( req: TransactionByIdRequest, ): Promise { const { type, args: rest } = parseId("txn", req.transactionId); - if ( - type === TransactionType.Withdrawal || - type === TransactionType.PeerPullCredit - ) { + if (type === TransactionType.Withdrawal) { const withdrawalGroupId = rest[0]; return await ws.db .mktx((x) => [ @@ -341,11 +338,77 @@ export async function getTransactionById( return buildTransactionForPushPaymentDebit(debit, ct.contractTermsRaw); }); } else if (type === TransactionType.PeerPushCredit) { - // FIXME: Implement! - throw Error("getTransaction not yet implemented for PeerPushCredit"); - } else if (type === TransactionType.PeerPushCredit) { - // FIXME: Implement! - throw Error("getTransaction not yet implemented for PeerPullCredit"); + const peerPushPaymentIncomingId = rest[0]; + return await ws.db + .mktx((x) => [ + x.peerPushPaymentIncoming, + x.contractTerms, + x.withdrawalGroups, + x.operationRetries, + ]) + .runReadWrite(async (tx) => { + const pushInc = await tx.peerPushPaymentIncoming.get( + peerPushPaymentIncomingId, + ); + if (!pushInc) throw Error("not found"); + const ct = await tx.contractTerms.get(pushInc.contractTermsHash); + checkDbInvariant(!!ct); + + let wg: WithdrawalGroupRecord | undefined = undefined; + let wgOrt: OperationRetryRecord | undefined = undefined; + if (pushInc.withdrawalGroupId) { + wg = await tx.withdrawalGroups.get(pushInc.withdrawalGroupId); + if (wg) { + const withdrawalOpId = RetryTags.forWithdrawal(wg); + wgOrt = await tx.operationRetries.get(withdrawalOpId); + } + } + const pushIncOpId = RetryTags.forPeerPushCredit(pushInc); + let pushIncOrt = await tx.operationRetries.get(pushIncOpId); + + return buildTransactionForPeerPushCredit( + pushInc, + pushIncOrt, + ct.contractTermsRaw, + wg, + wgOrt, + ); + }); + } else if (type === TransactionType.PeerPullCredit) { + const pursePub = rest[0]; + return await ws.db + .mktx((x) => [ + x.peerPullPaymentInitiations, + x.contractTerms, + x.withdrawalGroups, + x.operationRetries, + ]) + .runReadWrite(async (tx) => { + const pushInc = await tx.peerPullPaymentInitiations.get(pursePub); + if (!pushInc) throw Error("not found"); + const ct = await tx.contractTerms.get(pushInc.contractTermsHash); + checkDbInvariant(!!ct); + + let wg: WithdrawalGroupRecord | undefined = undefined; + let wgOrt: OperationRetryRecord | undefined = undefined; + if (pushInc.withdrawalGroupId) { + wg = await tx.withdrawalGroups.get(pushInc.withdrawalGroupId); + if (wg) { + const withdrawalOpId = RetryTags.forWithdrawal(wg); + wgOrt = await tx.operationRetries.get(withdrawalOpId); + } + } + const pushIncOpId = RetryTags.forPeerPullPaymentInitiation(pushInc); + let pushIncOrt = await tx.operationRetries.get(pushIncOpId); + + return buildTransactionForPeerPullCredit( + pushInc, + pushIncOrt, + ct.contractTermsRaw, + wg, + wgOrt, + ); + }); } else { const unknownTxType: never = type; throw Error(`can't retrieve a '${unknownTxType}' transaction`); -- cgit v1.2.3