diff options
author | Florian Dold <florian@dold.me> | 2023-02-20 03:36:46 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-02-20 03:36:46 +0100 |
commit | bd9904f6a057a6722f5ede036879a118bf0520a0 (patch) | |
tree | 41de62cff2593cd9f5cee98eca10dbcc844141a3 | |
parent | b718885907f4b6126900fcf7c3cce2f0948d6d68 (diff) |
-implement getTransaction for p2p credit txns
-rw-r--r-- | packages/taler-wallet-core/src/operations/transactions.ts | 81 |
1 files changed, 72 insertions, 9 deletions
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<Transaction> { 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`); |