diff options
Diffstat (limited to 'packages/taler-wallet-core/src')
-rw-r--r-- | packages/taler-wallet-core/src/operations/pay-merchant.ts | 44 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/operations/transactions.ts | 38 |
2 files changed, 32 insertions, 50 deletions
diff --git a/packages/taler-wallet-core/src/operations/pay-merchant.ts b/packages/taler-wallet-core/src/operations/pay-merchant.ts index 2b0ea1f96..082dc42d2 100644 --- a/packages/taler-wallet-core/src/operations/pay-merchant.ts +++ b/packages/taler-wallet-core/src/operations/pay-merchant.ts @@ -129,6 +129,7 @@ import { } from "./common.js"; import { getExchangeDetails } from "./exchanges.js"; import { createRefreshGroup, getTotalRefreshCost } from "./refresh.js"; +import { GetReadOnlyAccess } from "../util/query.js"; /** * Logger. @@ -257,6 +258,9 @@ function getPayRequestTimeout(purchase: PurchaseRecord): Duration { export async function expectProposalDownload( ws: InternalWalletState, p: PurchaseRecord, + parentTx?: GetReadOnlyAccess<{ + contractTerms: typeof WalletStoresV1.contractTerms; + }>, ): Promise<{ contractData: WalletContractData; contractTermsRaw: any; @@ -265,24 +269,32 @@ export async function expectProposalDownload( throw Error("expected proposal to be downloaded"); } const download = p.download; + + async function getFromTransaction( + tx: Exclude<typeof parentTx, undefined>, + ): Promise<ReturnType<typeof expectProposalDownload>> { + const contractTerms = await tx.contractTerms.get( + download.contractTermsHash, + ); + if (!contractTerms) { + throw Error("contract terms not found"); + } + return { + contractData: extractContractData( + contractTerms.contractTermsRaw, + download.contractTermsHash, + download.contractTermsMerchantSig, + ), + contractTermsRaw: contractTerms.contractTermsRaw, + }; + } + + if (parentTx) { + return getFromTransaction(parentTx); + } return await ws.db .mktx((x) => [x.contractTerms]) - .runReadOnly(async (tx) => { - const contractTerms = await tx.contractTerms.get( - download.contractTermsHash, - ); - if (!contractTerms) { - throw Error("contract terms not found"); - } - return { - contractData: extractContractData( - contractTerms.contractTermsRaw, - download.contractTermsHash, - download.contractTermsMerchantSig, - ), - contractTermsRaw: contractTerms.contractTermsRaw, - }; - }); + .runReadOnly(getFromTransaction); } export function extractContractData( diff --git a/packages/taler-wallet-core/src/operations/transactions.ts b/packages/taler-wallet-core/src/operations/transactions.ts index fea165588..3f1d0a224 100644 --- a/packages/taler-wallet-core/src/operations/transactions.ts +++ b/packages/taler-wallet-core/src/operations/transactions.ts @@ -212,28 +212,13 @@ export async function getTransactionById( }), ); - // const download = await expectProposalDownload(ws, purchase); + const download = await expectProposalDownload(ws, purchase, tx); - // 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), @@ -306,23 +291,8 @@ export async function getTransactionById( ), ); if (t) throw Error("deleted"); - // 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 download = await expectProposalDownload(ws, purchase, tx); + const contractData = download.contractData; const refunds = mergeRefundByExecutionTime( [theRefund], Amounts.getZero(contractData.amount.currency), |