@@ -66,6 +66,7 @@ import Cardano.Ledger.Alonzo.TxCert ()
6666import Cardano.Ledger.BaseTypes (ProtVer (.. ), kindObject )
6767import Cardano.Ledger.Binary (
6868 Annotator ,
69+ CBORGroup (.. ),
6970 DecCBOR (decCBOR ),
7071 DecCBORGroup (.. ),
7172 Decoder ,
@@ -83,7 +84,6 @@ import Cardano.Ledger.Binary.Coders (
8384 decode ,
8485 encode ,
8586 (!>) ,
86- (<!) ,
8787 (<*!) ,
8888 )
8989import Cardano.Ledger.Binary.Plain (serializeAsHexText )
@@ -323,36 +323,62 @@ instance
323323 AlonzoCertifying x -> rnf x
324324 AlonzoRewarding x -> rnf x
325325
326- instance Era era => EncCBORGroup (AlonzoPlutusPurpose AsIx era ) where
326+ instance
327+ ( forall a b . (EncCBOR a , EncCBOR b ) => EncCBOR (f a b )
328+ , Era era
329+ , Typeable f
330+ , EncCBOR (TxCert era )
331+ ) =>
332+ EncCBORGroup (AlonzoPlutusPurpose f era )
333+ where
327334 listLen _ = 2
328335 listLenBound _ = 2
329336 encCBORGroup = \ case
330- AlonzoSpending ( AsIx redeemerIx) -> encodeWord8 0 <> encCBOR redeemerIx
331- AlonzoMinting ( AsIx redeemerIx) -> encodeWord8 1 <> encCBOR redeemerIx
332- AlonzoCertifying ( AsIx redeemerIx) -> encodeWord8 2 <> encCBOR redeemerIx
333- AlonzoRewarding ( AsIx redeemerIx) -> encodeWord8 3 <> encCBOR redeemerIx
337+ AlonzoSpending p -> encodeWord8 0 <> encCBOR p
338+ AlonzoMinting p -> encodeWord8 1 <> encCBOR p
339+ AlonzoCertifying p -> encodeWord8 2 <> encCBOR p
340+ AlonzoRewarding p -> encodeWord8 3 <> encCBOR p
334341 encodedGroupSizeExpr size_ _proxy =
335342 encodedSizeExpr size_ (Proxy :: Proxy Word8 )
336343 + encodedSizeExpr size_ (Proxy :: Proxy Word16 )
337344
338- instance Era era => DecCBORGroup (AlonzoPlutusPurpose AsIx era ) where
345+ instance
346+ ( forall a b . (DecCBOR a , DecCBOR b ) => DecCBOR (f a b )
347+ , Era era
348+ , Typeable f
349+ , DecCBOR (TxCert era )
350+ ) =>
351+ DecCBORGroup (AlonzoPlutusPurpose f era )
352+ where
339353 decCBORGroup =
340354 decodeWord8 >>= \ case
341- 0 -> AlonzoSpending . AsIx <$> decCBOR
342- 1 -> AlonzoMinting . AsIx <$> decCBOR
343- 2 -> AlonzoCertifying . AsIx <$> decCBOR
344- 3 -> AlonzoRewarding . AsIx <$> decCBOR
355+ 0 -> AlonzoSpending <$> decCBOR
356+ 1 -> AlonzoMinting <$> decCBOR
357+ 2 -> AlonzoCertifying <$> decCBOR
358+ 3 -> AlonzoRewarding <$> decCBOR
345359 n -> fail $ " Unexpected tag for AlonzoPlutusPurpose: " <> show n
346360
347- -- | Incorrect CBOR implementation. Missing length encoding. Must keep it for backwards
348- -- compatibility
349- instance Era era => EncCBOR (AlonzoPlutusPurpose AsIx era ) where
350- encCBOR = encCBORGroup
351-
352- -- | Incorrect CBOR implementation. Missing length encoding. Must keep it for backwards
353- -- compatibility
354- instance Era era => DecCBOR (AlonzoPlutusPurpose AsIx era ) where
355- decCBOR = decCBORGroup
361+ deriving via
362+ (CBORGroup (AlonzoPlutusPurpose f era))
363+ instance
364+ ( forall a b . (EncCBOR a , EncCBOR b ) => EncCBOR (f a b )
365+ , Era era
366+ , Typeable f
367+ , EncCBOR (TxCert era )
368+ ) =>
369+ EncCBOR (AlonzoPlutusPurpose f era )
370+
371+ deriving via
372+ (CBORGroup (AlonzoPlutusPurpose f era))
373+ instance
374+ ( forall a b . (EncCBOR a , EncCBOR b ) => EncCBOR (f a b )
375+ , forall a b . (DecCBOR a , DecCBOR b ) => DecCBOR (f a b )
376+ , Era era
377+ , Typeable f
378+ , EncCBOR (TxCert era )
379+ , DecCBOR (TxCert era )
380+ ) =>
381+ DecCBOR (AlonzoPlutusPurpose f era )
356382
357383instance
358384 ( forall a b . (ToJSON a , ToJSON b ) => ToJSON (f a b )
@@ -369,29 +395,6 @@ instance
369395 where
370396 kindObjectWithValue name n = kindObject name [" value" .= n]
371397
372- -- | /Note/ - serialization of `AlonzoPlutusPurpose` `AsItem`
373- --
374- -- * Tags do not match the `AlonzoPlutusPurpose` `AsIx`. Unfortunate inconsistency
375- --
376- -- * It is only used for predicate failures. Thus we can change it after Conway to be
377- -- consistent with `AlonzoPlutusPurpose` `AsIx`
378- instance (Era era , EncCBOR (TxCert era )) => EncCBOR (AlonzoPlutusPurpose AsItem era ) where
379- encCBOR = \ case
380- AlonzoSpending (AsItem x) -> encode (Sum (AlonzoSpending @ _ @ era . AsItem ) 1 !> To x)
381- AlonzoMinting (AsItem x) -> encode (Sum (AlonzoMinting @ _ @ era . AsItem ) 0 !> To x)
382- AlonzoCertifying (AsItem x) -> encode (Sum (AlonzoCertifying . AsItem ) 3 !> To x)
383- AlonzoRewarding (AsItem x) -> encode (Sum (AlonzoRewarding @ _ @ era . AsItem ) 2 !> To x)
384-
385- -- | See note on the `EncCBOR` instace.
386- instance (Era era , DecCBOR (TxCert era )) => DecCBOR (AlonzoPlutusPurpose AsItem era ) where
387- decCBOR = decode (Summands " AlonzoPlutusPurpose" dec)
388- where
389- dec 1 = SumD (AlonzoSpending . AsItem ) <! From
390- dec 0 = SumD (AlonzoMinting . AsItem ) <! From
391- dec 3 = SumD (AlonzoCertifying . AsItem ) <! From
392- dec 2 = SumD (AlonzoRewarding . AsItem ) <! From
393- dec n = Invalid n
394-
395398pattern SpendingPurpose ::
396399 AlonzoEraScript era => f Word32 TxIn -> PlutusPurpose f era
397400pattern SpendingPurpose c <- (toSpendingPurpose -> Just c)
0 commit comments