diff options
Diffstat (limited to 'packages/taler-wallet-core/src')
| -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`);  | 
