55{-# LANGUAGE FlexibleContexts #-}
66{-# LANGUAGE FlexibleInstances #-}
77{-# LANGUAGE GADTs #-}
8+ {-# LANGUAGE InstanceSigs #-}
89{-# LANGUAGE LambdaCase #-}
910{-# LANGUAGE RankNTypes #-}
1011{-# LANGUAGE ScopedTypeVariables #-}
1112{-# LANGUAGE StandaloneDeriving #-}
1213{-# LANGUAGE TypeApplications #-}
1314{-# LANGUAGE TypeFamilies #-}
1415{-# LANGUAGE TypeOperators #-}
16+ {-# LANGUAGE UndecidableInstances #-}
1517
1618module Cardano.Api.Tx.Internal.Output
1719 ( -- * Transaction outputs
@@ -63,7 +65,7 @@ import Cardano.Api.Era.Internal.Eon.Convert
6365import Cardano.Api.Era.Internal.Eon.ConwayEraOnwards
6466import Cardano.Api.Era.Internal.Eon.ShelleyBasedEra
6567import Cardano.Api.Error (Error (.. ), displayError )
66- import Cardano.Api.Hash
68+ import Cardano.Api.HasTypeProxy qualified as HTP
6769import Cardano.Api.Ledger.Internal.Reexport qualified as Ledger
6870import Cardano.Api.Monad.Error
6971import Cardano.Api.Parser.Text qualified as P
@@ -82,7 +84,6 @@ import Cardano.Ledger.Alonzo.Core qualified as L
8284import Cardano.Ledger.Api qualified as L
8385import Cardano.Ledger.BaseTypes (StrictMaybe (.. ))
8486import Cardano.Ledger.Coin qualified as L
85- import Cardano.Ledger.Core ()
8687import Cardano.Ledger.Core qualified as Core
8788import Cardano.Ledger.Core qualified as Ledger
8889import Cardano.Ledger.Plutus.Data qualified as Plutus
@@ -100,6 +101,7 @@ import Data.Sequence.Strict qualified as Seq
100101import Data.Text (Text )
101102import Data.Text.Encoding qualified as Text
102103import Data.Type.Equality
104+ import Data.Typeable (Typeable )
103105import Data.Word
104106import GHC.Exts (IsList (.. ))
105107import GHC.Stack
@@ -122,6 +124,21 @@ data TxOut ctx era
122124 (TxOutDatum ctx era )
123125 (ReferenceScript era )
124126
127+ instance (Typeable ctx , IsShelleyBasedEra era ) => HTP. HasTypeProxy (TxOut ctx era ) where
128+ data AsType (TxOut ctx era ) = AsTxOut (AsType era )
129+ proxyToAsType :: HTP. Proxy (TxOut ctx era ) -> AsType (TxOut ctx era )
130+ proxyToAsType _ = AsTxOut (HTP.asType @ era )
131+
132+ -- | We do not provide a 'ToCBOR' instance for 'TxOut' because 'TxOut's can contain
133+ -- supplemental datums and the ledger's CBOR representation does not support this.
134+ -- For this reason, if we were to serialise a 'TxOut' with a supplemental datum,
135+ -- we would lose information and the roundtrip property would not hold.
136+ instance (Typeable ctx , IsShelleyBasedEra era ) => FromCBOR (TxOut ctx era ) where
137+ fromCBOR :: Ledger. Decoder s (TxOut ctx era )
138+ fromCBOR =
139+ shelleyBasedEraConstraints (shelleyBasedEra @ era ) $
140+ pure (fromShelleyTxOut shelleyBasedEra) <*> L. fromEraCBOR @ (ShelleyLedgerEra era )
141+
125142deriving instance Eq (TxOut ctx era )
126143
127144deriving instance Show (TxOut ctx era )
0 commit comments