Skip to content

Remove legacy TxOut from Compatible and Experimental APIs#1209

Merged
Jimbo4350 merged 2 commits into
masterfrom
jordan/remove-legacy-txout-from-compat-and-experimental
May 15, 2026
Merged

Remove legacy TxOut from Compatible and Experimental APIs#1209
Jimbo4350 merged 2 commits into
masterfrom
jordan/remove-legacy-txout-from-compat-and-experimental

Conversation

@Jimbo4350
Copy link
Copy Markdown
Contributor

Changelog

- description: |
    Remove legacy `TxOut ctx era` from the Compatible and Experimental APIs.

    `createCompatibleTx` now takes `[Exp.TxOut (ShelleyLedgerEra era)]`
    plus an explicit `Map L.DataHash (L.Data ...)` for supplemental
    datums, mirroring how it already takes `Exp.TxCertificates` /
    `Exp.TxVotingProcedures` / `Exp.TxProposalProcedures`.

    Deletes legacy bridge helpers from `Cardano.Api.Experimental.Tx`:
    `fromLegacyTxOut`, `legacyDatumToDatum`, `supplementalDatumFromLegacy`,
    `toLedgerDatum`, `DatumDecodingError`. They were re-exported only
    via the experimental namespace, whose stability contract permits
    breaking changes.

    The legacy `TxOut ctx era` type itself is **unchanged** — `UTxO`,
    `Tx` body construction, fee/balancing, `LedgerState`, and Byron all
    still depend on it.
  type:
   - breaking
  projects:
   - cardano-api

Context

data TxOut ctx era (from Cardano.Api.Tx.Internal.Output) is still load-bearing across Cardano.Api.UTxO, Cardano.Api.Tx.Internal.Body, fee/balancing helpers, LedgerState, and Byron — roughly 230 references in cardano-api/src after filtering — so deprecating it wholesale is not currently practical. The entire UTxO era = Map TxIn (TxOut CtxUTxO era) abstraction depends on it.

The Experimental API has already introduced its own GADT wrapper at Cardano.Api.Experimental.Tx.Internal.BodyContent.New:

data TxOut era where
  TxOut :: L.EraTxOut era => L.TxOut era -> TxOut era

— a thin wrapper over the ledger's L.TxOut. The Experimental code was internally consistent and only referenced legacy TxOut in a handful of migration bridge helpers. The Compatible API (Cardano.Api.Compatible.Tx) still threaded [TxOut CtxTx era] through createCompatibleTx, createCommonTxBody, and convScriptData'.

This PR removes legacy TxOut from both Compatible and Experimental:

  1. createCompatibleTx now takes [Exp.TxOut (ShelleyLedgerEra era)] + Map L.DataHash (L.Data (ShelleyLedgerEra era)) for supplemental datums. The legacy TxOut CtxTx era bundled supplemental datums inside outputs, which convScriptData' extracted via [d | TxOut _ _ (TxOutSupplementalDatum _ d) _ <- txOuts'] and folded into TxBodyScriptData. Exp.TxOut intentionally does not carry supplemental datums (only the datum hash; the full datum lives in the witness set), so callers now thread them in explicitly — matching how ledger TxDats actually work.

  2. Deletes the legacy bridge helpers from Cardano.Api.Experimental.Tx:

    • fromLegacyTxOut
    • legacyDatumToDatum
    • supplementalDatumFromLegacy
    • toLedgerDatum
    • DatumDecodingError

    These existed solely to convert legacy TxOut CtxTx era / TxOutDatum CtxTx era values into the new world. With the Compatible API no longer accepting the legacy type, no in-repo caller remains. They were re-exported only via Cardano.Api.Experimental.Tx — they are not part of top-level Cardano.Api, and the experimental namespace explicitly permits breaking changes.

After this PR, neither Cardano.Api.Compatible.* nor Cardano.Api.Experimental.* references OldApi.TxOut / TxOut CtxTx era.

How to trust this PR

# Clean build under -Werror across all packages
cabal build all -j4

# Targeted property test for createCompatibleTx
cabal test cardano-api-test --test-options="-p createCompatibleTx"

# Audit: zero legacy TxOut references in Compatible/Experimental sources
rg 'OldApi\.TxOut|TxOut CtxTx|TxOut ctx era' \
   cardano-api/src/Cardano/Api/Compatible \
   cardano-api/src/Cardano/Api/Experimental
# (The only hit should be a haddock comment in Compatible/Tx.hs
#  documenting the migration — intentional.)

Checklist

  • Commits are well-sequenced and each commit message is informative
  • New code is covered by existing tests (the prop_createCompatibleTx_preserves_all_certs Hedgehog property still passes 100 cases)
  • Self-reviewed the diff
  • Code formatted with fourmolu
  • Builds clean under -Werror

Jimbo4350 added a commit that referenced this pull request May 14, 2026
@Jimbo4350 Jimbo4350 marked this pull request as ready for review May 14, 2026 19:41
Copilot AI review requested due to automatic review settings May 14, 2026 19:41
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

Removes the legacy TxOut ctx era surface from the Compatible and Experimental exposed APIs, shifting createCompatibleTx to consume the experimental ledger-TxOut wrapper plus an explicit supplemental-datums map, and deleting now-obsolete legacy conversion helpers from the experimental namespace.

Changes:

  • Updated Cardano.Api.Compatible.Tx.createCompatibleTx to accept [Exp.TxOut (ShelleyLedgerEra era)] and an explicit Map L.DataHash (L.Data (ShelleyLedgerEra era)) for supplemental datums (instead of extracting them from legacy outputs).
  • Removed legacy TxOut/datum bridge helpers from Cardano.Api.Experimental.Tx and Cardano.Api.Experimental.Tx.Internal.BodyContent.New.
  • Adjusted the property test to pass mempty for the new supplemental-datums parameter, and added a Herald changelog fragment classifying this as breaking.

Reviewed changes

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

Show a summary per file
File Description
cardano-api/test/cardano-api-test/Test/Cardano/Api/Experimental/Fee.hs Updates createCompatibleTx test call site for the new supplemental-datums argument.
cardano-api/src/Cardano/Api/Experimental/Tx/Internal/BodyContent/New.hs Removes legacy TxOut/datum conversion helpers and related exports/imports.
cardano-api/src/Cardano/Api/Experimental/Tx.hs Stops re-exporting the removed legacy conversion helpers from the exposed Experimental API.
cardano-api/src/Cardano/Api/Compatible/Tx.hs Changes createCompatibleTx/createCommonTxBody to use experimental TxOut and threads supplemental datums explicitly into script data.
.changes/20260514_cardano_api_remove_legacy_txout_from_compat_and_experimental.yml Adds a breaking-change changelog fragment describing the API removals/signature change.

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.

It all looks good, and I can see you already have IntersectMBO/cardano-cli#1376 ready to adapt to the changes and it also compiles

@Jimbo4350 Jimbo4350 enabled auto-merge May 15, 2026 00:42
Jimbo4350 added 2 commits May 15, 2026 07:59
createCompatibleTx now takes [Exp.TxOut (ShelleyLedgerEra era)] plus an
explicit Map L.DataHash (L.Data ...) for supplemental datums, mirroring
how it already takes Exp.TxCertificates / Exp.TxVotingProcedures /
Exp.TxProposalProcedures. Supplemental datums were previously rescued
out of the legacy TxOut constructor inside convScriptData' and folded
into TxBodyScriptData; Exp.TxOut intentionally does not carry them
(only the hash; the full datum lives in the witness set), so callers
now thread them in explicitly.

Deletes the legacy bridge helpers from Experimental.Tx
(fromLegacyTxOut, legacyDatumToDatum, supplementalDatumFromLegacy,
toLedgerDatum, DatumDecodingError). They existed only to migrate
callers from legacy TxOut CtxTx era; with the Compatible API no longer
accepting that type, the bridges have no remaining callers inside
cardano-api. They were re-exported only via the experimental namespace,
whose stability contract permits breaking changes.

After this change, neither Cardano.Api.Compatible.* nor
Cardano.Api.Experimental.* references OldApi.TxOut / TxOut CtxTx era.
The legacy TxOut ctx era type itself stays in place — UTxO, Tx body
construction, fee/balancing, LedgerState, and Byron all still depend
on it.
@Jimbo4350 Jimbo4350 force-pushed the jordan/remove-legacy-txout-from-compat-and-experimental branch from d18a07c to e90405b Compare May 15, 2026 11:59
@Jimbo4350 Jimbo4350 added this pull request to the merge queue May 15, 2026
Merged via the queue into master with commit f1cc7c8 May 15, 2026
31 checks passed
@Jimbo4350 Jimbo4350 deleted the jordan/remove-legacy-txout-from-compat-and-experimental branch May 15, 2026 12:25
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