better workaround with duplication
This commit is contained in:
parent
683c89ab71
commit
e63f202e36
@ -129,6 +129,7 @@ import {
|
|||||||
} from "./common.js";
|
} from "./common.js";
|
||||||
import { getExchangeDetails } from "./exchanges.js";
|
import { getExchangeDetails } from "./exchanges.js";
|
||||||
import { createRefreshGroup, getTotalRefreshCost } from "./refresh.js";
|
import { createRefreshGroup, getTotalRefreshCost } from "./refresh.js";
|
||||||
|
import { GetReadOnlyAccess } from "../util/query.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logger.
|
* Logger.
|
||||||
@ -257,6 +258,9 @@ function getPayRequestTimeout(purchase: PurchaseRecord): Duration {
|
|||||||
export async function expectProposalDownload(
|
export async function expectProposalDownload(
|
||||||
ws: InternalWalletState,
|
ws: InternalWalletState,
|
||||||
p: PurchaseRecord,
|
p: PurchaseRecord,
|
||||||
|
parentTx?: GetReadOnlyAccess<{
|
||||||
|
contractTerms: typeof WalletStoresV1.contractTerms;
|
||||||
|
}>,
|
||||||
): Promise<{
|
): Promise<{
|
||||||
contractData: WalletContractData;
|
contractData: WalletContractData;
|
||||||
contractTermsRaw: any;
|
contractTermsRaw: any;
|
||||||
@ -265,9 +269,10 @@ export async function expectProposalDownload(
|
|||||||
throw Error("expected proposal to be downloaded");
|
throw Error("expected proposal to be downloaded");
|
||||||
}
|
}
|
||||||
const download = p.download;
|
const download = p.download;
|
||||||
return await ws.db
|
|
||||||
.mktx((x) => [x.contractTerms])
|
async function getFromTransaction(
|
||||||
.runReadOnly(async (tx) => {
|
tx: Exclude<typeof parentTx, undefined>,
|
||||||
|
): Promise<ReturnType<typeof expectProposalDownload>> {
|
||||||
const contractTerms = await tx.contractTerms.get(
|
const contractTerms = await tx.contractTerms.get(
|
||||||
download.contractTermsHash,
|
download.contractTermsHash,
|
||||||
);
|
);
|
||||||
@ -282,7 +287,14 @@ export async function expectProposalDownload(
|
|||||||
),
|
),
|
||||||
contractTermsRaw: contractTerms.contractTermsRaw,
|
contractTermsRaw: contractTerms.contractTermsRaw,
|
||||||
};
|
};
|
||||||
});
|
}
|
||||||
|
|
||||||
|
if (parentTx) {
|
||||||
|
return getFromTransaction(parentTx);
|
||||||
|
}
|
||||||
|
return await ws.db
|
||||||
|
.mktx((x) => [x.contractTerms])
|
||||||
|
.runReadOnly(getFromTransaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function extractContractData(
|
export function extractContractData(
|
||||||
|
@ -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(
|
const cleanRefunds = filteredRefunds.filter(
|
||||||
(x): x is WalletRefundItem => !!x,
|
(x): x is WalletRefundItem => !!x,
|
||||||
);
|
);
|
||||||
|
|
||||||
// const contractData = download.contractData;
|
const contractData = download.contractData;
|
||||||
const refunds = mergeRefundByExecutionTime(
|
const refunds = mergeRefundByExecutionTime(
|
||||||
cleanRefunds,
|
cleanRefunds,
|
||||||
Amounts.getZero(contractData.amount.currency),
|
Amounts.getZero(contractData.amount.currency),
|
||||||
@ -306,23 +291,8 @@ export async function getTransactionById(
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (t) throw Error("deleted");
|
if (t) throw Error("deleted");
|
||||||
// const download = await expectProposalDownload(ws, purchase);
|
const download = await expectProposalDownload(ws, purchase, tx);
|
||||||
// const contractData = download.contractData;
|
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(
|
const refunds = mergeRefundByExecutionTime(
|
||||||
[theRefund],
|
[theRefund],
|
||||||
Amounts.getZero(contractData.amount.currency),
|
Amounts.getZero(contractData.amount.currency),
|
||||||
|
Loading…
Reference in New Issue
Block a user