File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
src/Cardano/Api/Tx/Internal
test/cardano-api-test/Test/Cardano/Api Expand file tree Collapse file tree 2 files changed +27
-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,23 @@ 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 'TxOut's can
139+ -- contain supplemental datums and the CBOR representation does not support this.
140+ -- For this reason, if we were to serialise a 'TxOut' with a supplemental datum,
141+ -- we would lose information and the roundtrip property would not hold.
142+ instance
143+ ( TypeError
144+ ( TL. Text " Cannot serialise 'TxOut' to CBOR."
145+ :$$: TL. Text
146+ " Serialisation for 'TxOut' type is not implemented because they may contain supplemental datums and the CBOR representation does not support this."
147+ )
148+ , Typeable ctx
149+ , IsShelleyBasedEra era
150+ )
151+ => ToCBOR (TxOut ctx era )
152+ where
153+ toCBOR = error " This shouldn't happen"
154+
137155deriving instance Eq (TxOut ctx era )
138156
139157deriving instance Show (TxOut ctx era )
Original file line number Diff line number Diff line change @@ -110,6 +110,15 @@ 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 for 'TxOut' does not store supplemental datums.
114+ -- This means we cannot provide a lossless serialisation instance for which
115+ -- a roundtrip property would hold.
116+ --
117+ -- Therefore, we only provide a deserialisation instance. The serialisation
118+ -- implementation is included for testing purposes only.
119+ --
120+ -- For the roundtrip test, we hash any supplemental datum before serialisation
121+ -- to ensure the property holds.
113122prop_roundtrip_tx_out_CBOR :: Property
114123prop_roundtrip_tx_out_CBOR = H. property $ do
115124 AnyShelleyBasedEra era <- H. noteShowM . H. forAll $ Gen. element [minBound .. maxBound ]
You can’t perform that action at this time.
0 commit comments