{-# LANGUAGE DataKinds #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Cardano.Ledger.BHeaderView where
import Cardano.Ledger.BaseTypes (BoundedRational (..), UnitInterval)
import Cardano.Ledger.Hashes (EraIndependentBlockBody)
import Cardano.Ledger.Keys (Hash, KeyHash, KeyRole (..))
import Cardano.Ledger.Slot (SlotNo (..), (-*))
import Data.Word (Word32)
data c =
{ forall c. BHeaderView c -> KeyHash 'BlockIssuer c
bhviewID :: KeyHash 'BlockIssuer c
, forall c. BHeaderView c -> Word32
bhviewBSize :: Word32
, forall c. BHeaderView c -> Int
bhviewHSize :: Int
, forall c. BHeaderView c -> Hash c EraIndependentBlockBody
bhviewBHash :: Hash c EraIndependentBlockBody
, forall c. BHeaderView c -> SlotNo
bhviewSlot :: SlotNo
}
isOverlaySlot ::
SlotNo ->
UnitInterval ->
SlotNo ->
Bool
isOverlaySlot :: SlotNo -> UnitInterval -> SlotNo -> Bool
isOverlaySlot SlotNo
firstSlotNo UnitInterval
dval SlotNo
slot = Rational -> Integer
step Rational
s forall a. Ord a => a -> a -> Bool
< Rational -> Integer
step (Rational
s forall a. Num a => a -> a -> a
+ Rational
1)
where
s :: Rational
s = forall a b. (Integral a, Num b) => a -> b
fromIntegral forall a b. (a -> b) -> a -> b
$ SlotNo
slot SlotNo -> SlotNo -> Duration
-* SlotNo
firstSlotNo
d :: Rational
d = forall r. BoundedRational r => r -> Rational
unboundRational UnitInterval
dval
step :: Rational -> Integer
step :: Rational -> Integer
step Rational
x = forall a b. (RealFrac a, Integral b) => a -> b
ceiling (Rational
x forall a. Num a => a -> a -> a
* Rational
d)