Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .changes/20260521_cardano_cli_bump_cardano_api_11_2_0_0.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
project: cardano-cli
pr: 1379
kind:
- maintenance
description: |
Bump to cardano-api 11.2.0.0. Folds in three migrations that previously
lived in separate PRs / unreleased branches:

- Companion to cardano-api #1200: drop deprecated TxBody / TxBodyContent
uses (was #1375).
- Companion to cardano-api #1209: migrate createCompatibleTx, toTxOutInEra,
and toTxOutInShelleyBasedEra to the experimental TxOut plus supplemental
datum map (was #1376).
- Companion to cardano-api #1210: legacy Cardano.Api.Certificate module is
gone; migrate all imports to Cardano.Api.Experimental.Certificate /
Cardano.Api.Compatible.Certificate as appropriate, and drop vacuous
hiding clauses that became -Wdodgy-imports errors under -Werror.
10 changes: 10 additions & 0 deletions .changes/20260521_cardano_cli_fix_inline_datum_tx_view.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
project: cardano-cli
pr: 1379
kind:
- bugfix
description: |
Fix `cardano-cli transaction view` rendering inline datums as a Haskell-`Show`
string instead of the structured JSON detailed-schema dict. The friendly tx
renderer's `L.Datum` branch in `friendlyTxOut` now routes through
`scriptDataToJson ScriptDataJsonDetailedSchema . fromAlonzoData`, restoring the
pre-#1374 output shape for inline-datum outputs.
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repository cardano-haskell-packages
-- you need to run if you change them
index-state:
, hackage.haskell.org 2026-04-16T00:15:23Z
, cardano-haskell-packages 2026-05-08T13:26:45Z
, cardano-haskell-packages 2026-05-18T18:23:40Z

active-repositories:
, :rest
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ library
binary,
bytestring,
canonical-json,
cardano-api ^>=11.1,
cardano-api ^>=11.2,
cardano-binary,
cardano-crypto,
cardano-crypto-class ^>=2.3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Cardano.CLI.Compatible.Governance.Command
where

import Cardano.Api
import Cardano.Api.Compatible.Certificate (MIRPot)

import Cardano.CLI.Compatible.Governance.Types
import Cardano.CLI.EraBased.Governance.Option
Expand Down
69 changes: 36 additions & 33 deletions cardano-cli/src/Cardano/CLI/Compatible/Json/Friendly.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ where
import Cardano.Api as Api
import Cardano.Api.Experimental (obtainCommonConstraints)
import Cardano.Api.Experimental qualified as Exp
import Cardano.Api.Experimental.Tx qualified as Exp
import Cardano.Api.Ledger (ExUnits (..), extractHash, strictMaybeToMaybe)
import Cardano.Api.Ledger qualified as Alonzo
import Cardano.Api.Ledger qualified as L
Expand Down Expand Up @@ -219,8 +220,7 @@ basePairs
-> [Aeson.Pair]
basePairs era body mAuxData =
Exp.obtainCommonConstraints era $
let sbe = convert era :: ShelleyBasedEra era
certs = toList (body ^. L.certsTxBodyL)
let certs = toList (body ^. L.certsTxBodyL)
in [ "auxiliary scripts" .= friendlyAuxScripts era mAuxData
, "certificates"
.= if null certs
Expand All @@ -232,7 +232,7 @@ basePairs era body mAuxData =
, "metadata" .= friendlyMetadata mAuxData
, "outputs"
.= map
(friendlyTxOut era . fromCtxUTxOTxOut . fromShelleyTxOut sbe)
(friendlyTxOut era . Exp.TxOut)
(toList (body ^. L.outputsTxBodyL))
, "withdrawals" .= friendlyWithdrawals (body ^. L.withdrawalsTxBodyL)
]
Expand Down Expand Up @@ -472,8 +472,7 @@ friendlyReturnCollateral era = \case
L.SNothing -> Aeson.Null
L.SJust collOut ->
Exp.obtainCommonConstraints era $
let sbe = convert era :: ShelleyBasedEra era
in friendlyTxOut era (fromCtxUTxOTxOut (fromShelleyTxOut sbe collOut))
friendlyTxOut era (Exp.TxOut collOut)

friendlyExtraKeyWits :: Set.Set (L.KeyHash L.Guard) -> Aeson.Value
friendlyExtraKeyWits keyhashes
Expand All @@ -499,35 +498,45 @@ friendlyStakeAddress (StakeAddress net cred) =
, friendlyStakeCredential cred
]

friendlyTxOut :: Exp.Era era -> TxOut CtxTx era -> Aeson.Value
friendlyTxOut era (TxOut addr amount mdatum script) =
friendlyTxOut
:: forall era
. Exp.Era era
-> Exp.TxOut (Exp.LedgerEra era)
-> Aeson.Value
friendlyTxOut era (Exp.TxOut ledgerTxOut) =
Exp.obtainCommonConstraints era $
object $
case addr of
AddressInEra ByronAddressInAnyEra byronAdr ->
[ "address era" .= String "Byron"
, "address" .= serialiseAddress byronAdr
, "amount" .= friendlyTxOutValue era amount
]
AddressInEra (ShelleyAddressInEra _) saddr@(ShelleyAddress net cred stake) ->
let preAlonzo =
babbageEraOnwardsConstraints beo $
let addr = fromShelleyAddr sbe (ledgerTxOut ^. L.addrTxOutL)
ledgerValue = ledgerTxOut ^. L.valueTxOutL
refScript = case ledgerTxOut ^. L.referenceScriptTxOutL of
L.SNothing -> ReferenceScriptNone
L.SJust s -> fromShelleyScriptToReferenceScript sbe s
in object $
case addr of
AddressInEra ByronAddressInAnyEra byronAdr ->
[ "address era" .= String "Byron"
, "address" .= serialiseAddress byronAdr
, "amount" .= friendlyLedgerValue era ledgerValue
]
AddressInEra (ShelleyAddressInEra _) saddr@(ShelleyAddress net cred stake) ->
friendlyPaymentCredential (fromShelleyPaymentCredential cred)
: [ "address era" .= Aeson.String "Shelley"
, "network" .= net
, "address" .= serialiseAddress saddr
, "amount" .= friendlyTxOutValue era amount
, "stake reference" .= friendlyStakeReference (fromShelleyStakeReference stake)
, "amount" .= friendlyLedgerValue era ledgerValue
, "stake reference"
.= friendlyStakeReference (fromShelleyStakeReference stake)
, "datum" .= case ledgerTxOut ^. L.datumTxOutL of
L.NoDatum -> Aeson.Null
L.DatumHash h -> toJSON h
L.Datum bd ->
scriptDataToJson ScriptDataJsonDetailedSchema $
fromAlonzoData (L.binaryDataToData bd)
, "reference script" .= refScript
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
, "reference script" .= refScript
, "datum" .= case ledgerTxOut ^. L.datumTxOutL of
L.NoDatum -> Aeson.Null
L.DatumHash h -> toJSON h
L.Datum bd -> friendlyDatum (L.binaryDataToData bd)
, "reference script" .= refScript

It seems the datum here got removed. It seems originally it was only shown when present but, since this is Babbage onwards, I am guessing it is more consistent to show it as null if absent

]
datum = ["datum" .= d | d <- maybeToList $ renderDatum mdatum]
sinceAlonzo = ["reference script" .= script]
in preAlonzo ++ datum ++ sinceAlonzo
where
renderDatum :: TxOutDatum CtxTx era -> Maybe Aeson.Value
renderDatum = \case
TxOutDatumNone -> Nothing
TxOutDatumHash _ h -> Just $ toJSON h
TxOutSupplementalDatum _ sData -> Just $ scriptDataToJson ScriptDataJsonDetailedSchema sData
TxOutDatumInline _ sData -> Just $ scriptDataToJson ScriptDataJsonDetailedSchema sData
beo = convert era :: BabbageEraOnwards era
sbe = convert era :: ShelleyBasedEra era

friendlyStakeReference :: StakeAddressReference -> Aeson.Value
friendlyStakeReference = \case
Expand Down Expand Up @@ -690,12 +699,6 @@ friendlyPaymentCredential = \case
friendlyLovelace :: Lovelace -> Aeson.Value
friendlyLovelace value = String $ docToText (pretty value)

friendlyTxOutValue :: Exp.Era era -> TxOutValue era -> Aeson.Value
friendlyTxOutValue era = \case
TxOutValueByron lovelace -> friendlyLovelace lovelace
TxOutValueShelleyBased _ v ->
Exp.obtainCommonConstraints era $ friendlyLedgerValue era v

friendlyLedgerValue
:: ()
=> Exp.Era era
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Cardano.CLI.Compatible.StakeAddress.Run
)
where

import Cardano.Api hiding (makeStakeAddressRegistrationCertificate)
import Cardano.Api
import Cardano.Api.Compatible.Certificate
import Cardano.Api.Experimental qualified as Exp
import Cardano.Api.Ledger qualified as L
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module Cardano.CLI.Compatible.StakePool.Command
where

import Cardano.Api
import Cardano.Api.Experimental.Certificate (StakePoolMetadataReference, StakePoolRelay)

import Cardano.CLI.Type.Common
import Cardano.CLI.Type.Key
Expand Down
3 changes: 2 additions & 1 deletion cardano-cli/src/Cardano/CLI/Compatible/StakePool/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ module Cardano.CLI.Compatible.StakePool.Run
)
where

import Cardano.Api hiding (makeStakePoolRegistrationCertificate)
import Cardano.Api
import Cardano.Api.Compatible.Certificate
import Cardano.Api.Experimental qualified as Exp
import Cardano.Api.Experimental.Certificate (StakePoolParameters (..), toShelleyPoolParams)

import Cardano.CLI.Compatible.Exception
import Cardano.CLI.Compatible.StakePool.Command
Expand Down
6 changes: 4 additions & 2 deletions cardano-cli/src/Cardano/CLI/Compatible/Transaction/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import Cardano.CLI.Type.Common

import Control.Monad
import Data.Map.Ordered.Strict qualified as OMap
import Data.Map.Strict qualified as Map
import Lens.Micro

runCompatibleTransactionCmd
Expand All @@ -60,7 +61,8 @@ runCompatibleTransactionCmd
) = shelleyBasedEraConstraints sbe $ do
sks <- mapM (fromEitherIOCli . readWitnessSigningData) witnesses

allOuts <- mapM (toTxOutInAnyEra sbe) outs
(allOuts, extraDatumsMapList) <- mapAndUnzipM (toTxOutInAnyEra sbe) outs
let extraDatums = Map.unions extraDatumsMapList

certFilesAndMaybeScriptWits <-
readCertificateScriptWitnesses' sbe certificates
Expand Down Expand Up @@ -107,7 +109,7 @@ runCompatibleTransactionCmd

transaction@(ShelleyTx _ ledgerTx) <-
fromEitherCli $
createCompatibleTx sbe ins allOuts fee protocolUpdates votes txCerts
createCompatibleTx sbe ins allOuts extraDatums fee protocolUpdates votes txCerts

let txBody = ledgerTx ^. L.bodyTxL

Expand Down
36 changes: 33 additions & 3 deletions cardano-cli/src/Cardano/CLI/Compatible/Transaction/TxOut.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}

Expand All @@ -8,28 +10,44 @@
where

import Cardano.Api
import Cardano.Api.Experimental.Tx qualified as Exp
import Cardano.Api.Ledger qualified as L

import Cardano.CLI.Compatible.Exception
import Cardano.CLI.EraBased.Script.Read.Common
import Cardano.CLI.Orphan ()
import Cardano.CLI.Read
import Cardano.CLI.Type.Common
import Cardano.Ledger.Hashes (DataHash)
import Cardano.Ledger.Plutus.Data qualified as L

import Data.Map.Strict (Map)
import Data.Map.Strict qualified as Map

toTxOutInAnyEra
:: ShelleyBasedEra era
-> TxOutAnyEra
-> CIO e (TxOut CtxTx era)
-> CIO e (Exp.TxOut (ShelleyLedgerEra era), Map DataHash (L.Data (ShelleyLedgerEra era)))
toTxOutInAnyEra era (TxOutAnyEra addr' val' mDatumHash refScriptFp) = do
let addr = anyAddressInShelleyBasedEra era addr'
mkTxOut era addr val' mDatumHash refScriptFp

-- | Build an output for a transaction body. Produces the experimental
-- 'Exp.TxOut' plus any supplemental datum bodies that the caller-supplied
-- datum carries. 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 separately (e.g. via 'createCompatibleTx').
--
-- The legacy 'TxOut CtxTx era' is used internally as a stepping stone to
-- reuse the api's 'toShelleyTxOutAny' field-level conversion logic; it is
-- not exposed.
mkTxOut
:: ShelleyBasedEra era
-> AddressInEra era
-> Value
-> TxOutDatumAnyEra
-> ReferenceScriptAnyEra
-> CIO e (TxOut CtxTx era)
-> CIO e (Exp.TxOut (ShelleyLedgerEra era), Map DataHash (L.Data (ShelleyLedgerEra era)))
mkTxOut sbe addr val' mDatumHash refScriptFp = do
let era = toCardanoEra sbe
val <- toTxOutValueInShelleyBasedEra sbe val'
Expand All @@ -46,7 +64,19 @@
(`getReferenceScript` refScriptFp)
era

pure $ TxOut addr val datum refScript
let legacyTxOut = TxOut addr val datum refScript
pure $
shelleyBasedEraConstraints sbe $

Check notice

Code scanning / HLint

Redundant $ Note

cardano-cli/src/Cardano/CLI/Compatible/Transaction/TxOut.hs:69:36: Suggestion: Redundant $
  
Found:
  shelleyBasedEraConstraints sbe
    $ (Exp.TxOut (toShelleyTxOutAny sbe legacyTxOut), 
       supplementalsOf datum)
  
Perhaps:
  shelleyBasedEraConstraints
    sbe
    (Exp.TxOut (toShelleyTxOutAny sbe legacyTxOut), 
     supplementalsOf datum)
(Exp.TxOut (toShelleyTxOutAny sbe legacyTxOut), supplementalsOf datum)
where
supplementalsOf
:: L.Era (ShelleyLedgerEra era)
=> TxOutDatum CtxTx era
-> Map DataHash (L.Data (ShelleyLedgerEra era))
supplementalsOf (TxOutSupplementalDatum _ h) =
let ld = toAlonzoData h
in Map.singleton (L.hashData ld) ld
supplementalsOf _ = mempty

toTxOutValueInShelleyBasedEra
:: ShelleyBasedEra era
Expand Down
6 changes: 6 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Common/Option.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ module Cardano.CLI.EraBased.Common.Option where

import Cardano.Api
import Cardano.Api.Experimental as Exp
import Cardano.Api.Experimental.Certificate
( KESPeriod (..)
, StakePoolMetadata
, StakePoolMetadataReference (..)
, StakePoolRelay (..)
)
import Cardano.Api.Ledger qualified as L
import Cardano.Api.Network qualified as Consensus
import Cardano.Api.Parser.Text qualified as P
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ module Cardano.CLI.EraBased.Genesis.CreateTestnetData.Run
where

import Cardano.Api hiding (ConwayEra)
import Cardano.Api.Experimental.Certificate
( KESPeriod (..)
, OperationalCertificateIssueCounter (..)
)
import Cardano.Api.Ledger (StandardCrypto, StrictMaybe (SNothing))
import Cardano.Api.Ledger qualified as L

Expand Down
6 changes: 6 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Genesis/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ import Cardano.Api.Byron
, SigningKey (..)
)
import Cardano.Api.Byron qualified as Byron hiding (SigningKey)
import Cardano.Api.Experimental.Certificate
( KESPeriod (..)
, OperationalCertificate
, OperationalCertificateIssueCounter (..)
, issueOperationalCertificate
)
import Cardano.Api.Ledger qualified as L

import Cardano.CLI.Byron.Delegation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ module Cardano.CLI.EraBased.Governance.Committee.Run
)
where

import Cardano.Api hiding
( Certificate
, makeCommitteeColdkeyResignationCertificate
, makeCommitteeHotKeyAuthorizationCertificate
)
import Cardano.Api
import Cardano.Api.Experimental
( Certificate
, Era
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ where

import Cardano.Api
import Cardano.Api.Experimental qualified as Exp
import Cardano.Api.Experimental.Certificate (DRepMetadata)
import Cardano.Api.Ledger qualified as L

import Cardano.CLI.EraIndependent.Hash.Command (HashGoal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ where

import Cardano.Api
import Cardano.Api.Experimental qualified as Exp
import Cardano.Api.Experimental.Certificate (DRepMetadata, Hash (DRepMetadataHash))
import Cardano.Api.Ledger qualified as L

import Cardano.CLI.EraBased.Common.Option
Expand Down
8 changes: 2 additions & 6 deletions cardano-cli/src/Cardano/CLI/EraBased/Governance/DRep/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@ module Cardano.CLI.EraBased.Governance.DRep.Run
)
where

import Cardano.Api hiding
( Certificate
, makeDrepRegistrationCertificate
, makeDrepUnregistrationCertificate
, makeDrepUpdateCertificate
)
import Cardano.Api
import Cardano.Api.Experimental qualified as Exp
import Cardano.Api.Experimental.Certificate (DRepMetadata, hashDRepMetadata)
import Cardano.Api.Ledger qualified as L

import Cardano.CLI.Compatible.Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Cardano.CLI.EraBased.Governance.GenesisKeyDelegationCertificate.Run
)
where

import Cardano.Api hiding (makeGenesisKeyDelegationCertificate)
import Cardano.Api
import Cardano.Api.Compatible.Certificate

import Cardano.CLI.Compatible.Exception
Expand Down
Loading
Loading