Skip to content

Remove old-API TxBody uses from cardano-cli (companion to cardano-api #1200)#1375

Open
Jimbo4350 wants to merge 3 commits into
masterfrom
jordan/remove-old-api-txbody-uses
Open

Remove old-API TxBody uses from cardano-cli (companion to cardano-api #1200)#1375
Jimbo4350 wants to merge 3 commits into
masterfrom
jordan/remove-old-api-txbody-uses

Conversation

@Jimbo4350
Copy link
Copy Markdown
Contributor

@Jimbo4350 Jimbo4350 commented May 12, 2026

Summary

Companion to cardano-api #1200, which deprecates the old transaction-body API surface. This PR strips the remaining old-API uses from cardano-cli so -Werror stays clean once cardano-cli bumps to a cardano-api containing #1200.

PR #1374 already migrated the friendly-tx renderer; this PR handles the rest: Cardano.CLI.Read, Cardano.CLI.EraBased.Transaction.Run, Cardano.CLI.EraIndependent.Debug.TransactionView.Run, and the TxBodyFile phantom alias in Cardano.CLI.Type.Common.

Deprecated symbols replaced:

Old (deprecated by #1200) Replacement
TxBody era Exp.UnsignedTx (ShelleyLedgerEra era)
getTxBody pattern-match ShelleyTx _ ledgerTx
getTxBodyAndWitnesses getTxWitnesses + ledger body via lens
makeShelleyKeyWitness makeShelleyKeyWitness' (ledger body)
makeSignedTransaction addWitnesses
getTxId . getTxBody getTxIdShelley sbe (ledgerTx ^. L.bodyTxL)
evaluateTransactionExecutionUnits (on old TxBody) evaluateTransactionExecutionUnitsShelley (ledger Tx)
evaluateTransactionFee (on old TxBody) Exp.evaluateTransactionFee (on Exp.UnsignedTx)

Pre-Conway era support is preserved everywhere it currently works. The migration uses ledger-level signing (makeShelleyKeyWitness' / addWitnesses) rather than Exp.makeKeyWitness / Exp.signTx, which are Conway+ only. The TextEnvelope I/O boundary still uses Tx era / ShelleyTx _ (both non-deprecated); .tx/.txbody on-disk formats are unchanged.

The compatible command path (Cardano.CLI.Compatible.Transaction.Run) already used non-deprecated symbols and is unchanged.

Commits

Reviewable in order:

  1. cabal.project: temporarily pin cardano-api to PR #1200 — temporary source-repository-package stanza so CI builds against the deprecated surface. Drop this commit before merging once cardano-api ships a release containing Experimental api propagation 2025-05-23 #1200.
  2. Drop deprecated TxBody from TxBodyFile phantom — tiny, isolated. File (TxBody ())File TxBodyTag (a new empty tag type). No on-disk format change.
  3. Migrate IncompleteTxBody and transaction commands to Exp.UnsignedTx — the substantive change. Reworks IncompleteTxBody from a newtype around InAnyShelleyBasedEra TxBody into a GADT carrying Exp.UnsignedTx (ShelleyLedgerEra era) with IsShelleyBasedEra evidence; readFileTxBody destructures ShelleyTx _ ledgerTx directly. Updates transaction sign / sign-witness / witness / txid / submit / calculate-min-fee / calculate-plutus-script-cost and debug transaction view.

How to trust this PR

  • cabal build cardano-cli -j4 clean against the pinned cardano-api — zero -Wdeprecations, zero warnings.
  • cabal test cardano-cli-test -j4 — 69 / 69 pass.
  • cabal test cardano-cli-golden -j4 — 686 / 686 pass.
  • No on-disk format changes; existing .tx/.txbody files continue to round-trip via HasTextEnvelope (Tx era).

Changelog

- description: |
    Migrate cardano-cli off the deprecated old-API transaction-body
    surface (`TxBody`, `TxBodyContent`, `getTxBody`, `getTxBodyContent`,
    `createTransactionBody`, `defaultTxBodyContent`, `BalancedTxBody`)
    in favour of the experimental API (`Exp.UnsignedTx`,
    `Exp.evaluateTransactionFee`) and the existing ledger-level
    `makeShelleyKeyWitness'` / `addWitnesses` pair. Pre-Conway era
    support and on-disk `.tx`/`.txbody` formats are preserved.
  type:
    - refactoring

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated (existing golden + unit suites cover all affected commands; no behaviour change)
  • Self-reviewed the diff

Jimbo4350 added 3 commits May 12, 2026 14:44
Pins cardano-api to the master commit containing PR #1200, which
deprecates `TxBody`, `TxBodyContent`, `getTxBody`, `getTxBodyContent`,
`createTransactionBody`, `defaultTxBodyContent`, and `BalancedTxBody`.

Lets this PR verify -Wdeprecations is clean against the deprecated
surface. Remove this stanza once cardano-api releases a version
containing #1200.
`TxBodyFile` was a `File (TxBody ())` whose phantom payload was only
ever used as a file-tag for option/parser plumbing; the bytes on disk
do not depend on it. Replace `TxBody ()` with a fresh empty
`TxBodyTag` data type so the alias no longer references the deprecated
`TxBody` from cardano-api PR #1200.

No on-disk format change. No call-site change beyond the alias itself.
Drops the last remaining uses of the deprecated old-API transaction
body surface (`TxBody`, `getTxBody`, `getTxBodyAndWitnesses`,
`makeShelleyKeyWitness`, `makeSignedTransaction`,
`evaluateTransactionExecutionUnits` on a deprecated `TxBody`,
`getTxId . getTxBody`) from cardano-cli's source tree.

`IncompleteTxBody` is reworked from a `newtype` wrapping
`InAnyShelleyBasedEra TxBody` into a GADT existential carrying
`Exp.UnsignedTx (ShelleyLedgerEra era)` plus `IsShelleyBasedEra`
evidence. `readFileTxBody` pattern-matches `ShelleyTx _ ledgerTx`
directly and wraps as `Exp.UnsignedTx ledgerTx` — no `getTxBody`.

Consumers in `Transaction.Run` are migrated to:
- `makeShelleyKeyWitness'` (ledger-level body) and `addWitnesses` for
  signing — both non-deprecated and work for all Shelley-based eras,
  preserving pre-Conway support.
- `getTxIdShelley` for transaction IDs.
- `evaluateTransactionExecutionUnitsShelley` (operates on the ledger
  `Tx` directly) for `transaction calculate-plutus-script-cost`,
  preserving Alonzo+ era support.
- `Exp.evaluateTransactionFee` on `Exp.UnsignedTx` for
  `transaction calculate-min-fee` (already Conway+ via `sbeToEra`).

`TransactionView.Run` no longer needs the
`makeSignedTransaction []`-then-extract-ledger boundary that PR #1374
added — the new `readFileTxBody` returns `Exp.UnsignedTx` directly.

The TextEnvelope I/O boundary still uses `Tx era` and `ShelleyTx _`
(both non-deprecated), since `Exp.UnsignedTx`/`Exp.SignedTx` have no
`HasTextEnvelope` instance. The on-disk `.tx`/`.txbody` formats are
unchanged.

The compatible command path (`Cardano.CLI.Compatible.Transaction.Run`)
was already using non-deprecated symbols (`makeShelleyKeyWitness'`,
`addWitnesses`) and is unchanged by this commit.
Copilot AI review requested due to automatic review settings May 12, 2026 18:45
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

Migrates cardano-cli away from the deprecated legacy transaction-body API (TxBody, TxBodyContent, getTxBody, etc.) to keep builds clean under -Wdeprecations -Werror, aligning with the experimental API direction in cardano-api#1200.

Changes:

  • Replace TxBodyFile = File (TxBody ()) with a tag-based TxBodyFile = File TxBodyTag.
  • Rework readFileTxBody/IncompleteTxBody to carry an Exp.UnsignedTx (ledger tx) plus era evidence, and update transaction/debug commands to use ledger-level signing/witness attachment.
  • Temporarily pin cardano-api via source-repository-package in cabal.project to validate against the deprecated surface.

Reviewed changes

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

Show a summary per file
File Description
cardano-cli/src/Cardano/CLI/Type/Common.hs Switch TxBodyFile to a tag type to avoid deprecated TxBody in the phantom.
cardano-cli/src/Cardano/CLI/Read.hs Redefine IncompleteTxBody and update readFileTxBody to produce Exp.UnsignedTx with era evidence.
cardano-cli/src/Cardano/CLI/EraIndependent/Debug/TransactionView/Run.hs Update tx-body viewing path to consume IncompleteTxBody/Exp.UnsignedTx.
cardano-cli/src/Cardano/CLI/EraBased/Transaction/Run.hs Replace deprecated tx-body operations with ledger-level tx-body extraction, witness creation, and addWitnesses.
cabal.project Add a temporary cardano-api git pin to build against the deprecation changes.

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

deriving Show

type TxBodyFile = File (TxBody ())
data TxBodyTag
Comment thread cabal.project
Comment on lines +77 to +86
-- TEMPORARY: pin cardano-api to a master commit containing PR #1200
-- (deprecation of TxBody / TxBodyContent) so this PR can verify -Wdeprecations
-- is clean against the deprecated surface. Remove once cardano-api releases a
-- version containing PR #1200.
source-repository-package
type: git
location: https://github.com/IntersectMBO/cardano-api
tag: 1272b84342425dcbc653abe9b8eb11447a34ec01
subdir: cardano-api

-- Why are we differentiating between a transaction body and a transaction?
-- In the case of a transaction body, we /could/ simply call @makeSignedTransaction []@
-- In the case of a transaction body, we /could/ simply call @addWitnesses []@
-- to get a transaction which would allow us to reuse friendlyTxBS. However,
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.

2 participants