Skip to content

Migrate friendly transaction renderer to experimental API (Exp.Era era)#1374

Merged
Jimbo4350 merged 3 commits into
masterfrom
jordan/friendly-tx-experimental-api
May 12, 2026
Merged

Migrate friendly transaction renderer to experimental API (Exp.Era era)#1374
Jimbo4350 merged 3 commits into
masterfrom
jordan/friendly-tx-experimental-api

Conversation

@Jimbo4350
Copy link
Copy Markdown
Contributor

@Jimbo4350 Jimbo4350 commented May 6, 2026

Changelog

- description: |
    Migrate the friendly transaction renderer
    (`Cardano.CLI.Compatible.Json.Friendly`) off the old-API
    `Tx` / `TxBody` / `TxBodyContent` onto `Exp.SignedTx` /
    `Exp.UnsignedTx`. The public renderer entry points (`friendlyTx`,
    `friendlyTxBody`, `friendlyTxImpl`, `friendlyTxBodyImpl`) and every
    internal helper now use `Exp.Era era` and `Exp.LedgerEra era` —
    no `ShelleyBasedEra era` parameter or `ShelleyLedgerEra era` type
    family reference remains in the module. This is the last consumer
    of old-API `TxBodyContent` in cardano-cli.

    `cardano-cli debug transaction view` and `cardano-cli transaction
    view` now only accept Conway and Dijkstra tx / tx-body files.
    Pre-Conway files (Shelley, Allegra, Mary, Alonzo, Babbage) fail
    with a `DeprecatedEra` error at the call site, where the
    `InAnyShelleyBasedEra` witness is converted via `Exp.sbeToEra`.
    The matching pre-Conway golden tests have been removed.
  type:
   - breaking
   - refactoring
  projects:
   - cardano-cli

Context

Continuing the experimental-API migration. The friendly renderer was
the last consumer of the old-API TxBodyContent constructor in
cardano-cli — it pattern-matched on the result of getTxBodyContent
to render each field.

After this change the renderer consumes the experimental API
exclusively:

  • friendlyTx / friendlyTxBody take Exp.Era era and accept
    Exp.SignedTx era / Exp.UnsignedTx (Exp.LedgerEra era).
  • Every internal helper (basePairs, friendlyTxOut,
    friendlyCertificate, friendlyAuxScripts, renderPurpose,
    friendlyReturnCollateral, friendlyLedgerValue,
    alonzoScriptWitnessPairs, …) is parameterised over Exp.Era era
    and uses Exp.obtainCommonConstraints to bring ledger constraints
    into scope.
  • Exp.LedgerEra era is used throughout in place of
    ShelleyLedgerEra era.
  • Dead pre-Conway pattern-match branches and now-unreachable helpers
    (renderShelleyCertificate, friendlyMirTarget, friendlyMirPot,
    the nativeOnly aux-script renderer) have been deleted.
  • The dispatch site in Debug/TransactionView/Run.hs converts the
    era witness via Exp.sbeToEra; pre-Conway txs surface as a
    DeprecatedEra error.

After this change, no use of the old-API TxBodyContent remains in
cardano-cli. The remaining Exp.TxBodyContent references in
EraBased/Transaction/Run.hs are the experimental variant and are
unaffected.

Depends on cardano-api 11.1.0.0 (IntersectMBO/cardano-api#1199), which
widened Exp.SignedTx / Exp.UnsignedTx to be parameterised over the
ledger era family. Exp.Era itself remains a two-constructor GADT
(ConwayEra, DijkstraEra).

Notable behaviour changes

  • Conway and Dijkstra only: transaction view and
    debug transaction-view now reject pre-Conway tx / tx-body files
    with a DeprecatedEra error. This is a regression relative to
    master, where the old API supported all Shelley-based eras —
    flagged as breaking.

How to trust this PR

  • cabal build cardano-cli -j4 is clean.
  • grep -rn 'ShelleyLedgerEra' cardano-cli/src/Cardano/CLI/Compatible/Json/Friendly.hs returns nothing.
  • View-related golden tests pass:
    cabal test cardano-cli-golden --test-options='-p "/view/"'
    
    Conway debug-view, conway proposal view, the "latest" view tests in
    TxView.hs, governance action/vote view tests, and help-command
    goldens all pass (22 tests).
  • grep TxBodyContent in cardano-cli now only returns
    Exp.TxBodyContent references (experimental):
    grep -rn '\bTxBodyContent\b' --include='*.hs' cardano-cli/
    

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • Existing tests still pass
  • Self-reviewed the diff

Comment thread cardano-cli/src/Cardano/CLI/Compatible/Json/Friendly.hs Fixed
@Jimbo4350 Jimbo4350 force-pushed the jordan/friendly-tx-experimental-api branch 3 times, most recently from 66edca3 to 50f5898 Compare May 8, 2026 14:48
@Jimbo4350 Jimbo4350 marked this pull request as ready for review May 8, 2026 14:48
@Jimbo4350 Jimbo4350 requested a review from newhoggy as a code owner May 8, 2026 14:48
Copilot AI review requested due to automatic review settings May 8, 2026 14:48
@Jimbo4350 Jimbo4350 changed the title Migrate friendly rendering to experimental API types Widen friendly rendering to all Shelley-based eras May 8, 2026
Copy link
Copy Markdown

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

This PR continues the experimental-API migration by switching the “friendly” transaction/tx-body renderer to accept Cardano.Api.Experimental transaction types and by rendering tx-body fields directly from the ledger TxBody via lenses, removing the last usage of the old-API TxBodyContent pattern in this module.

Changes:

  • Update friendlyTx / friendlyTxBody to consume Exp.SignedTx / Exp.UnsignedTx, and refactor the implementation to read ledger TxBody fields via lenses.
  • Update debug transaction view to wrap parsed transactions/tx-bodies into the experimental wrapper types before rendering.
  • Refresh golden outputs (notably removing the update proposal field and adding Alonzo YAML goldens).

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
cardano-cli/src/Cardano/CLI/Compatible/Json/Friendly.hs Refactors friendly rendering to ledger-lens-based extraction and experimental tx wrappers.
cardano-cli/src/Cardano/CLI/EraIndependent/Debug/TransactionView/Run.hs Adapts debug transaction view command to call the updated friendly renderer with Exp.*Tx wrappers.
cardano-cli/src/Cardano/CLI/Read.hs Wraps update proposal envelope reading in era constraints (likely required by updated API constraints).
cardano-cli/test/cardano-cli-golden/Test/Golden/Debug/TransactionView.hs Adds an Alonzo YAML golden test case.
cardano-cli/test/cardano-cli-golden/files/golden/alonzo/transaction-view.yaml New golden output for Alonzo YAML rendering.
cardano-cli/test/cardano-cli-golden/files/golden/alonzo/transaction-view.json Golden updated to match new friendly output (e.g., key set/ordering differences such as removed update proposal).
cardano-cli/test/cardano-cli-golden/files/golden/alonzo/transaction-view.out Golden updated to match new friendly output (removes update proposal).
cardano-cli/test/cardano-cli-golden/files/golden/babbage/transaction-view.yaml Golden updated (adds datums/redeemers/scripts; removes update proposal).
cardano-cli/test/cardano-cli-golden/files/golden/babbage/transaction-view.json Golden updated (adds datums/redeemers/scripts; removes update proposal).
cardano-cli/test/cardano-cli-golden/files/golden/conway/transaction-view.yaml Golden updated (removes update proposal).
cardano-cli/test/cardano-cli-golden/files/golden/conway/transaction-view.json Golden updated (removes update proposal).
cardano-cli/test/cardano-cli-golden/files/golden/conway/transaction-view-metadata-noschema.out Golden updated (removes update proposal).
cardano-cli/test/cardano-cli-golden/files/golden/conway/transaction-view-metadata-detailedschema.out Golden updated (removes update proposal).
cardano-cli/test/cardano-cli-golden/files/golden/conway/tx-proposal.out.json Golden updated (removes update proposal).
cardano-cli/test/cardano-cli-golden/files/golden/shelley/transaction-view.yaml Golden updated (removes update proposal).
cardano-cli/test/cardano-cli-golden/files/golden/shelley/transaction-view.json Golden updated (removes update proposal).
cardano-cli/test/cardano-cli-golden/files/golden/mary/transaction-view.yaml Golden updated (removes update proposal).
cardano-cli/test/cardano-cli-golden/files/golden/mary/transaction-view.json Golden updated (removes update proposal).
cardano-cli/test/cardano-cli-golden/files/golden/allegra/transaction-view.yaml Golden updated (removes update proposal).
cardano-cli/test/cardano-cli-golden/files/golden/allegra/transaction-view.json Golden updated (removes update proposal).
cardano-cli/cardano-cli.cabal Bumps cardano-api dependency constraint to ^>=11.1.
cabal.project Updates cardano-haskell-packages index-state for dependency resolution.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

import Cardano.CLI.Type.Common (FormatJson (..), FormatYaml (..))
import Cardano.CLI.Type.MonadWarning (MonadWarning, runWarningIO)
import Cardano.Crypto.Hash (hashToTextAsHex)
import Cardano.Ledger.Api.Tx qualified as L
Ledger.DijkstraRewarding (L.AsIxItem _ rp) -> labelPurpose "withdrawing reward from script address" rp
Ledger.DijkstraVoting (L.AsIxItem _ vp) -> labelPurpose "voting using script protected voter credentials" vp
Ledger.DijkstraProposing (L.AsIxItem _ pp) -> labelPurpose "submitting a proposal following proposal policy" pp
Ledger.DijkstraGuarding _ -> error "TODO Dijkstra"
renderRedeemerInfo sbe tx redeemerPurpose (redeemerData, exUnits) =
let inputNotFoundError =
Aeson.object
[ "error" .= Aeson.String (T.pack "Could not find corresponding input to redeemer")
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch — restored show redeemerPurpose in the error string in 775575a.

@Jimbo4350 Jimbo4350 force-pushed the jordan/friendly-tx-experimental-api branch from 50f5898 to 5f7c05d Compare May 8, 2026 15:23
Jimbo4350 and others added 2 commits May 8, 2026 11:28
Bump CHaP index-state to pick up cardano-api 11.1.0.0, which contains
the widening of Exp.SignedTx to all Shelley-based eras (PR #1199) used
by the friendly rendering work in this branch.
@Jimbo4350 Jimbo4350 force-pushed the jordan/friendly-tx-experimental-api branch from 5f7c05d to 9b2f722 Compare May 8, 2026 15:30
@Jimbo4350 Jimbo4350 requested a review from a team as a code owner May 8, 2026 15:30
@Jimbo4350 Jimbo4350 force-pushed the jordan/friendly-tx-experimental-api branch 7 times, most recently from 4ddb601 to d9ecd53 Compare May 8, 2026 19:23
Copy link
Copy Markdown
Contributor

@carbolymer carbolymer left a comment

Choose a reason for hiding this comment

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

I'm not a fan of explicit pattern matching on eons. It just adds more work in the future.

@Jimbo4350
Copy link
Copy Markdown
Contributor Author

I'm not a fan of explicit pattern matching on eons. It just adds more work in the future.

What do you propose instead?

@Jimbo4350
Copy link
Copy Markdown
Contributor Author

I'm not a fan of explicit pattern matching on eons. It just adds more work in the future.

What do you propose instead?

Resolved to use Era era instead as QA actually does not use the view command on pre-Mainnet eras.

Copy link
Copy Markdown
Contributor

@palas palas left a comment

Choose a reason for hiding this comment

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

Nice! And I cannot find any issues.

I was thinking maybe "lower bound" should be omitted for consistency in Shelley, but I am not even sure that is a good idea...

@carbolymer
Copy link
Copy Markdown
Contributor

carbolymer commented May 12, 2026

I'm not a fan of explicit pattern matching on eons. It just adds more work in the future.

What do you propose instead?

I've tried to generalise the solution of eons so we wouldn't have so much boilerplate, but unfortunately it gets even more complicated. We can't work on era ranges and single ledger constraints because we can't easily prove for example if era - 1 and era + 1 eras have AlonzoEraTx constraint, then era would have it too.

So I suppose in the cases where we can't use experimental code, we could leave eons, but bury them in Compatible or Deprecated module.

Resolved to use Era era instead as QA actually does not use the view command on pre-Mainnet eras.

That would be fine. 👍🏻 But I don't see it in the diff yet.

@Jimbo4350 Jimbo4350 force-pushed the jordan/friendly-tx-experimental-api branch 3 times, most recently from 67cf048 to 87607ba Compare May 12, 2026 14:07
@Jimbo4350 Jimbo4350 changed the title Widen friendly rendering to all Shelley-based eras Migrate friendly transaction renderer to experimental API (Exp.Era era) May 12, 2026
@Jimbo4350 Jimbo4350 force-pushed the jordan/friendly-tx-experimental-api branch from 87607ba to 90233a4 Compare May 12, 2026 14:27
Migrates Cardano.CLI.Compatible.Json.Friendly off the old-API
Tx / TxBody / TxBodyContent onto Exp.SignedTx / Exp.UnsignedTx, with
the public renderer functions (friendlyTx, friendlyTxBody,
friendlyTxImpl, friendlyTxBodyImpl) now taking Exp.Era era instead of
ShelleyBasedEra era. This is the last consumer of old-API
TxBodyContent in cardano-cli.

Behaviour change: 'cardano-cli debug transaction view' and
'cardano-cli transaction view' now only accept Conway and Dijkstra
tx / tx-body files. Pre-Conway files (Shelley, Allegra, Mary, Alonzo,
Babbage) fail with a DeprecatedEra error. The corresponding pre-Conway
golden tests have been removed.
@Jimbo4350 Jimbo4350 force-pushed the jordan/friendly-tx-experimental-api branch from 90233a4 to 775575a Compare May 12, 2026 14:29
@Jimbo4350 Jimbo4350 enabled auto-merge May 12, 2026 14:41
@Jimbo4350 Jimbo4350 added this pull request to the merge queue May 12, 2026
Merged via the queue into master with commit a0e80f9 May 12, 2026
25 checks passed
@Jimbo4350 Jimbo4350 deleted the jordan/friendly-tx-experimental-api branch May 12, 2026 17:41
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.

5 participants