{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Cardano.Ledger.Alonzo.Block () where

import Cardano.Ledger.Alonzo.BlockBody ()
import Cardano.Ledger.Alonzo.Era
import Cardano.Ledger.Alonzo.Tx ()
import Cardano.Ledger.Binary (
  Annotator,
  DecCBOR (decCBOR),
  EncCBOR (..),
  EncCBORGroup (..),
  decodeRecordNamed,
  encodeListLen,
  toPlainEncoding,
 )
import qualified Cardano.Ledger.Binary.Plain as Plain
import Cardano.Ledger.Block (Block (..))
import Cardano.Ledger.Core
import Data.Typeable (Typeable)

instance EncCBOR h => EncCBOR (Block h AlonzoEra) where
  encCBOR :: Block h AlonzoEra -> Encoding
encCBOR (Block h
h BlockBody AlonzoEra
txns) =
    Word -> Encoding
encodeListLen Word
5 Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> h -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR h
h Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> AlonzoBlockBody AlonzoEra -> Encoding
forall a. EncCBORGroup a => a -> Encoding
encCBORGroup BlockBody AlonzoEra
AlonzoBlockBody AlonzoEra
txns

instance (EncCBOR h, Typeable h) => Plain.ToCBOR (Block h AlonzoEra) where
  toCBOR :: Block h AlonzoEra -> Encoding
toCBOR = Version -> Encoding -> Encoding
toPlainEncoding (forall era. Era era => Version
eraProtVerLow @AlonzoEra) (Encoding -> Encoding)
-> (Block h AlonzoEra -> Encoding) -> Block h AlonzoEra -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Block h AlonzoEra -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR

instance
  (DecCBOR (Annotator h), Typeable h) =>
  DecCBOR (Annotator (Block h AlonzoEra))
  where
  decCBOR :: forall s. Decoder s (Annotator (Block h AlonzoEra))
decCBOR =
    Text
-> (Annotator (Block h AlonzoEra) -> Int)
-> Decoder s (Annotator (Block h AlonzoEra))
-> Decoder s (Annotator (Block h AlonzoEra))
forall a s. Text -> (a -> Int) -> Decoder s a -> Decoder s a
decodeRecordNamed Text
"Block" (Int -> Annotator (Block h AlonzoEra) -> Int
forall a b. a -> b -> a
const Int
5) (Decoder s (Annotator (Block h AlonzoEra))
 -> Decoder s (Annotator (Block h AlonzoEra)))
-> Decoder s (Annotator (Block h AlonzoEra))
-> Decoder s (Annotator (Block h AlonzoEra))
forall a b. (a -> b) -> a -> b
$ do
      header <- Decoder s (Annotator h)
forall s. Decoder s (Annotator h)
forall a s. DecCBOR a => Decoder s a
decCBOR
      txns <- decCBOR
      pure $ Block <$> header <*> txns