Skip to content

Commit f1cc7c8

Browse files
authored
Merge pull request #1209 from IntersectMBO/jordan/remove-legacy-txout-from-compat-and-experimental
Remove legacy TxOut from Compatible and Experimental APIs
2 parents 074ddaa + e90405b commit f1cc7c8

5 files changed

Lines changed: 39 additions & 97 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
project: cardano-api
2+
pr: 1209
3+
kind:
4+
- breaking
5+
description: |
6+
Remove legacy `TxOut ctx era` from the Compatible and Experimental APIs.
7+
8+
`createCompatibleTx` now takes `[Exp.TxOut (ShelleyLedgerEra era)]` plus an explicit `Map L.DataHash (L.Data (ShelleyLedgerEra era))` for supplemental datums, mirroring how it already takes `Exp.TxCertificates` / `Exp.TxVotingProcedures` / `Exp.TxProposalProcedures`. The legacy `TxOut CtxTx era` bundled supplemental datums inside outputs; `Exp.TxOut` only carries the datum hash (the full datum lives in the witness set), so callers now thread them in explicitly.
9+
10+
Deletes the legacy bridge helpers re-exported from `Cardano.Api.Experimental.Tx`:
11+
12+
- `fromLegacyTxOut`
13+
- `legacyDatumToDatum`
14+
- `supplementalDatumFromLegacy`
15+
- `toLedgerDatum`
16+
- `DatumDecodingError`
17+
18+
These existed solely to convert legacy `TxOut CtxTx era` / `TxOutDatum CtxTx era` values into the experimental world. With the Compatible API no longer accepting the legacy type, they had no remaining in-repo callers. They are not re-exported from top-level `Cardano.Api`.
19+
20+
The legacy `TxOut ctx era` type itself is unchanged — `UTxO`, `Tx` body construction, fee/balancing, `LedgerState`, and Byron all still depend on it.

cardano-api/src/Cardano/Api/Compatible/Tx.hs

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ import Cardano.Ledger.Alonzo.TxWits qualified as Alonzo
3737
import Cardano.Ledger.Api qualified as L
3838
import Cardano.Ledger.Core qualified as L
3939

40+
import Data.Map.Strict (Map)
4041
import Data.Map.Strict qualified as Map
4142
import Data.Maybe
4243
import Data.Maybe.Strict
4344
import Data.Monoid
4445
import Data.OSet.Strict (OSet)
4546
import Data.Sequence.Strict qualified as Seq
4647
import GHC.Exts (IsList (..))
47-
import GHC.Stack
4848
import Lens.Micro hiding (ix)
4949

5050
data AnyProtocolUpdate era where
@@ -72,14 +72,19 @@ createCompatibleTx
7272
:: forall era
7373
. ShelleyBasedEra era
7474
-> [TxIn]
75-
-> [TxOut CtxTx era]
75+
-> [Exp.TxOut (ShelleyLedgerEra era)]
76+
-> Map L.DataHash (L.Data (ShelleyLedgerEra era))
77+
-- ^ Supplemental datums to include in the witness set. Use 'mempty' if
78+
-- none are required. The legacy 'TxOut CtxTx era' bundled supplemental
79+
-- datums inside outputs; 'Exp.TxOut' only carries the datum hash, so
80+
-- callers thread the full datum bodies in here explicitly.
7681
-> Lovelace
7782
-- ^ Fee
7883
-> AnyProtocolUpdate era
7984
-> AnyVote era
8085
-> Exp.TxCertificates (ShelleyLedgerEra era)
8186
-> Either ProtocolParametersConversionError (Tx era)
82-
createCompatibleTx sbe ins outs txFee' anyProtocolUpdate anyVote txCertificates' =
87+
createCompatibleTx sbe ins outs extraDatums txFee' anyProtocolUpdate anyVote txCertificates' =
8388
shelleyBasedEraConstraints sbe $ do
8489
(updateTxBody, extraScriptWitnesses) <-
8590
case anyProtocolUpdate of
@@ -186,7 +191,7 @@ createCompatibleTx sbe ins outs txFee' anyProtocolUpdate anyVote txCertificates'
186191
[ monoidForEraInEon
187192
era
188193
( \aeo -> alonzoEraOnwardsConstraints aeo $ Endo $ do
189-
let sData = convScriptData' sbe outs scriptWitnesses
194+
let sData = convScriptData' sbe extraDatums scriptWitnesses
190195
let (datums, redeemers) = case sData of
191196
TxBodyScriptData _ ds rs -> (ds, rs)
192197
TxBodyNoScriptData -> (mempty, L.Redeemers mempty)
@@ -223,25 +228,16 @@ convCertificates (Exp.TxCertificates cs) =
223228

224229
convScriptData'
225230
:: ShelleyBasedEra era
226-
-> [TxOut CtxTx era]
231+
-> Map L.DataHash (L.Data (ShelleyLedgerEra era))
227232
-> [(ScriptWitnessIndex, AnyWitness (ShelleyLedgerEra era))]
228233
-> TxBodyScriptData era
229-
convScriptData' sbe txOuts' scriptWitnesses =
234+
convScriptData' sbe extraDatums scriptWitnesses =
230235
caseShelleyToMaryOrAlonzoEraOnwards
231236
(const TxBodyNoScriptData)
232237
( \w ->
233238
let redeemers = getAnyPlutusScriptWitnessRedeemerPointerMap w scriptWitnesses
234-
235239
datums = mconcat [getAnyWitnessScriptData wit | (_, wit) <- scriptWitnesses]
236-
237-
supplementalDatums =
238-
let ds = [d | TxOut _ _ (TxOutSupplementalDatum _ d) _ <- txOuts']
239-
in Alonzo.TxDats $
240-
fromList
241-
[ (L.hashData d', d')
242-
| d <- ds
243-
, let d' = toAlonzoData d
244-
]
240+
supplementalDatums = alonzoEraOnwardsConstraints w $ Alonzo.TxDats extraDatums
245241
in TxBodyScriptData w (datums <> supplementalDatums) redeemers
246242
)
247243
sbe
@@ -268,17 +264,16 @@ getAnyPlutusScriptWitnessRedeemerPointerMap w wits =
268264
]
269265

270266
createCommonTxBody
271-
:: HasCallStack
272-
=> ShelleyBasedEra era
267+
:: ShelleyBasedEra era
273268
-> [TxIn]
274-
-> [TxOut ctx era]
269+
-> [Exp.TxOut (ShelleyLedgerEra era)]
275270
-> Lovelace
276271
-> L.TxBody L.TopTx (ShelleyLedgerEra era)
277272
createCommonTxBody era ins outs txFee' =
278-
let txIns' = map toShelleyTxIn ins
279-
txOuts' = map (toShelleyTxOutAny era) outs
280-
in shelleyBasedEraConstraints era $
281-
L.mkBasicTxBody
273+
shelleyBasedEraConstraints era $
274+
let txIns' = map toShelleyTxIn ins
275+
txOuts' = map (\(Exp.TxOut o) -> o) outs
276+
in L.mkBasicTxBody
282277
& L.inputsTxBodyL
283278
.~ fromList txIns'
284279
& L.outputsTxBodyL

cardano-api/src/Cardano/Api/Experimental/Tx.hs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,6 @@ module Cardano.Api.Experimental.Tx
158158
, setTxVotingProcedures
159159
, setTxWithdrawals
160160

161-
-- * Legacy Conversions
162-
, DatumDecodingError (..)
163-
, legacyDatumToDatum
164-
, fromLegacyTxOut
165-
, supplementalDatumFromLegacy
166-
167161
-- * TxBodyContent sub type
168162
, TxCertificates (..)
169163
, TxMintValue (..)

cardano-api/src/Cardano/Api/Experimental/Tx/Internal/BodyContent/New.hs

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,6 @@ module Cardano.Api.Experimental.Tx.Internal.BodyContent.New
6969
, extractWitnessableWithdrawals
7070
, extractWitnessableVotes
7171
, extractWitnessableProposals
72-
73-
-- * Legacy conversions
74-
, DatumDecodingError (..)
75-
, legacyDatumToDatum
76-
, fromLegacyTxOut
77-
, supplementalDatumFromLegacy
7872
)
7973
where
8074

@@ -117,7 +111,6 @@ import Cardano.Api.Plutus.Internal.Script
117111
)
118112
import Cardano.Api.Plutus.Internal.Script qualified as OldScript
119113
import Cardano.Api.Plutus.Internal.ScriptData qualified as Api
120-
import Cardano.Api.Pretty
121114
import Cardano.Api.Serialise.Cbor (serialiseToCBOR)
122115
import Cardano.Api.Tx.Internal.Body
123116
( CtxTx
@@ -126,7 +119,6 @@ import Cardano.Api.Tx.Internal.Body
126119
, toShelleyTxIn
127120
, toShelleyWithdrawal
128121
)
129-
import Cardano.Api.Tx.Internal.Output qualified as OldApi
130122
import Cardano.Api.Tx.Internal.Sign
131123
import Cardano.Api.Tx.Internal.TxMetadata
132124
import Cardano.Api.Value.Internal
@@ -153,7 +145,6 @@ import Control.Monad
153145
import Data.Aeson (ToJSON (..), (.=))
154146
import Data.Aeson qualified as Aeson
155147
import Data.ByteString.Base16 qualified as Base16
156-
import Data.ByteString.Short qualified as SBS
157148
import Data.Functor
158149
import Data.List qualified as List
159150
import Data.Map.Ordered.Strict (OMap)
@@ -169,7 +160,6 @@ import Data.Set qualified as Set
169160
import Data.Text.Encoding qualified as Text
170161
import Data.Typeable (cast)
171162
import GHC.Exts (IsList (..))
172-
import GHC.Stack (HasCallStack)
173163
import Lens.Micro
174164

175165
-- | Error that can occur when constructing an unsigned transaction.
@@ -521,63 +511,6 @@ extractDatumsAndHashes TxOutDatumHash{} = Nothing
521511
extractDatumsAndHashes (TxOutSupplementalDatum h d) = Just (h, d)
522512
extractDatumsAndHashes (TxOutDatumInline h d) = Just (h, d)
523513

524-
hashableScriptDatumToDatumAndHash :: L.Era era => Api.HashableScriptData -> (L.DataHash, L.Data era)
525-
hashableScriptDatumToDatumAndHash sd =
526-
(Api.unScriptDataHash $ Api.hashScriptDataBytes sd, Api.toAlonzoData sd)
527-
528-
legacyDatumToDatum
529-
:: forall era. IsEra era => OldApi.TxOutDatum CtxTx era -> Maybe (Datum CtxTx (LedgerEra era))
530-
legacyDatumToDatum (OldApi.TxOutDatumHash _ h) = Just (TxOutDatumHash $ Api.unScriptDataHash h)
531-
legacyDatumToDatum (OldApi.TxOutSupplementalDatum _ hd) = do
532-
let (hash, d) = obtainCommonConstraints (useEra @era) $ hashableScriptDatumToDatumAndHash hd
533-
Just (TxOutSupplementalDatum hash d)
534-
legacyDatumToDatum (OldApi.TxOutDatumInline _ hd) = do
535-
let (hash, d) = obtainCommonConstraints (useEra @era) $ hashableScriptDatumToDatumAndHash hd
536-
Just (TxOutDatumInline hash d)
537-
legacyDatumToDatum OldApi.TxOutDatumNone = Nothing
538-
539-
fromLegacyTxOut
540-
:: forall era
541-
. HasCallStack
542-
=> IsEra era
543-
=> OldApi.TxOut CtxTx era
544-
-> Either DatumDecodingError (TxOut (LedgerEra era), Map L.DataHash (L.Data (LedgerEra era)))
545-
fromLegacyTxOut tOut@(OldApi.TxOut _ _ d _) = do
546-
let o = OldApi.toShelleyTxOutAny (convert $ useEra @era) tOut
547-
newDatum :: L.Datum (LedgerEra era) <- obtainCommonConstraints (useEra @era) $ toLedgerDatum d
548-
let txOut = obtainCommonConstraints (useEra @era) $ TxOut $ o & L.datumTxOutL .~ newDatum
549-
suppDats = obtainCommonConstraints (useEra @era) $ supplementalDatumFromLegacy d
550-
return (txOut, suppDats)
551-
552-
-- | Extract supplemental datum data from a legacy 'TxOutDatum'.
553-
-- Returns 'mempty' for non-supplemental datums.
554-
supplementalDatumFromLegacy
555-
:: L.Era (LedgerEra era)
556-
=> OldApi.TxOutDatum CtxTx era
557-
-> Map L.DataHash (L.Data (LedgerEra era))
558-
supplementalDatumFromLegacy (OldApi.TxOutSupplementalDatum _ h) =
559-
let ledgerData = Api.toAlonzoData h
560-
in fromList [(L.hashData ledgerData, ledgerData)]
561-
supplementalDatumFromLegacy _ = mempty
562-
563-
newtype DatumDecodingError = DatumDecodingError String
564-
deriving (Show, Eq)
565-
566-
instance Error DatumDecodingError where
567-
prettyError (DatumDecodingError msg) = "Datum decoding error: " <> pshow msg
568-
569-
toLedgerDatum
570-
:: L.Era (LedgerEra era)
571-
=> OldApi.TxOutDatum CtxTx era -> Either DatumDecodingError (L.Datum (LedgerEra era))
572-
toLedgerDatum OldApi.TxOutDatumNone = Right L.NoDatum
573-
toLedgerDatum (OldApi.TxOutDatumHash _ (Api.ScriptDataHash h)) = Right $ L.DatumHash h
574-
toLedgerDatum (OldApi.TxOutSupplementalDatum _ h) =
575-
Right $ L.DatumHash (Api.unScriptDataHash $ Api.hashScriptDataBytes h)
576-
toLedgerDatum (OldApi.TxOutDatumInline _ h) =
577-
case L.makeBinaryData $ SBS.toShort $ Api.getOriginalScriptDataBytes h of
578-
Left e -> Left $ DatumDecodingError e
579-
Right bd -> Right $ L.Datum bd
580-
581514
data TxInsReference era = TxInsReference [TxIn] (Set (Datum CtxTx era))
582515

583516
newtype TxTotalCollateral = TxTotalCollateral {unTxTotalCollateral :: L.Coin}

cardano-api/test/cardano-api-test/Test/Cardano/Api/Experimental/Fee.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ prop_createCompatibleTx_preserves_all_certs = H.property $ do
775775
let sbe = convert Exp.ConwayEra
776776
inputCerts = Exp.mkTxCertificates Exp.ConwayEra allCerts
777777
Api.ShelleyTx _ ledgerTx <-
778-
H.evalEither $ createCompatibleTx sbe [] [] 0 (NoPParamsUpdate sbe) NoVotes inputCerts
778+
H.evalEither $ createCompatibleTx sbe [] [] mempty 0 (NoPParamsUpdate sbe) NoVotes inputCerts
779779
let bodyCerts = ledgerTx ^. L.bodyTxL . L.certsTxBodyL
780780
Seq.length bodyCerts H.=== expectedCount
781781

0 commit comments

Comments
 (0)