Migrate friendly transaction renderer to experimental API (Exp.Era era)#1374
Conversation
66edca3 to
50f5898
Compare
There was a problem hiding this comment.
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/friendlyTxBodyto consumeExp.SignedTx/Exp.UnsignedTx, and refactor the implementation to read ledgerTxBodyfields via lenses. - Update
debug transaction viewto wrap parsed transactions/tx-bodies into the experimental wrapper types before rendering. - Refresh golden outputs (notably removing the
update proposalfield 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") |
There was a problem hiding this comment.
Good catch — restored show redeemerPurpose in the error string in 775575a.
50f5898 to
5f7c05d
Compare
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.
5f7c05d to
9b2f722
Compare
4ddb601 to
d9ecd53
Compare
What do you propose instead? |
Resolved to use |
palas
left a comment
There was a problem hiding this comment.
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...
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 So I suppose in the cases where we can't use experimental code, we could leave eons, but bury them in
That would be fine. 👍🏻 But I don't see it in the diff yet. |
67cf048 to
87607ba
Compare
87607ba to
90233a4
Compare
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.
90233a4 to
775575a
Compare
Changelog
Context
Continuing the experimental-API migration. The friendly renderer was
the last consumer of the old-API
TxBodyContentconstructor incardano-cli — it pattern-matched on the result of
getTxBodyContentto render each field.
After this change the renderer consumes the experimental API
exclusively:
friendlyTx/friendlyTxBodytakeExp.Era eraand acceptExp.SignedTx era/Exp.UnsignedTx (Exp.LedgerEra era).basePairs,friendlyTxOut,friendlyCertificate,friendlyAuxScripts,renderPurpose,friendlyReturnCollateral,friendlyLedgerValue,alonzoScriptWitnessPairs, …) is parameterised overExp.Era eraand uses
Exp.obtainCommonConstraintsto bring ledger constraintsinto scope.
Exp.LedgerEra erais used throughout in place ofShelleyLedgerEra era.(
renderShelleyCertificate,friendlyMirTarget,friendlyMirPot,the
nativeOnlyaux-script renderer) have been deleted.Debug/TransactionView/Run.hsconverts theera witness via
Exp.sbeToEra; pre-Conway txs surface as aDeprecatedEraerror.After this change, no use of the old-API
TxBodyContentremains incardano-cli. The remaining
Exp.TxBodyContentreferences inEraBased/Transaction/Run.hsare the experimental variant and areunaffected.
Depends on cardano-api 11.1.0.0 (IntersectMBO/cardano-api#1199), which
widened
Exp.SignedTx/Exp.UnsignedTxto be parameterised over theledger era family.
Exp.Eraitself remains a two-constructor GADT(
ConwayEra,DijkstraEra).Notable behaviour changes
transaction viewanddebug transaction-viewnow reject pre-Conway tx / tx-body fileswith a
DeprecatedEraerror. This is a regression relative tomaster, where the old API supported all Shelley-based eras —flagged as
breaking.How to trust this PR
cabal build cardano-cli -j4is clean.grep -rn 'ShelleyLedgerEra' cardano-cli/src/Cardano/CLI/Compatible/Json/Friendly.hsreturns nothing.TxView.hs, governance action/vote view tests, and help-commandgoldens all pass (22 tests).
grep TxBodyContentin cardano-cli now only returnsExp.TxBodyContentreferences (experimental):Checklist