diff options
author | Sebastian <sebasjm@gmail.com> | 2022-10-21 10:11:41 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2022-10-21 10:11:41 -0300 |
commit | e63f202e369c9dd84bfcdb273a7219e936d1f699 (patch) | |
tree | f59afba3985a53ba23d5df022d872b2569221c53 /packages/taler-wallet-core/src/operations/pay-merchant.ts | |
parent | 683c89ab71a71fbd26bda58457ba5792e79d577f (diff) | |
download | wallet-core-e63f202e369c9dd84bfcdb273a7219e936d1f699.tar.xz |
better workaround with duplication
Diffstat (limited to 'packages/taler-wallet-core/src/operations/pay-merchant.ts')
-rw-r--r-- | packages/taler-wallet-core/src/operations/pay-merchant.ts | 44 |
1 files changed, 28 insertions, 16 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( |