workaround: Failed transaction was started here

This commit is contained in:
Sebastian 2022-10-21 09:26:53 -03:00
parent 414b1b84e8
commit 683c89ab71
No known key found for this signature in database
GPG Key ID: BE4FF68352439FC1

View File

@ -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),