Skip to content

Widen friendly rendering to all Shelley-based eras#1374

Open
Jimbo4350 wants to merge 5 commits intomasterfrom
jordan/friendly-tx-experimental-api
Open

Widen friendly rendering to all Shelley-based eras#1374
Jimbo4350 wants to merge 5 commits intomasterfrom
jordan/friendly-tx-experimental-api

Conversation

@Jimbo4350
Copy link
Copy Markdown
Contributor

@Jimbo4350 Jimbo4350 commented May 6, 2026

Changelog

- description: |
    `transaction view` and `debug transaction-view` now work on
    Shelley- through Conway-era tx and tx-body files. Previously the
    friendly renderer was Conway-only via the experimental API; this
    series migrates it to `Exp.SignedTx` / `Exp.UnsignedTx` and widens
    `friendlyTx` / `friendlyTxBody` to take `ShelleyBasedEra era`
    instead of `Exp.Era era`. Field presence is now era-accurate:
    fields the era doesn't have (e.g. `mint` in Shelley, `collateral
    inputs` in Mary, `update proposal` in Conway+) are omitted from
    the output rather than rendered as `null`. The `update proposal`
    field is read directly from the ledger `TxBody` for Shelley-Babbage.
  type:
   - feature
   - breaking
   - refactoring
  projects:
   - cardano-cli

Context

Continuing the experimental-API migration. The friendly renderer
(Cardano.CLI.Compatible.Json.Friendly) 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.

This series:

  1. Migrates, widens, and refactors the renderer in one cohesive
    step
    : friendlyTx / friendlyTxBody now take ShelleyBasedEra era and accept Exp.SignedTx / Exp.UnsignedTx. friendlyTxBodyImpl
    reads every field directly from the ledger TxBody via lenses and
    composes a list of pairs from per-feature helpers
    (validityRangePair, mintPairFor, collateralInputsPairFor, …).
    Era-gated helpers return [Aeson.Pair] and emit [] in eras that
    don't have the field, so JSON keys for absent-in-this-era fields
    are omitted from the output rather than rendered as null. Also
    adds an Alonzo YAML golden alongside the existing JSON one.
    Relies on cardano-api 11.1.0.0 (Widen Exp.SignedTx to all Shelley-based eras cardano-api#1199),
    which widened Exp.SignedTx / Exp.UnsignedTx to all
    Shelley-based eras.
  2. Renders the update proposal field for Shelley-Babbage eras —
    read directly from the ledger TxBody via updateTxBodyL. Each
    era's PParamsUpdate is rendered via its ledger ToJSON
    instance. Conway+ has no update field (replaced by the governance
    system), so the key is absent for those eras.

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.

Notable behaviour changes

  • All Shelley-based eras: transaction view and
    debug transaction-view now succeed on Shelley through Babbage tx
    and tx-body files.
  • Era-accurate field presence: keys for fields a given era
    doesn't have are absent from the JSON/YAML output (instead of
    appearing with null). For example: pre-Mary outputs no longer
    include mint; pre-Alonzo outputs no longer include collateral inputs, total collateral, return collateral, required signers, reference inputs; Conway+ outputs no longer include
    update proposal.
  • update proposal field semantics (where present):
    • Shelley-Babbage: rendered from the ledger TxBody's update
      field. null when the body has no update; otherwise an object
      with epoch and updates: [{genesis key hash, update}] where
      each update is the ledger-ToJSON rendering of PParamsUpdate.
    • Conway+: the key is omitted entirely.
  • auxiliary scripts field: now rendered from the ledger
    TxAuxData via friendlyAuxScripts. Shelley has no auxiliary
    scripts (always null); Allegra/Mary render native (timelock)
    scripts; Alonzo+ render native plus Plutus scripts. Empty script
    sets render as null.

How to trust this PR

  • All golden view / debug transaction view tests pass:
    cabal test cardano-cli-golden --test-options='-p "/transaction view/"'
    
  • 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")
@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 6 times, most recently from 430847c to 4ddb601 Compare May 8, 2026 19:14
Jimbo4350 added 3 commits May 8, 2026 15:22
…elley-based eras, and refactor with per-feature helpers

friendlyTx and friendlyTxBody now take ShelleyBasedEra era and accept
Exp.SignedTx era / Exp.UnsignedTx (ShelleyLedgerEra era). They are no
longer parameterised by Exp.Era era (which is Conway-only) — the
renderer works for Shelley through Conway tx and tx-body files,
unblocking transaction view for pre-Conway tx files.

friendlyTxBodyImpl reads every field directly from the ledger TxBody
via lenses, so the old API's TxBodyContent constructor and
getTxBodyContent are no longer used in this module.

The body composes a list of pairs from per-feature helpers
(validityRangePair, mintPairFor, collateralInputsPairFor,
requiredSignersPairFor, referenceInputsPairFor, totalCollateralPairFor,
returnCollateralPairFor, alonzoScriptWitnessPairsFor,
conwayBodyPairsFor). Era-gated helpers return [Aeson.Pair] and emit []
in eras that don't have the field, so JSON keys for absent-in-this-era
fields (e.g. "mint" in Shelley, "collateral inputs" in Mary) are
omitted from the output rather than rendered as null. The eon-based
dispatchers (forShelleyBasedEraInEon, AlonzoEraOnwards,
ConwayEraOnwards, ...) are no longer used in this module.

Also adds an Alonzo YAML golden test alongside the existing JSON
golden to cover the YAML output path for that era.

Relies on cardano-api 11.1.0.0 (PR IntersectMBO/cardano-api#1199),
which widened Exp.SignedTx / Exp.UnsignedTx to all Shelley-based eras.
Now that the friendly renderer covers Shelley through Babbage, those
tx bodies' update field is no longer just noise — it carries real
governance state (a ProposedPPUpdates map keyed by genesis-key hash and
an EpochNo). Render it directly from the ledger TxBody via
`updateTxBodyL`. Conway replaced update proposals with the new
governance system, so the field is absent (not null) in Conway+.

Adds `updateProposalPairFor` and `renderUpdate` helpers; the
per-era PParamsUpdate is rendered via its ledger ToJSON instance.
@Jimbo4350 Jimbo4350 force-pushed the jordan/friendly-tx-experimental-api branch from 4ddb601 to d9ecd53 Compare May 8, 2026 19:23
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.

4 participants