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

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

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

deriving newtype instance DecCBOR (TxBody TopTx ConwayEra)

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

instance DecCBOR h => DecCBOR (Block h ConwayEra) where
  decCBOR :: forall s. Decoder s (Block h ConwayEra)
decCBOR =
    Text
-> (Block h ConwayEra -> Int)
-> Decoder s (Block h ConwayEra)
-> Decoder s (Block h ConwayEra)
forall a s. Text -> (a -> Int) -> Decoder s a -> Decoder s a
decodeRecordNamed Text
"Block" (Int -> Block h ConwayEra -> Int
forall a b. a -> b -> a
const Int
5) (Decoder s (Block h ConwayEra) -> Decoder s (Block h ConwayEra))
-> Decoder s (Block h ConwayEra) -> Decoder s (Block h ConwayEra)
forall a b. (a -> b) -> a -> b
$ h -> BlockBody ConwayEra -> Block h ConwayEra
h -> AlonzoBlockBody ConwayEra -> Block h ConwayEra
forall h era. h -> BlockBody era -> Block h era
Block (h -> AlonzoBlockBody ConwayEra -> Block h ConwayEra)
-> Decoder s h
-> Decoder s (AlonzoBlockBody ConwayEra -> Block h ConwayEra)
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 ConwayEra -> Block h ConwayEra)
-> Decoder s (AlonzoBlockBody ConwayEra)
-> Decoder s (Block h ConwayEra)
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 ConwayEra)
forall s. Decoder s (AlonzoBlockBody ConwayEra)
forall a s. DecCBOR a => Decoder s a
decCBOR