Skip to content

Add evaluateTransaction to Cardano.Api.Experimental#1205

Merged
carbolymer merged 1 commit into
masterfrom
mgalazyn/refactor/move-evaltx-to-api
May 18, 2026
Merged

Add evaluateTransaction to Cardano.Api.Experimental#1205
carbolymer merged 1 commit into
masterfrom
mgalazyn/refactor/move-evaltx-to-api

Conversation

@carbolymer
Copy link
Copy Markdown
Contributor

@carbolymer carbolymer commented May 14, 2026

Context

Closes #1204

cardano-api has individual building blocks for transaction evaluation (evaluateTransactionExecutionUnits, evaluateTransactionFee, evaluateTransactionBalance) but no single function that runs the full evaluate execution units, compute fee, check balance pipeline on a signed transaction.

cardano-rpc's evalTxMethod filled this gap by inlining the pipeline with ledger internals directly. This PR extracts that logic into a reusable cardano-api function.

Changes

  • cardano-api: Add evaluateTransaction and evaluateSignedTx to Cardano.Api.Experimental, composing script evaluation, fee computation via setMinFeeTxUtxo, and balance checking into a single pure function. Add TxEvaluationResult result type with fee, per-redeemer execution units, and balance fields.
  • cardano-rpc: Refactor evalTxMethod to call Exp.evaluateTransaction instead of inlining the pipeline (-46 lines).
  • Tests: Three new property tests for evaluateTransaction - positive fee, empty execution units for script-free transactions, and mempty balance for transactions balanced by calcMinFeeRecursive.

How to trust this PR

The core function (evaluateTransaction in Fee.hs) is a direct extraction of the logic previously in Eval.hs lines 83-137. The pipeline is:

  1. evaluateTransactionExecutionUnits - run scripts
  2. Substitute evaluated ExUnits into the redeemer map (failed redeemers keep client-supplied units)
  3. setMinFeeTxUtxo - compute fee for the concrete signed tx with UTxO context
  4. evalBalanceTxBody - check the balance

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated
  • Self-reviewed the diff
  • Changelog fragments added in .changes/

@carbolymer carbolymer self-assigned this May 14, 2026
@carbolymer carbolymer force-pushed the mgalazyn/refactor/move-evaltx-to-api branch 2 times, most recently from 47dd9d1 to 10cf9be Compare May 15, 2026 18:01
@carbolymer carbolymer changed the title Refactor: move evaltx to api Add evaluateTransaction to Cardano.Api.Experimental May 15, 2026
@carbolymer carbolymer marked this pull request as ready for review May 15, 2026 18:02
Copilot AI review requested due to automatic review settings May 15, 2026 18:02
@carbolymer carbolymer force-pushed the mgalazyn/refactor/move-evaltx-to-api branch from 10cf9be to 91d7750 Compare May 15, 2026 18:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Extracts the "evaluate execution units → compute min fee → check balance" pipeline that was inlined in cardano-rpc's evalTxMethod into a reusable Cardano.Api.Experimental function (evaluateTransaction, plus a SignedTx-flavoured wrapper evaluateSignedTx), introduces a TxEvaluationResult record, and refactors evalTxMethod to call the new function. Adds three property tests covering the new function.

Changes:

  • Add evaluateTransaction / evaluateSignedTx / TxEvaluationResult to Cardano.Api.Experimental.Tx.Internal.Fee and re-export through Cardano.Api.Experimental.Tx and Cardano.Api.Experimental under a new "Transaction evaluation" section.
  • Refactor evalTxMethod in cardano-rpc to delegate the pipeline to the new function (−46 lines).
  • Add property tests for fee positivity, empty ExUnits for script-free txs, and mempty balance for balanced txs; add two Herald changelog fragments (feature for cardano-api, refactoring for cardano-rpc).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
cardano-api/src/Cardano/Api/Experimental/Tx/Internal/Fee.hs Adds TxEvaluationResult data type and evaluateTransaction orchestration function.
cardano-api/src/Cardano/Api/Experimental/Tx.hs Adds evaluateSignedTx wrapper and re-exports new symbols under a "Transaction evaluation" section.
cardano-api/src/Cardano/Api/Experimental.hs Re-exports new evaluation API under a new sub-section.
cardano-api/test/cardano-api-test/Test/Cardano/Api/Experimental/Fee.hs Three new property tests for the new evaluation function.
cardano-rpc/src/Cardano/Rpc/Server/Internal/UtxoRpc/Eval.hs Refactor: replace inlined pipeline with a call to Exp.evaluateTransaction.
.changes/20260515_cardano_api_evaluate_transaction.yml Herald changelog fragment (feature) for cardano-api.
.changes/20260515_cardano_rpc_use_evaluate_transaction.yml Herald changelog fragment (refactoring) for cardano-rpc.

Comment thread cardano-api/src/Cardano/Api/Experimental/Tx/Internal/Fee.hs
Comment thread cardano-api/src/Cardano/Api/Experimental/Tx/Internal/Fee.hs
Comment thread cardano-api/src/Cardano/Api/Experimental/Tx.hs
Comment thread cardano-api/test/cardano-api-test/Test/Cardano/Api/Experimental/Fee.hs Outdated
@Jimbo4350 Jimbo4350 self-requested a review May 15, 2026 18:49
…rimental`, composing script evaluation, fee computation, and balance checking into a single pure function for signed transactions.
@carbolymer carbolymer force-pushed the mgalazyn/refactor/move-evaltx-to-api branch from 91d7750 to 39fdbc2 Compare May 18, 2026 10:15
@carbolymer carbolymer enabled auto-merge May 18, 2026 10:16
@carbolymer carbolymer added this pull request to the merge queue May 18, 2026
Merged via the queue into master with commit fea6c67 May 18, 2026
31 checks passed
@carbolymer carbolymer deleted the mgalazyn/refactor/move-evaltx-to-api branch May 18, 2026 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extract transaction evaluation pipeline from cardano-rpc into cardano-api

3 participants