Skip to content

Migrate to experimental TxOut in createCompatibleTx#1376

Closed
Jimbo4350 wants to merge 2 commits into
masterfrom
jordan/migrate-cli-to-no-legacy-txout
Closed

Migrate to experimental TxOut in createCompatibleTx#1376
Jimbo4350 wants to merge 2 commits into
masterfrom
jordan/migrate-cli-to-no-legacy-txout

Conversation

@Jimbo4350
Copy link
Copy Markdown
Contributor

Changelog

- description: |
    Migrate `createCompatibleTx`, `toTxOutInEra`, and `toTxOutInShelleyBasedEra`
    to the experimental `TxOut` plus supplemental-datum map introduced by
    cardano-api PR #1209. Drop `TxCmdDatumDecodingError` (the underlying
    `Exp.DatumDecodingError` is deleted upstream).
  type:
   - maintenance

Context

Depends on cardano-api #1209Remove legacy TxOut from Compatible and Experimental APIs.

That PR makes two breaking changes in the cardano-api experimental namespace:

  1. createCompatibleTx now takes [Exp.TxOut (ShelleyLedgerEra era)] plus a new Map L.DataHash (L.Data ...) of supplemental datum bodies. The legacy TxOut CtxTx era bundled supplemental datums inside outputs; Exp.TxOut only carries the datum hash, so callers thread the full datum bodies in explicitly.
  2. The bridge helpers fromLegacyTxOut, legacyDatumToDatum, supplementalDatumFromLegacy, toLedgerDatum, and the DatumDecodingError type are removed from Cardano.Api.Experimental.Tx.

This PR adapts cardano-cli's three affected call sites and removes the now-unreachable error constructor.

How the migration works

A new helper convertLegacyTxOut :: ShelleyBasedEra era -> TxOut CtxTx era -> (Exp.TxOut (ShelleyLedgerEra era), Map DataHash (L.Data ...)) lives in Cardano.CLI.Compatible.Transaction.TxOut. It builds on the existing toShelleyTxOutAny (which already strips supplemental datums to their hash in the ledger TxOut) and pulls the supplemental datum bodies into the map. Total conversion — no error case, so the previous Either DatumDecodingError ... plumbing is gone.

Call sites:

  • Cardano.CLI.Compatible.Transaction.Run: converts outs at the boundary and folds supplemental datums via Map.unions before calling createCompatibleTx.
  • Cardano.CLI.EraBased.Transaction.Run: toTxOutInEra and toTxOutInShelleyBasedEra use convertLegacyTxOut instead of the deleted Exp.fromLegacyTxOut. obtainCommonConstraints bridges ShelleyLedgerEra ~ LedgerEra for the experimental-era return type.

Temporary cabal.project additions

To let CI validate against the unpublished API:

The PR branch is several commits ahead of cardano-api-11.1.0.0 and surfaces unrelated TxBody/TxBodyContent deprecations (cardano-api #1200) plus a redundant Cardano.Ledger.Core import in Cardano.CLI.Read that became visible after upstream re-exports widened. Both are separate cardano-cli cleanups; this PR keeps them out of scope by downgrading the warnings. All four lines should be removed in a follow-up once #1209 is merged and the next cardano-api is published to CHaP.

How to trust this PR

  • The migration is mechanical: one new helper, three replaced call sites, one removed error constructor.
  • convertLegacyTxOut reuses toShelleyTxOutAny rather than re-implementing the datum-to-ledger mapping, so semantics on the Exp.TxOut side are identical to what cardano-api itself does for non-experimental tx body construction.
  • Supplemental datums are still threaded into the witness set: the helper returns them in the map, and the new createCompatibleTx argument is passed through to convScriptData' inside cardano-api.
  • Build is clean (lib + exe + both test suites) against the SRP'd cardano-api branch with -Werror still in effect for everything except the two pre-existing classes of warnings above.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated. See Running tests for more details — no tests added; behavior on the cardano-cli surface is unchanged
  • Self-reviewed the diff

Comment thread cardano-cli/src/Cardano/CLI/Compatible/Transaction/TxOut.hs Fixed
pure $ TxOut addr val datum refScript
let legacyTxOut = TxOut addr val datum refScript
pure $
shelleyBasedEraConstraints sbe $
Jimbo4350 added 2 commits May 14, 2026 17:14
Adapt to cardano-api PR #1209, which removes the legacy 'TxOut CtxTx era'
from the Compatible and Experimental APIs:

  * 'createCompatibleTx' now takes '[Exp.TxOut (ShelleyLedgerEra era)]'
    plus a new 'Map L.DataHash (L.Data ...)' argument carrying any
    supplemental datum bodies. The legacy 'TxOut CtxTx era' bundled
    supplemental datums inside outputs; 'Exp.TxOut' only carries the
    datum hash, so callers thread the full datum bodies in explicitly.
  * The bridge helpers 'fromLegacyTxOut', 'legacyDatumToDatum',
    'supplementalDatumFromLegacy', 'toLedgerDatum', and the
    'DatumDecodingError' type are deleted from 'Cardano.Api.Experimental.Tx'.

Migration:

  * 'mkTxOut' and 'toTxOutInAnyEra' now return
    '(Exp.TxOut (ShelleyLedgerEra era), Map DataHash (L.Data ...))'
    directly, building the legacy 'TxOut CtxTx era' internally only as
    a stepping stone for 'toShelleyTxOutAny'.
  * 'createCompatibleTx' call site in 'Compatible/Transaction/Run.hs'
    folds the per-output supplemental datums via 'Map.unions' and
    passes them as the new argument.
  * 'toTxOutInEra' and 'toTxOutInShelleyBasedEra' in
    'EraBased/Transaction/Run.hs' delegate directly to 'mkTxOut' (the
    deleted 'fromLegacyTxOut' is gone).
  * 'TxCmdDatumDecodingError' is removed since the underlying
    'Exp.DatumDecodingError' is gone and the new conversion is total.

Temporary 'cabal.project' additions (to be removed once #1209 is
merged and the next cardano-api is published to CHaP):

  * 'source-repository-package' pointing at the PR branch so CI can
    build against the unpublished API.
  * Per-package '-Wwarn=deprecations -Wwarn=unused-imports' for
    cardano-cli. The PR branch is several commits ahead of
    cardano-api-11.1.0.0 and surfaces unrelated TxBody/TxBodyContent
    deprecations (cardano-api PR #1200) plus a redundant
    'Cardano.Ledger.Core' import in 'Cardano.CLI.Read' that became
    visible after upstream re-exports widened. Both are separate
    cleanups out of scope for this PR.
Eliminate the legacy 'TxOut CtxTx era' and 'TxOut CtxUTxO era' type
signatures and pattern matches from cardano-cli's non-Byron code paths.
Byron-era code uses a separate pre-Shelley tx output model and is left
alone — 'Exp.TxOut' is not applicable there.

  * 'friendlyTxOut' in 'Compatible/Json/Friendly.hs' now takes
    'Exp.TxOut (LedgerEra era)' and reads address, value, datum, and
    reference script directly via the ledger lenses ('addrTxOutL',
    'valueTxOutL', 'datumTxOutL', 'referenceScriptTxOutL'). The two
    call sites ('basePairs', 'friendlyReturnCollateral') wrap the
    body's ledger outputs with 'Exp.TxOut' instead of going through
    'fromShelleyTxOut → fromCtxUTxOTxOut'. The dead 'friendlyTxOutValue'
    helper is dropped.

  * 'filteredUTxOsToText' in 'EraBased/Query/Run.hs' now takes a
    'ShelleyBasedEra era' witness, converts the api 'UTxO era' to the
    ledger UTxO once via 'toLedgerUTxO', then renders each entry from
    '(TxIn, Exp.TxOut (ShelleyLedgerEra era))' using ledger lenses.
    The pre-Babbage datum slot has no uniform ledger representation,
    so the renderer emits an empty placeholder there and shows the
    babbage+ ledger datum elsewhere — debug-style output, no golden
    tests touched.

  * Removed 'validateTxReturnCollateral' from
    'Type/Error/TxValidationError.hs'. It was exported but never
    called outside its own module; the actual return-collateral
    construction in 'EraBased/Transaction/Run' builds
    'Exp.TxReturnCollateral' directly.

Remaining uses of legacy ctx-typed tx outputs in cardano-cli are
confined to Byron-only modules.
@Jimbo4350
Copy link
Copy Markdown
Contributor Author

Superseded by #1379, which folds in this PR's work (cardano-api #1209 companion — migration of createCompatibleTx, toTxOutInEra, and toTxOutInShelleyBasedEra to the experimental TxOut plus supplemental datum map) along with the cardano-api #1200 TxBody deprecation migration (was #1375) and the cardano-api #1210 Certificate API migration. All three now consume the published cardano-api 11.2.0.0 from CHaP rather than a source-repository-package pin. Closing in favour of #1379.

@Jimbo4350 Jimbo4350 closed this May 19, 2026
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