{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ViewPatterns #-}

-- | Block header associated with Leios.
--
-- The Leios block header is the Praos block header with two additional fields
-- appended. Everything else is identical to the Praos header, see
-- "Cardano.Protocol.Praos.BlockHeader" for details.
module Cardano.Protocol.Leios.BlockHeader (
  Header (HeaderConstr, Header, headerBody, headerSig),
  HeaderBody (..),
  EbAnnouncement (..),
  headerHash,
  headerSize,
) where

import qualified Cardano.Crypto.Hash as Hash
import qualified Cardano.Crypto.KES as KES
import Cardano.Crypto.Util (
  SignableRepresentation (getSignableRepresentation),
 )
import qualified Cardano.Crypto.VRF as VRF
import Cardano.Ledger.BaseTypes (ProtVer (pvMajor))
import Cardano.Ledger.Binary (
  Annotator (..),
  DecCBOR (decCBOR),
  EncCBOR (..),
  decodeFixedSized,
  decodeNullStrictMaybe,
  decodeRecordNamed,
  encodeFixedSized,
  encodeListLen,
  encodeNullStrictMaybe,
  serialize',
  unCBORGroup,
 )
import qualified Cardano.Ledger.Binary.Plain as Plain
import Cardano.Ledger.Block (Block (..), EraBlockHeader (..))
import Cardano.Ledger.Core (Era)
import Cardano.Ledger.Hashes (
  EraIndependentBlockBody,
  EraIndependentBlockHeader,
  EraIndependentEb,
  HASH,
  HashAnnotated (..),
  SafeHash,
  SafeToHash,
  extractHash,
  originalBytesSize,
 )
import Cardano.Ledger.Keys (KeyRole (BlockIssuer), VKey, hashKey)
import Cardano.Ledger.MemoBytes (
  Mem,
  MemoBytes,
  MemoHashIndex,
  Memoized (..),
  getMemoRawType,
  getMemoSafeHash,
  mkMemoized,
 )
import Cardano.Protocol.Crypto (Crypto, KES, VRF)
import Cardano.Protocol.Praos.VRF (InputVRF)
import Cardano.Protocol.TPraos.BlockHeader (PrevHash)
import Cardano.Protocol.TPraos.OCert (OCert)
import Cardano.Slotting.Block (BlockNo)
import Cardano.Slotting.Slot (SlotNo)
import Control.DeepSeq (NFData)
import Data.Maybe.Strict (StrictMaybe (..))
import Data.Word (Word32)
import GHC.Generics (Generic)
import Lens.Micro (lens, to)
import NoThunks.Class (NoThunks (..))

-- | Announcement of an Endorser Block (EB).
data EbAnnouncement = EbAnnouncement
  { EbAnnouncement -> SafeHash EraIndependentEb
ebAnnouncementHash :: !(SafeHash EraIndependentEb)
  , EbAnnouncement -> Word32
ebAnnouncementSize :: !Word32
  -- ^ Size of the EB block closure
  }
  deriving stock (Int -> EbAnnouncement -> ShowS
[EbAnnouncement] -> ShowS
EbAnnouncement -> String
(Int -> EbAnnouncement -> ShowS)
-> (EbAnnouncement -> String)
-> ([EbAnnouncement] -> ShowS)
-> Show EbAnnouncement
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> EbAnnouncement -> ShowS
showsPrec :: Int -> EbAnnouncement -> ShowS
$cshow :: EbAnnouncement -> String
show :: EbAnnouncement -> String
$cshowList :: [EbAnnouncement] -> ShowS
showList :: [EbAnnouncement] -> ShowS
Show, EbAnnouncement -> EbAnnouncement -> Bool
(EbAnnouncement -> EbAnnouncement -> Bool)
-> (EbAnnouncement -> EbAnnouncement -> Bool) -> Eq EbAnnouncement
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EbAnnouncement -> EbAnnouncement -> Bool
== :: EbAnnouncement -> EbAnnouncement -> Bool
$c/= :: EbAnnouncement -> EbAnnouncement -> Bool
/= :: EbAnnouncement -> EbAnnouncement -> Bool
Eq, (forall x. EbAnnouncement -> Rep EbAnnouncement x)
-> (forall x. Rep EbAnnouncement x -> EbAnnouncement)
-> Generic EbAnnouncement
forall x. Rep EbAnnouncement x -> EbAnnouncement
forall x. EbAnnouncement -> Rep EbAnnouncement x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. EbAnnouncement -> Rep EbAnnouncement x
from :: forall x. EbAnnouncement -> Rep EbAnnouncement x
$cto :: forall x. Rep EbAnnouncement x -> EbAnnouncement
to :: forall x. Rep EbAnnouncement x -> EbAnnouncement
Generic)
  deriving anyclass (Context -> EbAnnouncement -> IO (Maybe ThunkInfo)
Proxy EbAnnouncement -> String
(Context -> EbAnnouncement -> IO (Maybe ThunkInfo))
-> (Context -> EbAnnouncement -> IO (Maybe ThunkInfo))
-> (Proxy EbAnnouncement -> String)
-> NoThunks EbAnnouncement
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
$cnoThunks :: Context -> EbAnnouncement -> IO (Maybe ThunkInfo)
noThunks :: Context -> EbAnnouncement -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> EbAnnouncement -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> EbAnnouncement -> IO (Maybe ThunkInfo)
$cshowTypeOf :: Proxy EbAnnouncement -> String
showTypeOf :: Proxy EbAnnouncement -> String
NoThunks, EbAnnouncement -> ()
(EbAnnouncement -> ()) -> NFData EbAnnouncement
forall a. (a -> ()) -> NFData a
$crnf :: EbAnnouncement -> ()
rnf :: EbAnnouncement -> ()
NFData)

instance EncCBOR EbAnnouncement where
  encCBOR :: EbAnnouncement -> Encoding
encCBOR (EbAnnouncement SafeHash EraIndependentEb
h Word32
s) =
    Word -> Encoding
encodeListLen Word
2
      Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> SafeHash EraIndependentEb -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR SafeHash EraIndependentEb
h
      Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word32 -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR Word32
s

instance DecCBOR EbAnnouncement where
  decCBOR :: forall s. Decoder s EbAnnouncement
decCBOR =
    Text
-> (EbAnnouncement -> Int)
-> Decoder s EbAnnouncement
-> Decoder s EbAnnouncement
forall a s. Text -> (a -> Int) -> Decoder s a -> Decoder s a
decodeRecordNamed Text
"EbAnnouncement" (Int -> EbAnnouncement -> Int
forall a b. a -> b -> a
const Int
2) (Decoder s EbAnnouncement -> Decoder s EbAnnouncement)
-> Decoder s EbAnnouncement -> Decoder s EbAnnouncement
forall a b. (a -> b) -> a -> b
$
      SafeHash EraIndependentEb -> Word32 -> EbAnnouncement
EbAnnouncement
        (SafeHash EraIndependentEb -> Word32 -> EbAnnouncement)
-> Decoder s (SafeHash EraIndependentEb)
-> Decoder s (Word32 -> EbAnnouncement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s (SafeHash EraIndependentEb)
forall s. Decoder s (SafeHash EraIndependentEb)
forall a s. DecCBOR a => Decoder s a
decCBOR
        Decoder s (Word32 -> EbAnnouncement)
-> Decoder s Word32 -> Decoder s EbAnnouncement
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 Word32
forall s. Decoder s Word32
forall a s. DecCBOR a => Decoder s a
decCBOR

data HeaderBody crypto = HeaderBody
  { forall crypto. HeaderBody crypto -> BlockNo
hbBlockNo :: !BlockNo
  -- ^ block number
  , forall crypto. HeaderBody crypto -> SlotNo
hbSlotNo :: !SlotNo
  -- ^ block slot
  , forall crypto. HeaderBody crypto -> PrevHash
hbPrev :: !PrevHash
  -- ^ Hash of the previous block header
  , forall crypto. HeaderBody crypto -> VKey BlockIssuer
hbVk :: !(VKey BlockIssuer)
  -- ^ verification key of block issuer
  , forall crypto. HeaderBody crypto -> VerKeyVRF (VRF crypto)
hbVrfVk :: !(VRF.VerKeyVRF (VRF crypto))
  -- ^ VRF verification key for block issuer
  , forall crypto.
HeaderBody crypto -> CertifiedVRF (VRF crypto) InputVRF
hbVrfRes :: !(VRF.CertifiedVRF (VRF crypto) InputVRF)
  -- ^ Certified VRF value
  , forall crypto. HeaderBody crypto -> Word32
hbBodySize :: !Word32
  -- ^ Size of the block body
  , forall crypto.
HeaderBody crypto -> Hash HASH EraIndependentBlockBody
hbBodyHash :: !(Hash.Hash HASH EraIndependentBlockBody)
  -- ^ Hash of block body
  , forall crypto. HeaderBody crypto -> OCert crypto
hbOCert :: !(OCert crypto)
  -- ^ operational certificate
  , forall crypto. HeaderBody crypto -> ProtVer
hbProtVer :: !ProtVer
  -- ^ protocol version
  , forall crypto. HeaderBody crypto -> Bool
hbBlockBodyContainsLeiosCert :: !Bool
  -- ^ whether the block body contains a Leios certificate
  , forall crypto. HeaderBody crypto -> StrictMaybe EbAnnouncement
hbEbAnnouncement :: !(StrictMaybe EbAnnouncement)
  -- ^ Announcement of Endorser Block (EB)
  }
  deriving ((forall x. HeaderBody crypto -> Rep (HeaderBody crypto) x)
-> (forall x. Rep (HeaderBody crypto) x -> HeaderBody crypto)
-> Generic (HeaderBody crypto)
forall x. Rep (HeaderBody crypto) x -> HeaderBody crypto
forall x. HeaderBody crypto -> Rep (HeaderBody crypto) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall crypto x. Rep (HeaderBody crypto) x -> HeaderBody crypto
forall crypto x. HeaderBody crypto -> Rep (HeaderBody crypto) x
$cfrom :: forall crypto x. HeaderBody crypto -> Rep (HeaderBody crypto) x
from :: forall x. HeaderBody crypto -> Rep (HeaderBody crypto) x
$cto :: forall crypto x. Rep (HeaderBody crypto) x -> HeaderBody crypto
to :: forall x. Rep (HeaderBody crypto) x -> HeaderBody crypto
Generic)

deriving instance Crypto crypto => Show (HeaderBody crypto)

deriving instance Crypto crypto => Eq (HeaderBody crypto)

instance
  Crypto crypto =>
  SignableRepresentation (HeaderBody crypto)
  where
  getSignableRepresentation :: HeaderBody crypto -> ByteString
getSignableRepresentation HeaderBody crypto
hb = Version -> HeaderBody crypto -> ByteString
forall a. EncCBOR a => Version -> a -> ByteString
serialize' (ProtVer -> Version
pvMajor (HeaderBody crypto -> ProtVer
forall crypto. HeaderBody crypto -> ProtVer
hbProtVer HeaderBody crypto
hb)) HeaderBody crypto
hb

instance
  Crypto crypto =>
  NoThunks (HeaderBody crypto)

data HeaderRaw crypto = HeaderRaw
  { forall crypto. HeaderRaw crypto -> HeaderBody crypto
headerRawBody :: !(HeaderBody crypto)
  , forall crypto.
HeaderRaw crypto -> SignedKES (KES crypto) (HeaderBody crypto)
headerRawSig :: !(KES.SignedKES (KES crypto) (HeaderBody crypto))
  }
  deriving (Int -> HeaderRaw crypto -> ShowS
[HeaderRaw crypto] -> ShowS
HeaderRaw crypto -> String
(Int -> HeaderRaw crypto -> ShowS)
-> (HeaderRaw crypto -> String)
-> ([HeaderRaw crypto] -> ShowS)
-> Show (HeaderRaw crypto)
forall crypto. Crypto crypto => Int -> HeaderRaw crypto -> ShowS
forall crypto. Crypto crypto => [HeaderRaw crypto] -> ShowS
forall crypto. Crypto crypto => HeaderRaw crypto -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall crypto. Crypto crypto => Int -> HeaderRaw crypto -> ShowS
showsPrec :: Int -> HeaderRaw crypto -> ShowS
$cshow :: forall crypto. Crypto crypto => HeaderRaw crypto -> String
show :: HeaderRaw crypto -> String
$cshowList :: forall crypto. Crypto crypto => [HeaderRaw crypto] -> ShowS
showList :: [HeaderRaw crypto] -> ShowS
Show, (forall x. HeaderRaw crypto -> Rep (HeaderRaw crypto) x)
-> (forall x. Rep (HeaderRaw crypto) x -> HeaderRaw crypto)
-> Generic (HeaderRaw crypto)
forall x. Rep (HeaderRaw crypto) x -> HeaderRaw crypto
forall x. HeaderRaw crypto -> Rep (HeaderRaw crypto) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall crypto x. Rep (HeaderRaw crypto) x -> HeaderRaw crypto
forall crypto x. HeaderRaw crypto -> Rep (HeaderRaw crypto) x
$cfrom :: forall crypto x. HeaderRaw crypto -> Rep (HeaderRaw crypto) x
from :: forall x. HeaderRaw crypto -> Rep (HeaderRaw crypto) x
$cto :: forall crypto x. Rep (HeaderRaw crypto) x -> HeaderRaw crypto
to :: forall x. Rep (HeaderRaw crypto) x -> HeaderRaw crypto
Generic)

instance Crypto c => Eq (HeaderRaw c) where
  HeaderRaw c
h1 == :: HeaderRaw c -> HeaderRaw c -> Bool
== HeaderRaw c
h2 =
    HeaderRaw c -> SignedKES (KES c) (HeaderBody c)
forall crypto.
HeaderRaw crypto -> SignedKES (KES crypto) (HeaderBody crypto)
headerRawSig HeaderRaw c
h1 SignedKES (KES c) (HeaderBody c)
-> SignedKES (KES c) (HeaderBody c) -> Bool
forall a. Eq a => a -> a -> Bool
== HeaderRaw c -> SignedKES (KES c) (HeaderBody c)
forall crypto.
HeaderRaw crypto -> SignedKES (KES crypto) (HeaderBody crypto)
headerRawSig HeaderRaw c
h2
      Bool -> Bool -> Bool
&& HeaderRaw c -> HeaderBody c
forall crypto. HeaderRaw crypto -> HeaderBody crypto
headerRawBody HeaderRaw c
h1 HeaderBody c -> HeaderBody c -> Bool
forall a. Eq a => a -> a -> Bool
== HeaderRaw c -> HeaderBody c
forall crypto. HeaderRaw crypto -> HeaderBody crypto
headerRawBody HeaderRaw c
h2

instance
  Crypto crypto =>
  NoThunks (HeaderRaw crypto)

newtype Header crypto = HeaderConstr (MemoBytes (HeaderRaw crypto))
  deriving ((forall x. Header crypto -> Rep (Header crypto) x)
-> (forall x. Rep (Header crypto) x -> Header crypto)
-> Generic (Header crypto)
forall x. Rep (Header crypto) x -> Header crypto
forall x. Header crypto -> Rep (Header crypto) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall crypto x. Rep (Header crypto) x -> Header crypto
forall crypto x. Header crypto -> Rep (Header crypto) x
$cfrom :: forall crypto x. Header crypto -> Rep (Header crypto) x
from :: forall x. Header crypto -> Rep (Header crypto) x
$cto :: forall crypto x. Rep (Header crypto) x -> Header crypto
to :: forall x. Rep (Header crypto) x -> Header crypto
Generic)
  deriving newtype (Header crypto -> Header crypto -> Bool
(Header crypto -> Header crypto -> Bool)
-> (Header crypto -> Header crypto -> Bool) -> Eq (Header crypto)
forall crypto.
Crypto crypto =>
Header crypto -> Header crypto -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall crypto.
Crypto crypto =>
Header crypto -> Header crypto -> Bool
== :: Header crypto -> Header crypto -> Bool
$c/= :: forall crypto.
Crypto crypto =>
Header crypto -> Header crypto -> Bool
/= :: Header crypto -> Header crypto -> Bool
Eq, Int -> Header crypto -> ShowS
[Header crypto] -> ShowS
Header crypto -> String
(Int -> Header crypto -> ShowS)
-> (Header crypto -> String)
-> ([Header crypto] -> ShowS)
-> Show (Header crypto)
forall crypto. Crypto crypto => Int -> Header crypto -> ShowS
forall crypto. Crypto crypto => [Header crypto] -> ShowS
forall crypto. Crypto crypto => Header crypto -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall crypto. Crypto crypto => Int -> Header crypto -> ShowS
showsPrec :: Int -> Header crypto -> ShowS
$cshow :: forall crypto. Crypto crypto => Header crypto -> String
show :: Header crypto -> String
$cshowList :: forall crypto. Crypto crypto => [Header crypto] -> ShowS
showList :: [Header crypto] -> ShowS
Show, Context -> Header crypto -> IO (Maybe ThunkInfo)
Proxy (Header crypto) -> String
(Context -> Header crypto -> IO (Maybe ThunkInfo))
-> (Context -> Header crypto -> IO (Maybe ThunkInfo))
-> (Proxy (Header crypto) -> String)
-> NoThunks (Header crypto)
forall crypto.
Crypto crypto =>
Context -> Header crypto -> IO (Maybe ThunkInfo)
forall crypto. Crypto crypto => Proxy (Header crypto) -> String
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
$cnoThunks :: forall crypto.
Crypto crypto =>
Context -> Header crypto -> IO (Maybe ThunkInfo)
noThunks :: Context -> Header crypto -> IO (Maybe ThunkInfo)
$cwNoThunks :: forall crypto.
Crypto crypto =>
Context -> Header crypto -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> Header crypto -> IO (Maybe ThunkInfo)
$cshowTypeOf :: forall crypto. Crypto crypto => Proxy (Header crypto) -> String
showTypeOf :: Proxy (Header crypto) -> String
NoThunks, Typeable (Header crypto)
Typeable (Header crypto) =>
(Header crypto -> Encoding)
-> ((forall t. ToCBOR t => Proxy t -> Size)
    -> Proxy (Header crypto) -> Size)
-> ((forall t. ToCBOR t => Proxy t -> Size)
    -> Proxy [Header crypto] -> Size)
-> ToCBOR (Header crypto)
Header crypto -> Encoding
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [Header crypto] -> Size
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (Header crypto) -> Size
forall crypto. Typeable crypto => Typeable (Header crypto)
forall crypto. Typeable crypto => Header crypto -> Encoding
forall a.
Typeable a =>
(a -> Encoding)
-> ((forall t. ToCBOR t => Proxy t -> Size) -> Proxy a -> Size)
-> ((forall t. ToCBOR t => Proxy t -> Size) -> Proxy [a] -> Size)
-> ToCBOR a
forall crypto.
Typeable crypto =>
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [Header crypto] -> Size
forall crypto.
Typeable crypto =>
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (Header crypto) -> Size
$ctoCBOR :: forall crypto. Typeable crypto => Header crypto -> Encoding
toCBOR :: Header crypto -> Encoding
$cencodedSizeExpr :: forall crypto.
Typeable crypto =>
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (Header crypto) -> Size
encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (Header crypto) -> Size
$cencodedListSizeExpr :: forall crypto.
Typeable crypto =>
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [Header crypto] -> Size
encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [Header crypto] -> Size
Plain.ToCBOR, Header crypto -> Int
Header crypto -> ByteString
(Header crypto -> ByteString)
-> (Header crypto -> Int)
-> (forall i. Proxy i -> Header crypto -> SafeHash i)
-> SafeToHash (Header crypto)
forall i. Proxy i -> Header crypto -> SafeHash i
forall crypto. Header crypto -> Int
forall crypto. Header crypto -> ByteString
forall t.
(t -> ByteString)
-> (t -> Int)
-> (forall i. Proxy i -> t -> SafeHash i)
-> SafeToHash t
forall crypto i. Proxy i -> Header crypto -> SafeHash i
$coriginalBytes :: forall crypto. Header crypto -> ByteString
originalBytes :: Header crypto -> ByteString
$coriginalBytesSize :: forall crypto. Header crypto -> Int
originalBytesSize :: Header crypto -> Int
$cmakeHashWithExplicitProxys :: forall crypto i. Proxy i -> Header crypto -> SafeHash i
makeHashWithExplicitProxys :: forall i. Proxy i -> Header crypto -> SafeHash i
SafeToHash)

instance Memoized (Header crypto) where
  type RawType (Header crypto) = HeaderRaw crypto

type instance MemoHashIndex (HeaderRaw crypto) = EraIndependentBlockHeader

instance HashAnnotated (Header crypto) EraIndependentBlockHeader where
  hashAnnotated :: Header crypto -> SafeHash EraIndependentBlockHeader
hashAnnotated = Header crypto -> SafeHash EraIndependentBlockHeader
Header crypto -> SafeHash (MemoHashIndex (RawType (Header crypto)))
forall t. Memoized t => t -> SafeHash (MemoHashIndex (RawType t))
getMemoSafeHash

pattern Header ::
  Crypto crypto =>
  HeaderBody crypto ->
  KES.SignedKES (KES crypto) (HeaderBody crypto) ->
  Header crypto
pattern $mHeader :: forall {r} {crypto}.
Crypto crypto =>
Header crypto
-> (HeaderBody crypto
    -> SignedKES (KES crypto) (HeaderBody crypto) -> r)
-> ((# #) -> r)
-> r
$bHeader :: forall crypto.
Crypto crypto =>
HeaderBody crypto
-> SignedKES (KES crypto) (HeaderBody crypto) -> Header crypto
Header {forall crypto. Crypto crypto => Header crypto -> HeaderBody crypto
headerBody, forall crypto.
Crypto crypto =>
Header crypto -> SignedKES (KES crypto) (HeaderBody crypto)
headerSig} <- (getMemoRawType -> HeaderRaw headerBody headerSig)
  where
    Header HeaderBody crypto
body SignedKES (KES crypto) (HeaderBody crypto)
sig = Version -> RawType (Header crypto) -> Header crypto
forall t.
(EncCBOR (RawType t), Memoized t) =>
Version -> RawType t -> t
mkMemoized (ProtVer -> Version
pvMajor (HeaderBody crypto -> ProtVer
forall crypto. HeaderBody crypto -> ProtVer
hbProtVer HeaderBody crypto
body)) (RawType (Header crypto) -> Header crypto)
-> RawType (Header crypto) -> Header crypto
forall a b. (a -> b) -> a -> b
$ HeaderBody crypto
-> SignedKES (KES crypto) (HeaderBody crypto) -> HeaderRaw crypto
forall crypto.
HeaderBody crypto
-> SignedKES (KES crypto) (HeaderBody crypto) -> HeaderRaw crypto
HeaderRaw HeaderBody crypto
body SignedKES (KES crypto) (HeaderBody crypto)
sig

{-# COMPLETE Header #-}

headerSize :: Header crypto -> Int
headerSize :: forall crypto. Header crypto -> Int
headerSize = Header crypto -> Int
forall t. SafeToHash t => t -> Int
originalBytesSize

headerHash ::
  Header crypto ->
  Hash.Hash HASH EraIndependentBlockHeader
headerHash :: forall crypto. Header crypto -> Hash HASH EraIndependentBlockHeader
headerHash = SafeHash EraIndependentBlockHeader
-> Hash HASH EraIndependentBlockHeader
forall i. SafeHash i -> Hash HASH i
extractHash (SafeHash EraIndependentBlockHeader
 -> Hash HASH EraIndependentBlockHeader)
-> (Header crypto -> SafeHash EraIndependentBlockHeader)
-> Header crypto
-> Hash HASH EraIndependentBlockHeader
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Header crypto -> SafeHash EraIndependentBlockHeader
forall x i. HashAnnotated x i => x -> SafeHash i
hashAnnotated

--------------------------------------------------------------------------------
-- Serialisation
--------------------------------------------------------------------------------

instance Crypto crypto => EncCBOR (HeaderBody crypto) where
  encCBOR :: HeaderBody crypto -> Encoding
encCBOR
    HeaderBody
      { BlockNo
hbBlockNo :: forall crypto. HeaderBody crypto -> BlockNo
hbBlockNo :: BlockNo
hbBlockNo
      , SlotNo
hbSlotNo :: forall crypto. HeaderBody crypto -> SlotNo
hbSlotNo :: SlotNo
hbSlotNo
      , PrevHash
hbPrev :: forall crypto. HeaderBody crypto -> PrevHash
hbPrev :: PrevHash
hbPrev
      , VKey BlockIssuer
hbVk :: forall crypto. HeaderBody crypto -> VKey BlockIssuer
hbVk :: VKey BlockIssuer
hbVk
      , VerKeyVRF (VRF crypto)
hbVrfVk :: forall crypto. HeaderBody crypto -> VerKeyVRF (VRF crypto)
hbVrfVk :: VerKeyVRF (VRF crypto)
hbVrfVk
      , CertifiedVRF (VRF crypto) InputVRF
hbVrfRes :: forall crypto.
HeaderBody crypto -> CertifiedVRF (VRF crypto) InputVRF
hbVrfRes :: CertifiedVRF (VRF crypto) InputVRF
hbVrfRes
      , Word32
hbBodySize :: forall crypto. HeaderBody crypto -> Word32
hbBodySize :: Word32
hbBodySize
      , Hash HASH EraIndependentBlockBody
hbBodyHash :: forall crypto.
HeaderBody crypto -> Hash HASH EraIndependentBlockBody
hbBodyHash :: Hash HASH EraIndependentBlockBody
hbBodyHash
      , OCert crypto
hbOCert :: forall crypto. HeaderBody crypto -> OCert crypto
hbOCert :: OCert crypto
hbOCert
      , ProtVer
hbProtVer :: forall crypto. HeaderBody crypto -> ProtVer
hbProtVer :: ProtVer
hbProtVer
      , Bool
hbBlockBodyContainsLeiosCert :: forall crypto. HeaderBody crypto -> Bool
hbBlockBodyContainsLeiosCert :: Bool
hbBlockBodyContainsLeiosCert
      , StrictMaybe EbAnnouncement
hbEbAnnouncement :: forall crypto. HeaderBody crypto -> StrictMaybe EbAnnouncement
hbEbAnnouncement :: StrictMaybe EbAnnouncement
hbEbAnnouncement
      } =
      Word -> Encoding
encodeListLen Word
12
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> BlockNo -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR BlockNo
hbBlockNo
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> SlotNo -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR SlotNo
hbSlotNo
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> PrevHash -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR PrevHash
hbPrev
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> VKey BlockIssuer -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR VKey BlockIssuer
hbVk
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> VerKeyVRF (VRF crypto) -> Encoding
forall a. FixedSizeCodec a => a -> Encoding
encodeFixedSized VerKeyVRF (VRF crypto)
hbVrfVk
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> CertifiedVRF (VRF crypto) InputVRF -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR CertifiedVRF (VRF crypto) InputVRF
hbVrfRes
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word32 -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR Word32
hbBodySize
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Hash HASH EraIndependentBlockBody -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR Hash HASH EraIndependentBlockBody
hbBodyHash
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> OCert crypto -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR OCert crypto
hbOCert
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> ProtVer -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR ProtVer
hbProtVer
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Bool -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR Bool
hbBlockBodyContainsLeiosCert
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> (EbAnnouncement -> Encoding)
-> StrictMaybe EbAnnouncement -> Encoding
forall a. (a -> Encoding) -> StrictMaybe a -> Encoding
encodeNullStrictMaybe EbAnnouncement -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR StrictMaybe EbAnnouncement
hbEbAnnouncement

instance Crypto crypto => DecCBOR (HeaderBody crypto) where
  decCBOR :: forall s. Decoder s (HeaderBody crypto)
decCBOR =
    Text
-> (HeaderBody crypto -> Int)
-> Decoder s (HeaderBody crypto)
-> Decoder s (HeaderBody crypto)
forall a s. Text -> (a -> Int) -> Decoder s a -> Decoder s a
decodeRecordNamed Text
"HeaderBody" (Int -> HeaderBody crypto -> Int
forall a b. a -> b -> a
const Int
12) (Decoder s (HeaderBody crypto) -> Decoder s (HeaderBody crypto))
-> Decoder s (HeaderBody crypto) -> Decoder s (HeaderBody crypto)
forall a b. (a -> b) -> a -> b
$
      BlockNo
-> SlotNo
-> PrevHash
-> VKey BlockIssuer
-> VerKeyVRF (VRF crypto)
-> CertifiedVRF (VRF crypto) InputVRF
-> Word32
-> Hash HASH EraIndependentBlockBody
-> OCert crypto
-> ProtVer
-> Bool
-> StrictMaybe EbAnnouncement
-> HeaderBody crypto
forall crypto.
BlockNo
-> SlotNo
-> PrevHash
-> VKey BlockIssuer
-> VerKeyVRF (VRF crypto)
-> CertifiedVRF (VRF crypto) InputVRF
-> Word32
-> Hash HASH EraIndependentBlockBody
-> OCert crypto
-> ProtVer
-> Bool
-> StrictMaybe EbAnnouncement
-> HeaderBody crypto
HeaderBody
        (BlockNo
 -> SlotNo
 -> PrevHash
 -> VKey BlockIssuer
 -> VerKeyVRF (VRF crypto)
 -> CertifiedVRF (VRF crypto) InputVRF
 -> Word32
 -> Hash HASH EraIndependentBlockBody
 -> OCert crypto
 -> ProtVer
 -> Bool
 -> StrictMaybe EbAnnouncement
 -> HeaderBody crypto)
-> Decoder s BlockNo
-> Decoder
     s
     (SlotNo
      -> PrevHash
      -> VKey BlockIssuer
      -> VerKeyVRF (VRF crypto)
      -> CertifiedVRF (VRF crypto) InputVRF
      -> Word32
      -> Hash HASH EraIndependentBlockBody
      -> OCert crypto
      -> ProtVer
      -> Bool
      -> StrictMaybe EbAnnouncement
      -> HeaderBody crypto)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s BlockNo
forall s. Decoder s BlockNo
forall a s. DecCBOR a => Decoder s a
decCBOR
        Decoder
  s
  (SlotNo
   -> PrevHash
   -> VKey BlockIssuer
   -> VerKeyVRF (VRF crypto)
   -> CertifiedVRF (VRF crypto) InputVRF
   -> Word32
   -> Hash HASH EraIndependentBlockBody
   -> OCert crypto
   -> ProtVer
   -> Bool
   -> StrictMaybe EbAnnouncement
   -> HeaderBody crypto)
-> Decoder s SlotNo
-> Decoder
     s
     (PrevHash
      -> VKey BlockIssuer
      -> VerKeyVRF (VRF crypto)
      -> CertifiedVRF (VRF crypto) InputVRF
      -> Word32
      -> Hash HASH EraIndependentBlockBody
      -> OCert crypto
      -> ProtVer
      -> Bool
      -> StrictMaybe EbAnnouncement
      -> HeaderBody crypto)
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 SlotNo
forall s. Decoder s SlotNo
forall a s. DecCBOR a => Decoder s a
decCBOR
        Decoder
  s
  (PrevHash
   -> VKey BlockIssuer
   -> VerKeyVRF (VRF crypto)
   -> CertifiedVRF (VRF crypto) InputVRF
   -> Word32
   -> Hash HASH EraIndependentBlockBody
   -> OCert crypto
   -> ProtVer
   -> Bool
   -> StrictMaybe EbAnnouncement
   -> HeaderBody crypto)
-> Decoder s PrevHash
-> Decoder
     s
     (VKey BlockIssuer
      -> VerKeyVRF (VRF crypto)
      -> CertifiedVRF (VRF crypto) InputVRF
      -> Word32
      -> Hash HASH EraIndependentBlockBody
      -> OCert crypto
      -> ProtVer
      -> Bool
      -> StrictMaybe EbAnnouncement
      -> HeaderBody crypto)
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 PrevHash
forall s. Decoder s PrevHash
forall a s. DecCBOR a => Decoder s a
decCBOR
        Decoder
  s
  (VKey BlockIssuer
   -> VerKeyVRF (VRF crypto)
   -> CertifiedVRF (VRF crypto) InputVRF
   -> Word32
   -> Hash HASH EraIndependentBlockBody
   -> OCert crypto
   -> ProtVer
   -> Bool
   -> StrictMaybe EbAnnouncement
   -> HeaderBody crypto)
-> Decoder s (VKey BlockIssuer)
-> Decoder
     s
     (VerKeyVRF (VRF crypto)
      -> CertifiedVRF (VRF crypto) InputVRF
      -> Word32
      -> Hash HASH EraIndependentBlockBody
      -> OCert crypto
      -> ProtVer
      -> Bool
      -> StrictMaybe EbAnnouncement
      -> HeaderBody crypto)
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 (VKey BlockIssuer)
forall s. Decoder s (VKey BlockIssuer)
forall a s. DecCBOR a => Decoder s a
decCBOR
        Decoder
  s
  (VerKeyVRF (VRF crypto)
   -> CertifiedVRF (VRF crypto) InputVRF
   -> Word32
   -> Hash HASH EraIndependentBlockBody
   -> OCert crypto
   -> ProtVer
   -> Bool
   -> StrictMaybe EbAnnouncement
   -> HeaderBody crypto)
-> Decoder s (VerKeyVRF (VRF crypto))
-> Decoder
     s
     (CertifiedVRF (VRF crypto) InputVRF
      -> Word32
      -> Hash HASH EraIndependentBlockBody
      -> OCert crypto
      -> ProtVer
      -> Bool
      -> StrictMaybe EbAnnouncement
      -> HeaderBody crypto)
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 (VerKeyVRF (VRF crypto))
forall a s. FixedSizeCodec a => Decoder s a
decodeFixedSized
        Decoder
  s
  (CertifiedVRF (VRF crypto) InputVRF
   -> Word32
   -> Hash HASH EraIndependentBlockBody
   -> OCert crypto
   -> ProtVer
   -> Bool
   -> StrictMaybe EbAnnouncement
   -> HeaderBody crypto)
-> Decoder s (CertifiedVRF (VRF crypto) InputVRF)
-> Decoder
     s
     (Word32
      -> Hash HASH EraIndependentBlockBody
      -> OCert crypto
      -> ProtVer
      -> Bool
      -> StrictMaybe EbAnnouncement
      -> HeaderBody crypto)
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 (CertifiedVRF (VRF crypto) InputVRF)
forall s. Decoder s (CertifiedVRF (VRF crypto) InputVRF)
forall a s. DecCBOR a => Decoder s a
decCBOR
        Decoder
  s
  (Word32
   -> Hash HASH EraIndependentBlockBody
   -> OCert crypto
   -> ProtVer
   -> Bool
   -> StrictMaybe EbAnnouncement
   -> HeaderBody crypto)
-> Decoder s Word32
-> Decoder
     s
     (Hash HASH EraIndependentBlockBody
      -> OCert crypto
      -> ProtVer
      -> Bool
      -> StrictMaybe EbAnnouncement
      -> HeaderBody crypto)
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 Word32
forall s. Decoder s Word32
forall a s. DecCBOR a => Decoder s a
decCBOR
        Decoder
  s
  (Hash HASH EraIndependentBlockBody
   -> OCert crypto
   -> ProtVer
   -> Bool
   -> StrictMaybe EbAnnouncement
   -> HeaderBody crypto)
-> Decoder s (Hash HASH EraIndependentBlockBody)
-> Decoder
     s
     (OCert crypto
      -> ProtVer
      -> Bool
      -> StrictMaybe EbAnnouncement
      -> HeaderBody crypto)
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 (Hash HASH EraIndependentBlockBody)
forall s. Decoder s (Hash HASH EraIndependentBlockBody)
forall a s. DecCBOR a => Decoder s a
decCBOR
        Decoder
  s
  (OCert crypto
   -> ProtVer
   -> Bool
   -> StrictMaybe EbAnnouncement
   -> HeaderBody crypto)
-> Decoder s (OCert crypto)
-> Decoder
     s
     (ProtVer
      -> Bool -> StrictMaybe EbAnnouncement -> HeaderBody crypto)
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
<*> (CBORGroup (OCert crypto) -> OCert crypto
forall a. CBORGroup a -> a
unCBORGroup (CBORGroup (OCert crypto) -> OCert crypto)
-> Decoder s (CBORGroup (OCert crypto)) -> Decoder s (OCert crypto)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s (CBORGroup (OCert crypto))
forall s. Decoder s (CBORGroup (OCert crypto))
forall a s. DecCBOR a => Decoder s a
decCBOR)
        Decoder
  s
  (ProtVer
   -> Bool -> StrictMaybe EbAnnouncement -> HeaderBody crypto)
-> Decoder s ProtVer
-> Decoder
     s (Bool -> StrictMaybe EbAnnouncement -> HeaderBody crypto)
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 ProtVer
forall s. Decoder s ProtVer
forall a s. DecCBOR a => Decoder s a
decCBOR
        Decoder s (Bool -> StrictMaybe EbAnnouncement -> HeaderBody crypto)
-> Decoder s Bool
-> Decoder s (StrictMaybe EbAnnouncement -> HeaderBody crypto)
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 Bool
forall s. Decoder s Bool
forall a s. DecCBOR a => Decoder s a
decCBOR
        Decoder s (StrictMaybe EbAnnouncement -> HeaderBody crypto)
-> Decoder s (StrictMaybe EbAnnouncement)
-> Decoder s (HeaderBody crypto)
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 EbAnnouncement -> Decoder s (StrictMaybe EbAnnouncement)
forall s a. Decoder s a -> Decoder s (StrictMaybe a)
decodeNullStrictMaybe Decoder s EbAnnouncement
forall s. Decoder s EbAnnouncement
forall a s. DecCBOR a => Decoder s a
decCBOR

instance Crypto crypto => EncCBOR (HeaderRaw crypto) where
  encCBOR :: HeaderRaw crypto -> Encoding
encCBOR (HeaderRaw HeaderBody crypto
body SignedKES (KES crypto) (HeaderBody crypto)
sig) =
    Word -> Encoding
encodeListLen Word
2 Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> HeaderBody crypto -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR HeaderBody crypto
body Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> SignedKES (KES crypto) (HeaderBody crypto) -> Encoding
forall a. FixedSizeCodec a => a -> Encoding
encodeFixedSized SignedKES (KES crypto) (HeaderBody crypto)
sig

instance Crypto crypto => DecCBOR (HeaderRaw crypto) where
  decCBOR :: forall s. Decoder s (HeaderRaw crypto)
decCBOR =
    Text
-> (HeaderRaw crypto -> Int)
-> Decoder s (HeaderRaw crypto)
-> Decoder s (HeaderRaw crypto)
forall a s. Text -> (a -> Int) -> Decoder s a -> Decoder s a
decodeRecordNamed Text
"HeaderRaw" (Int -> HeaderRaw crypto -> Int
forall a b. a -> b -> a
const Int
2) (Decoder s (HeaderRaw crypto) -> Decoder s (HeaderRaw crypto))
-> Decoder s (HeaderRaw crypto) -> Decoder s (HeaderRaw crypto)
forall a b. (a -> b) -> a -> b
$
      HeaderBody crypto
-> SignedKES (KES crypto) (HeaderBody crypto) -> HeaderRaw crypto
forall crypto.
HeaderBody crypto
-> SignedKES (KES crypto) (HeaderBody crypto) -> HeaderRaw crypto
HeaderRaw (HeaderBody crypto
 -> SignedKES (KES crypto) (HeaderBody crypto) -> HeaderRaw crypto)
-> Decoder s (HeaderBody crypto)
-> Decoder
     s (SignedKES (KES crypto) (HeaderBody crypto) -> HeaderRaw crypto)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s (HeaderBody crypto)
forall s. Decoder s (HeaderBody crypto)
forall a s. DecCBOR a => Decoder s a
decCBOR Decoder
  s (SignedKES (KES crypto) (HeaderBody crypto) -> HeaderRaw crypto)
-> Decoder s (SignedKES (KES crypto) (HeaderBody crypto))
-> Decoder s (HeaderRaw crypto)
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 (SignedKES (KES crypto) (HeaderBody crypto))
forall a s. FixedSizeCodec a => Decoder s a
decodeFixedSized

instance Crypto crypto => DecCBOR (Annotator (HeaderRaw crypto)) where
  decCBOR :: forall s. Decoder s (Annotator (HeaderRaw crypto))
decCBOR = HeaderRaw crypto -> Annotator (HeaderRaw crypto)
forall a. a -> Annotator a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (HeaderRaw crypto -> Annotator (HeaderRaw crypto))
-> Decoder s (HeaderRaw crypto)
-> Decoder s (Annotator (HeaderRaw crypto))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s (HeaderRaw crypto)
forall s. Decoder s (HeaderRaw crypto)
forall a s. DecCBOR a => Decoder s a
decCBOR

instance Crypto c => EncCBOR (Header c)

deriving via
  Mem (HeaderRaw c)
  instance
    Crypto c => DecCBOR (Annotator (Header c))

instance (Crypto c, Era era) => EraBlockHeader (Header c) era where
  blockIssuerBlockHeaderG :: SimpleGetter (Block (Header c) era) (KeyHash BlockIssuer)
blockIssuerBlockHeaderG =
    (Block (Header c) era -> KeyHash BlockIssuer)
-> SimpleGetter (Block (Header c) era) (KeyHash BlockIssuer)
forall s a. (s -> a) -> SimpleGetter s a
to (\(Block (Header HeaderBody c
hb SignedKES (KES c) (HeaderBody c)
_) BlockBody era
_) -> VKey BlockIssuer -> KeyHash BlockIssuer
forall (kd :: KeyRole). VKey kd -> KeyHash kd
hashKey (HeaderBody c -> VKey BlockIssuer
forall crypto. HeaderBody crypto -> VKey BlockIssuer
hbVk HeaderBody c
hb))
  blockHeaderSizeBlockHeaderG :: SimpleGetter (Block (Header c) era) Int
blockHeaderSizeBlockHeaderG =
    (Block (Header c) era -> Int)
-> SimpleGetter (Block (Header c) era) Int
forall s a. (s -> a) -> SimpleGetter s a
to (\(Block Header c
hdr BlockBody era
_) -> Header c -> Int
forall t. SafeToHash t => t -> Int
originalBytesSize Header c
hdr)
  blockBodySizeBlockHeaderL :: Lens' (Block (Header c) era) Word32
blockBodySizeBlockHeaderL =
    (Block (Header c) era -> Word32)
-> (Block (Header c) era -> Word32 -> Block (Header c) era)
-> Lens' (Block (Header c) era) Word32
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens
      (\(Block (Header HeaderBody c
hb SignedKES (KES c) (HeaderBody c)
_) BlockBody era
_) -> HeaderBody c -> Word32
forall crypto. HeaderBody crypto -> Word32
hbBodySize HeaderBody c
hb)
      ( \(Block (Header HeaderBody c
hb SignedKES (KES c) (HeaderBody c)
sig) BlockBody era
body) Word32
sz ->
          Header c -> BlockBody era -> Block (Header c) era
forall h era. h -> BlockBody era -> Block h era
Block (HeaderBody c -> SignedKES (KES c) (HeaderBody c) -> Header c
forall crypto.
Crypto crypto =>
HeaderBody crypto
-> SignedKES (KES crypto) (HeaderBody crypto) -> Header crypto
Header HeaderBody c
hb {hbBodySize = sz} SignedKES (KES c) (HeaderBody c)
sig) BlockBody era
body
      )
  blockBodyHashBlockHeaderL :: Lens' (Block (Header c) era) (Hash HASH EraIndependentBlockBody)
blockBodyHashBlockHeaderL =
    (Block (Header c) era -> Hash HASH EraIndependentBlockBody)
-> (Block (Header c) era
    -> Hash HASH EraIndependentBlockBody -> Block (Header c) era)
-> Lens' (Block (Header c) era) (Hash HASH EraIndependentBlockBody)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens
      (\(Block (Header HeaderBody c
hb SignedKES (KES c) (HeaderBody c)
_) BlockBody era
_) -> HeaderBody c -> Hash HASH EraIndependentBlockBody
forall crypto.
HeaderBody crypto -> Hash HASH EraIndependentBlockBody
hbBodyHash HeaderBody c
hb)
      ( \(Block (Header HeaderBody c
hb SignedKES (KES c) (HeaderBody c)
sig) BlockBody era
body) Hash HASH EraIndependentBlockBody
h ->
          Header c -> BlockBody era -> Block (Header c) era
forall h era. h -> BlockBody era -> Block h era
Block (HeaderBody c -> SignedKES (KES c) (HeaderBody c) -> Header c
forall crypto.
Crypto crypto =>
HeaderBody crypto
-> SignedKES (KES crypto) (HeaderBody crypto) -> Header crypto
Header HeaderBody c
hb {hbBodyHash = h} SignedKES (KES c) (HeaderBody c)
sig) BlockBody era
body
      )
  slotNoBlockHeaderL :: Lens' (Block (Header c) era) SlotNo
slotNoBlockHeaderL =
    (Block (Header c) era -> SlotNo)
-> (Block (Header c) era -> SlotNo -> Block (Header c) era)
-> Lens' (Block (Header c) era) SlotNo
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens
      (\(Block (Header HeaderBody c
hb SignedKES (KES c) (HeaderBody c)
_) BlockBody era
_) -> HeaderBody c -> SlotNo
forall crypto. HeaderBody crypto -> SlotNo
hbSlotNo HeaderBody c
hb)
      ( \(Block (Header HeaderBody c
hb SignedKES (KES c) (HeaderBody c)
sig) BlockBody era
body) SlotNo
s ->
          Header c -> BlockBody era -> Block (Header c) era
forall h era. h -> BlockBody era -> Block h era
Block (HeaderBody c -> SignedKES (KES c) (HeaderBody c) -> Header c
forall crypto.
Crypto crypto =>
HeaderBody crypto
-> SignedKES (KES crypto) (HeaderBody crypto) -> Header crypto
Header HeaderBody c
hb {hbSlotNo = s} SignedKES (KES c) (HeaderBody c)
sig) BlockBody era
body
      )
  protVerBlockHeaderL :: Lens' (Block (Header c) era) ProtVer
protVerBlockHeaderL =
    (Block (Header c) era -> ProtVer)
-> (Block (Header c) era -> ProtVer -> Block (Header c) era)
-> Lens' (Block (Header c) era) ProtVer
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens
      (\(Block (Header HeaderBody c
hb SignedKES (KES c) (HeaderBody c)
_) BlockBody era
_) -> HeaderBody c -> ProtVer
forall crypto. HeaderBody crypto -> ProtVer
hbProtVer HeaderBody c
hb)
      ( \(Block (Header HeaderBody c
hb SignedKES (KES c) (HeaderBody c)
sig) BlockBody era
body) ProtVer
pv ->
          Header c -> BlockBody era -> Block (Header c) era
forall h era. h -> BlockBody era -> Block h era
Block (HeaderBody c -> SignedKES (KES c) (HeaderBody c) -> Header c
forall crypto.
Crypto crypto =>
HeaderBody crypto
-> SignedKES (KES crypto) (HeaderBody crypto) -> Header crypto
Header HeaderBody c
hb {hbProtVer = pv} SignedKES (KES c) (HeaderBody c)
sig) BlockBody era
body
      )