{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Test.Cardano.Ledger.Allegra.Binary.Annotator (
  module Test.Cardano.Ledger.Shelley.Binary.Annotator,
) where

import Cardano.Ledger.Allegra (AllegraEra)
import Cardano.Ledger.Allegra.Scripts
import Cardano.Ledger.Allegra.TxAuxData
import Cardano.Ledger.Allegra.TxBody
import Cardano.Ledger.Binary
import Cardano.Ledger.Binary.Coders
import Cardano.Ledger.Core
import Cardano.Ledger.MemoBytes (decodeMemoized)
import qualified Data.Sequence.Strict as StrictSeq
import Test.Cardano.Ledger.Allegra.Arbitrary ()
import Test.Cardano.Ledger.Shelley.Binary.Annotator

deriving newtype instance DecCBOR (TxBody AllegraEra)

instance Era era => DecCBOR (AllegraTxAuxDataRaw era) where
  decCBOR :: forall s. Decoder s (AllegraTxAuxDataRaw era)
decCBOR =
    Decoder s TokenType
forall s. Decoder s TokenType
peekTokenType Decoder s TokenType
-> (TokenType -> Decoder s (AllegraTxAuxDataRaw era))
-> Decoder s (AllegraTxAuxDataRaw era)
forall a b. Decoder s a -> (a -> Decoder s b) -> Decoder s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
      TokenType
TypeMapLen -> Decoder s (AllegraTxAuxDataRaw era)
forall s. Decoder s (AllegraTxAuxDataRaw era)
decodeFromMap
      TokenType
TypeMapLen64 -> Decoder s (AllegraTxAuxDataRaw era)
forall s. Decoder s (AllegraTxAuxDataRaw era)
decodeFromMap
      TokenType
TypeMapLenIndef -> Decoder s (AllegraTxAuxDataRaw era)
forall s. Decoder s (AllegraTxAuxDataRaw era)
decodeFromMap
      TokenType
TypeListLen -> Decoder s (AllegraTxAuxDataRaw era)
forall s. Decoder s (AllegraTxAuxDataRaw era)
decodeFromList
      TokenType
TypeListLen64 -> Decoder s (AllegraTxAuxDataRaw era)
forall s. Decoder s (AllegraTxAuxDataRaw era)
decodeFromList
      TokenType
TypeListLenIndef -> Decoder s (AllegraTxAuxDataRaw era)
forall s. Decoder s (AllegraTxAuxDataRaw era)
decodeFromList
      TokenType
_ -> String -> Decoder s (AllegraTxAuxDataRaw era)
forall a. String -> Decoder s a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Failed to decode AuxiliaryDataRaw"
    where
      decodeFromMap :: Decoder s (AllegraTxAuxDataRaw era)
decodeFromMap =
        Decode Any (AllegraTxAuxDataRaw era)
-> Decoder s (AllegraTxAuxDataRaw era)
forall t (w :: Wrapped) s. Typeable t => Decode w t -> Decoder s t
decode
          ( (Map Word64 Metadatum
 -> StrictSeq (Timelock era) -> AllegraTxAuxDataRaw era)
-> Decode
     Any
     (Map Word64 Metadatum
      -> StrictSeq (Timelock era) -> AllegraTxAuxDataRaw era)
forall t (w :: Wrapped). t -> Decode w t
Emit Map Word64 Metadatum
-> StrictSeq (Timelock era) -> AllegraTxAuxDataRaw era
forall era.
Map Word64 Metadatum
-> StrictSeq (Timelock era) -> AllegraTxAuxDataRaw era
AllegraTxAuxDataRaw
              Decode
  Any
  (Map Word64 Metadatum
   -> StrictSeq (Timelock era) -> AllegraTxAuxDataRaw era)
-> Decode ('Closed Any) (Map Word64 Metadatum)
-> Decode Any (StrictSeq (Timelock era) -> AllegraTxAuxDataRaw era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) (Map Word64 Metadatum)
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
              Decode Any (StrictSeq (Timelock era) -> AllegraTxAuxDataRaw era)
-> Decode ('Closed Any) (StrictSeq (Timelock era))
-> Decode Any (AllegraTxAuxDataRaw era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! StrictSeq (Timelock era)
-> Decode ('Closed Any) (StrictSeq (Timelock era))
forall t (w :: Wrapped). t -> Decode w t
Emit StrictSeq (Timelock era)
forall a. StrictSeq a
StrictSeq.empty
          )
      decodeFromList :: Decoder s (AllegraTxAuxDataRaw era)
decodeFromList =
        Decode ('Closed 'Dense) (AllegraTxAuxDataRaw era)
-> Decoder s (AllegraTxAuxDataRaw era)
forall t (w :: Wrapped) s. Typeable t => Decode w t -> Decoder s t
decode
          ( (Map Word64 Metadatum
 -> StrictSeq (Timelock era) -> AllegraTxAuxDataRaw era)
-> Decode
     ('Closed 'Dense)
     (Map Word64 Metadatum
      -> StrictSeq (Timelock era) -> AllegraTxAuxDataRaw era)
forall t. t -> Decode ('Closed 'Dense) t
RecD Map Word64 Metadatum
-> StrictSeq (Timelock era) -> AllegraTxAuxDataRaw era
forall era.
Map Word64 Metadatum
-> StrictSeq (Timelock era) -> AllegraTxAuxDataRaw era
AllegraTxAuxDataRaw
              Decode
  ('Closed 'Dense)
  (Map Word64 Metadatum
   -> StrictSeq (Timelock era) -> AllegraTxAuxDataRaw era)
-> Decode ('Closed Any) (Map Word64 Metadatum)
-> Decode
     ('Closed 'Dense)
     (StrictSeq (Timelock era) -> AllegraTxAuxDataRaw era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) (Map Word64 Metadatum)
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
              Decode
  ('Closed 'Dense)
  (StrictSeq (Timelock era) -> AllegraTxAuxDataRaw era)
-> Decode ('Closed Any) (StrictSeq (Timelock era))
-> Decode ('Closed 'Dense) (AllegraTxAuxDataRaw era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) (StrictSeq (Timelock era))
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
          )

deriving newtype instance Era era => DecCBOR (AllegraTxAuxData era)

instance Era era => DecCBOR (TimelockRaw era) where
  decCBOR :: forall s. Decoder s (TimelockRaw era)
decCBOR = Decode ('Closed 'Dense) (TimelockRaw era)
-> Decoder s (TimelockRaw era)
forall t (w :: Wrapped) s. Typeable t => Decode w t -> Decoder s t
decode (Decode ('Closed 'Dense) (TimelockRaw era)
 -> Decoder s (TimelockRaw era))
-> Decode ('Closed 'Dense) (TimelockRaw era)
-> Decoder s (TimelockRaw era)
forall a b. (a -> b) -> a -> b
$ Text
-> (Word -> Decode 'Open (TimelockRaw era))
-> Decode ('Closed 'Dense) (TimelockRaw era)
forall t.
Text -> (Word -> Decode 'Open t) -> Decode ('Closed 'Dense) t
Summands Text
"TimelockRaw" ((Word -> Decode 'Open (TimelockRaw era))
 -> Decode ('Closed 'Dense) (TimelockRaw era))
-> (Word -> Decode 'Open (TimelockRaw era))
-> Decode ('Closed 'Dense) (TimelockRaw era)
forall a b. (a -> b) -> a -> b
$ \case
    Word
0 -> (KeyHash 'Witness -> TimelockRaw era)
-> Decode 'Open (KeyHash 'Witness -> TimelockRaw era)
forall t. t -> Decode 'Open t
SumD KeyHash 'Witness -> TimelockRaw era
forall {k} (era :: k). KeyHash 'Witness -> TimelockRaw era
TimelockSignature Decode 'Open (KeyHash 'Witness -> TimelockRaw era)
-> Decode ('Closed Any) (KeyHash 'Witness)
-> Decode 'Open (TimelockRaw era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) (KeyHash 'Witness)
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
    Word
1 -> (StrictSeq (Timelock era) -> TimelockRaw era)
-> Decode 'Open (StrictSeq (Timelock era) -> TimelockRaw era)
forall t. t -> Decode 'Open t
SumD StrictSeq (Timelock era) -> TimelockRaw era
forall {k} (era :: k). StrictSeq (Timelock era) -> TimelockRaw era
TimelockAllOf Decode 'Open (StrictSeq (Timelock era) -> TimelockRaw era)
-> Decode ('Closed Any) (StrictSeq (Timelock era))
-> Decode 'Open (TimelockRaw era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) (StrictSeq (Timelock era))
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
    Word
2 -> (StrictSeq (Timelock era) -> TimelockRaw era)
-> Decode 'Open (StrictSeq (Timelock era) -> TimelockRaw era)
forall t. t -> Decode 'Open t
SumD StrictSeq (Timelock era) -> TimelockRaw era
forall {k} (era :: k). StrictSeq (Timelock era) -> TimelockRaw era
TimelockAnyOf Decode 'Open (StrictSeq (Timelock era) -> TimelockRaw era)
-> Decode ('Closed Any) (StrictSeq (Timelock era))
-> Decode 'Open (TimelockRaw era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) (StrictSeq (Timelock era))
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
    Word
3 -> (Int -> StrictSeq (Timelock era) -> TimelockRaw era)
-> Decode
     'Open (Int -> StrictSeq (Timelock era) -> TimelockRaw era)
forall t. t -> Decode 'Open t
SumD Int -> StrictSeq (Timelock era) -> TimelockRaw era
forall {k} (era :: k).
Int -> StrictSeq (Timelock era) -> TimelockRaw era
TimelockMOf Decode 'Open (Int -> StrictSeq (Timelock era) -> TimelockRaw era)
-> Decode ('Closed Any) Int
-> Decode 'Open (StrictSeq (Timelock era) -> TimelockRaw era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) Int
forall t (w :: Wrapped). DecCBOR t => Decode w t
From Decode 'Open (StrictSeq (Timelock era) -> TimelockRaw era)
-> Decode ('Closed Any) (StrictSeq (Timelock era))
-> Decode 'Open (TimelockRaw era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) (StrictSeq (Timelock era))
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
    Word
4 -> (SlotNo -> TimelockRaw era)
-> Decode 'Open (SlotNo -> TimelockRaw era)
forall t. t -> Decode 'Open t
SumD SlotNo -> TimelockRaw era
forall {k} (era :: k). SlotNo -> TimelockRaw era
TimelockTimeStart Decode 'Open (SlotNo -> TimelockRaw era)
-> Decode ('Closed Any) SlotNo -> Decode 'Open (TimelockRaw era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) SlotNo
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
    Word
5 -> (SlotNo -> TimelockRaw era)
-> Decode 'Open (SlotNo -> TimelockRaw era)
forall t. t -> Decode 'Open t
SumD SlotNo -> TimelockRaw era
forall {k} (era :: k). SlotNo -> TimelockRaw era
TimelockTimeExpire Decode 'Open (SlotNo -> TimelockRaw era)
-> Decode ('Closed Any) SlotNo -> Decode 'Open (TimelockRaw era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) SlotNo
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
    Word
n -> Word -> Decode 'Open (TimelockRaw era)
forall (w :: Wrapped) t. Word -> Decode w t
Invalid Word
n

instance Era era => DecCBOR (Timelock era) where
  decCBOR :: forall s. Decoder s (Timelock era)
decCBOR = MemoBytes (TimelockRaw era) -> Timelock era
forall {k} (era :: k). MemoBytes (TimelockRaw era) -> Timelock era
MkTimelock (MemoBytes (TimelockRaw era) -> Timelock era)
-> Decoder s (MemoBytes (TimelockRaw era))
-> Decoder s (Timelock era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s (TimelockRaw era)
-> Decoder s (MemoBytes (TimelockRaw era))
forall s t. Decoder s t -> Decoder s (MemoBytes t)
decodeMemoized Decoder s (TimelockRaw era)
forall s. Decoder s (TimelockRaw era)
forall a s. DecCBOR a => Decoder s a
decCBOR