File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
src/Cardano/Api/Tx/Internal
test/cardano-api-test/Test/Cardano/Api Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -104,6 +104,7 @@ import Data.Typeable (Typeable)
104104import Data.Word
105105import GHC.Exts (IsList (.. ))
106106import GHC.Stack
107+ import GHC.TypeLits as TL
107108import Lens.Micro hiding (ix )
108109
109110-- ----------------------------------------------------------------------------
@@ -134,6 +135,21 @@ instance (Typeable ctx, IsShelleyBasedEra era) => FromCBOR (TxOut ctx era) where
134135 shelleyBasedEraConstraints (shelleyBasedEra @ era ) $
135136 pure (fromShelleyTxOut shelleyBasedEra) <*> L. fromEraCBOR @ (ShelleyLedgerEra era )
136137
138+ -- | We do not provide a 'ToCBOR' instance for 'TxOut' because they may
139+ -- contain supplemental datums and the CBOR representation does not support this.
140+ instance
141+ ( TypeError
142+ ( TL. Text " Cannot serialise 'TxOut' to CBOR."
143+ :$$: TL. Text
144+ " Serialisation for 'TxOut' type is not implemented because they may contain supplemental datums and the CBOR representation does not support this."
145+ )
146+ , Typeable ctx
147+ , IsShelleyBasedEra era
148+ )
149+ => ToCBOR (TxOut ctx era )
150+ where
151+ toCBOR = error " This shouldn't happen"
152+
137153deriving instance Eq (TxOut ctx era )
138154
139155deriving instance Show (TxOut ctx era )
Original file line number Diff line number Diff line change @@ -110,6 +110,13 @@ prop_roundtrip_tx_CBOR = H.property $ do
110110 x <- H. forAll $ genTx era
111111 shelleyBasedEraConstraints era $ H. trippingCbor (proxyToAsType Proxy ) x
112112
113+ -- | The CBOR representation fo TxOut does not allow for storing
114+ -- suplemental datums, so we cannot provide a serialization mechanism
115+ -- that is lossless and for which the roundtrip property would hold.
116+ -- Therefore, we only provide deserialisation functionality and we
117+ -- include serialization only for testing purposes. Additionally,
118+ -- we convert hash any supplemental datum generated before testing
119+ -- because, otherwise, the property would not hold.
113120prop_roundtrip_tx_out_CBOR :: Property
114121prop_roundtrip_tx_out_CBOR = H. property $ do
115122 AnyShelleyBasedEra era <- H. noteShowM . H. forAll $ Gen. element [minBound .. maxBound ]
You can’t perform that action at this time.
0 commit comments