Skip to content

Commit

Permalink
[core] - BHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
teodanciu committed Jan 24, 2025
1 parent 4e7da4e commit 1c1c2a6
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ import Cardano.Ledger.Hashes (
hashKey,
)
import Cardano.Ledger.Keys (VKey)
import Cardano.Ledger.MemoBytes (MemoBytes (Memo), decodeMemoized)
import Cardano.Ledger.NonIntegral (CompareResult (..), taylorExpCmp)
import Cardano.Ledger.Slot (BlockNo (..), SlotNo (..))
import Cardano.Protocol.Crypto
Expand All @@ -98,6 +99,7 @@ import qualified Data.ByteString as BS
import qualified Data.ByteString.Builder as BS
import qualified Data.ByteString.Builder.Extra as BS
import qualified Data.ByteString.Lazy as BSL
import qualified Data.ByteString.Short as SBS
import Data.Ratio ((%))
import Data.Typeable
import Data.Word (Word32, Word64)
Expand Down Expand Up @@ -291,6 +293,20 @@ instance Crypto c => DecCBOR (Annotator (BHeader c)) where
sig <- decodeSignedKES
pure $ pure $ BHeader' bhb sig . BSL.toStrict

data BHeaderRaw c = BHeaderRaw !(BHBody c) !(KES.SignedKES (KES c) (BHBody c))

instance Crypto c => DecCBOR (BHeaderRaw c) where
decCBOR = decodeRecordNamed "Header" (const 2) $ do
bhb <- decCBOR
sig <- decodeSignedKES
pure $ BHeaderRaw bhb sig

instance Crypto c => DecCBOR (BHeader c) where
decCBOR = do
mb <- decodeMemoized decCBOR
let (Memo (BHeaderRaw bhb sig) bs) = mb
pure $ BHeader' bhb sig (SBS.fromShort bs)

-- | Hash a given block header
bhHash :: Crypto c => BHeader c -> HashHeader
bhHash bh = HashHeader . Hash.castHash . hashEncCBOR version $ bh
Expand Down

0 comments on commit 1c1c2a6

Please sign in to comment.