{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
{-# LANGUAGE MonoLocalBinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Test.Cardano.Ledger.Babbage.Binary.Annotator (
  module Test.Cardano.Ledger.Alonzo.Binary.Annotator,
) where

import Cardano.Ledger.Babbage (BabbageEra, Tx (..))
import Cardano.Ledger.Babbage.Core
import Cardano.Ledger.Babbage.TxBody
import Cardano.Ledger.Binary
import Cardano.Ledger.Block (Block (..))
import Cardano.Ledger.MempoolTx.Internal (MempoolTx (..))
import Test.Cardano.Ledger.Alonzo.Binary.Annotator

deriving newtype instance DecCBOR (TxBody TopTx BabbageEra)

instance DecCBOR (MempoolTx BabbageEra) where
  decCBOR :: forall s. Decoder s (MempoolTx BabbageEra)
decCBOR = Tx TopTx BabbageEra -> MempoolTx BabbageEra
forall era. Tx TopTx era -> MempoolTx era
UnsafeMkMempoolTx (Tx TopTx BabbageEra -> MempoolTx BabbageEra)
-> (AlonzoTx TopTx BabbageEra -> Tx TopTx BabbageEra)
-> AlonzoTx TopTx BabbageEra
-> MempoolTx BabbageEra
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AlonzoTx TopTx BabbageEra -> Tx TopTx BabbageEra
forall (l :: TxLevel). AlonzoTx l BabbageEra -> Tx l BabbageEra
MkBabbageTx (AlonzoTx TopTx BabbageEra -> MempoolTx BabbageEra)
-> Decoder s (AlonzoTx TopTx BabbageEra)
-> Decoder s (MempoolTx BabbageEra)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s (AlonzoTx TopTx BabbageEra)
forall s. Decoder s (AlonzoTx TopTx BabbageEra)
forall a s. DecCBOR a => Decoder s a
decCBOR

instance DecCBOR h => DecCBOR (Block h BabbageEra) where
  decCBOR :: forall s. Decoder s (Block h BabbageEra)
decCBOR =
    Text
-> (Block h BabbageEra -> Int)
-> Decoder s (Block h BabbageEra)
-> Decoder s (Block h BabbageEra)
forall a s. Text -> (a -> Int) -> Decoder s a -> Decoder s a
decodeRecordNamed Text
"Block" (Int -> Block h BabbageEra -> Int
forall a b. a -> b -> a
const Int
5) (Decoder s (Block h BabbageEra) -> Decoder s (Block h BabbageEra))
-> Decoder s (Block h BabbageEra) -> Decoder s (Block h BabbageEra)
forall a b. (a -> b) -> a -> b
$ h -> BlockBody BabbageEra -> Block h BabbageEra
h -> AlonzoBlockBody BabbageEra -> Block h BabbageEra
forall h era. h -> BlockBody era -> Block h era
Block (h -> AlonzoBlockBody BabbageEra -> Block h BabbageEra)
-> Decoder s h
-> Decoder s (AlonzoBlockBody BabbageEra -> Block h BabbageEra)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s h
forall s. Decoder s h
forall a s. DecCBOR a => Decoder s a
decCBOR Decoder s (AlonzoBlockBody BabbageEra -> Block h BabbageEra)
-> Decoder s (AlonzoBlockBody BabbageEra)
-> Decoder s (Block h BabbageEra)
forall a b. Decoder s (a -> b) -> Decoder s a -> Decoder s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s (AlonzoBlockBody BabbageEra)
forall s. Decoder s (AlonzoBlockBody BabbageEra)
forall a s. DecCBOR a => Decoder s a
decCBOR