Skip to content

Commit

Permalink
patch: recursively reevaluate
Browse files Browse the repository at this point in the history
  • Loading branch information
micahkendall committed Sep 8, 2024
1 parent de955cd commit 5369627
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/bright-pillows-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blaze-cardano/tx": patch
---

patch: evaluate recursively
10 changes: 9 additions & 1 deletion packages/blaze-tx/src/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1440,10 +1440,10 @@ export class TxBuilder {
new Value(-(bigintMax(this.fee, this.minimumFee) + this.feePadding)),
);
this.balanceChange(excessValue);
let evaluationFee: bigint = 0n;
if (this.redeemers.size() > 0) {
this.prepareCollateral();
tw = this.buildTransactionWitnessSet();
let evaluationFee: bigint = 0n;
try {
evaluationFee = await this.evaluate(draft_tx);
} catch (e) {
Expand Down Expand Up @@ -1479,6 +1479,7 @@ export class TxBuilder {
}
let final_size = draft_tx.toCbor().length / 2;
do {
const oldEvaluationFee = evaluationFee;
this.fee += BigInt(
Math.ceil((final_size - draft_size) * this.params.minFeeCoefficient),
);
Expand All @@ -1504,6 +1505,13 @@ export class TxBuilder {
for (const input of selectionResult.selectedInputs) {
this.addInput(input);
}
draft_tx.setBody(this.body);
if (evaluationFee > 0) {
evaluationFee = await this.evaluate(draft_tx);
if (evaluationFee > oldEvaluationFee) {
continue;
}
}
}
if (this.body.collateral()) {
this.balanceCollateralChange();
Expand Down

0 comments on commit 5369627

Please sign in to comment.