diff options
-rw-r--r-- | packages/taler-wallet-core/src/operations/transactions.ts | 52 |
1 files changed, 46 insertions, 6 deletions
diff --git a/packages/taler-wallet-core/src/operations/transactions.ts b/packages/taler-wallet-core/src/operations/transactions.ts index 6e8ebc4f4..fea165588 100644 --- a/packages/taler-wallet-core/src/operations/transactions.ts +++ b/packages/taler-wallet-core/src/operations/transactions.ts @@ -188,7 +188,12 @@ export async function getTransactionById( } else if (type === TransactionType.Payment) { const proposalId = rest[0]; return await ws.db - .mktx((x) => [x.purchases, x.tombstones, x.operationRetries]) + .mktx((x) => [ + x.purchases, + x.tombstones, + x.operationRetries, + x.contractTerms, + ]) .runReadWrite(async (tx) => { const purchase = await tx.purchases.get(proposalId); if (!purchase) throw Error("not found"); @@ -207,13 +212,28 @@ export async function getTransactionById( }), ); - const download = await expectProposalDownload(ws, purchase); + // const download = await expectProposalDownload(ws, purchase); + // FIXME: this is what expectProposalDownload, but nested tx is not supported + if (!purchase.download) { + throw Error("expected proposal to be downloaded"); + } + const contractTerms = await tx.contractTerms.get( + purchase.download.contractTermsHash, + ); + if (!contractTerms) { + throw Error("contract terms not found"); + } + const contractData = extractContractData( + contractTerms.contractTermsRaw, + purchase.download.contractTermsHash, + purchase.download.contractTermsMerchantSig, + ); const cleanRefunds = filteredRefunds.filter( (x): x is WalletRefundItem => !!x, ); - const contractData = download.contractData; + // const contractData = download.contractData; const refunds = mergeRefundByExecutionTime( cleanRefunds, Amounts.getZero(contractData.amount.currency), @@ -263,7 +283,12 @@ export async function getTransactionById( const executionTimeStr = rest[1]; return await ws.db - .mktx((x) => [x.operationRetries, x.purchases, x.tombstones]) + .mktx((x) => [ + x.operationRetries, + x.purchases, + x.tombstones, + x.contractTerms, + ]) .runReadWrite(async (tx) => { const purchase = await tx.purchases.get(proposalId); if (!purchase) throw Error("not found"); @@ -281,8 +306,23 @@ export async function getTransactionById( ), ); if (t) throw Error("deleted"); - const download = await expectProposalDownload(ws, purchase); - const contractData = download.contractData; + // const download = await expectProposalDownload(ws, purchase); + // const contractData = download.contractData; + // FIXME: this is what expectProposalDownload, but nested tx is not supported + if (!purchase.download) { + throw Error("expected proposal to be downloaded"); + } + const contractTerms = await tx.contractTerms.get( + purchase.download.contractTermsHash, + ); + if (!contractTerms) { + throw Error("contract terms not found"); + } + const contractData = extractContractData( + contractTerms.contractTermsRaw, + purchase.download.contractTermsHash, + purchase.download.contractTermsMerchantSig, + ); const refunds = mergeRefundByExecutionTime( [theRefund], Amounts.getZero(contractData.amount.currency), |