{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Cardano.Chain.Slotting.EpochSlots (
EpochSlots (..),
WithEpochSlots (..),
epochFirstSlot,
) where
import Cardano.Chain.Slotting.EpochNumber
import Cardano.Chain.Slotting.SlotNumber
import Cardano.Ledger.Binary (
DecCBOR (..),
EncCBOR (..),
FromCBOR (..),
ToCBOR (..),
fromByronCBOR,
toByronCBOR,
)
import Cardano.Prelude
import Data.Data (Data)
import Formatting.Buildable (Buildable)
import NoThunks.Class (NoThunks (..))
newtype EpochSlots = EpochSlots
{ EpochSlots -> Word64
unEpochSlots :: Word64
}
deriving (Typeable EpochSlots
Typeable EpochSlots =>
(forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> EpochSlots -> c EpochSlots)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c EpochSlots)
-> (EpochSlots -> Constr)
-> (EpochSlots -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c EpochSlots))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c EpochSlots))
-> ((forall b. Data b => b -> b) -> EpochSlots -> EpochSlots)
-> (forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> EpochSlots -> r)
-> (forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> EpochSlots -> r)
-> (forall u. (forall d. Data d => d -> u) -> EpochSlots -> [u])
-> (forall u.
Int -> (forall d. Data d => d -> u) -> EpochSlots -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> EpochSlots -> m EpochSlots)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> EpochSlots -> m EpochSlots)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> EpochSlots -> m EpochSlots)
-> Data EpochSlots
EpochSlots -> Constr
EpochSlots -> DataType
(forall b. Data b => b -> b) -> EpochSlots -> EpochSlots
forall a.
Typeable a =>
(forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> EpochSlots -> u
forall u. (forall d. Data d => d -> u) -> EpochSlots -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> EpochSlots -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> EpochSlots -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> EpochSlots -> m EpochSlots
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> EpochSlots -> m EpochSlots
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c EpochSlots
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> EpochSlots -> c EpochSlots
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c EpochSlots)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c EpochSlots)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> EpochSlots -> c EpochSlots
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> EpochSlots -> c EpochSlots
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c EpochSlots
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c EpochSlots
$ctoConstr :: EpochSlots -> Constr
toConstr :: EpochSlots -> Constr
$cdataTypeOf :: EpochSlots -> DataType
dataTypeOf :: EpochSlots -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c EpochSlots)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c EpochSlots)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c EpochSlots)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c EpochSlots)
$cgmapT :: (forall b. Data b => b -> b) -> EpochSlots -> EpochSlots
gmapT :: (forall b. Data b => b -> b) -> EpochSlots -> EpochSlots
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> EpochSlots -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> EpochSlots -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> EpochSlots -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> EpochSlots -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> EpochSlots -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> EpochSlots -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> EpochSlots -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> EpochSlots -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> EpochSlots -> m EpochSlots
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> EpochSlots -> m EpochSlots
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> EpochSlots -> m EpochSlots
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> EpochSlots -> m EpochSlots
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> EpochSlots -> m EpochSlots
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> EpochSlots -> m EpochSlots
Data, EpochSlots -> EpochSlots -> Bool
(EpochSlots -> EpochSlots -> Bool)
-> (EpochSlots -> EpochSlots -> Bool) -> Eq EpochSlots
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EpochSlots -> EpochSlots -> Bool
== :: EpochSlots -> EpochSlots -> Bool
$c/= :: EpochSlots -> EpochSlots -> Bool
/= :: EpochSlots -> EpochSlots -> Bool
Eq, Eq EpochSlots
Eq EpochSlots =>
(EpochSlots -> EpochSlots -> Ordering)
-> (EpochSlots -> EpochSlots -> Bool)
-> (EpochSlots -> EpochSlots -> Bool)
-> (EpochSlots -> EpochSlots -> Bool)
-> (EpochSlots -> EpochSlots -> Bool)
-> (EpochSlots -> EpochSlots -> EpochSlots)
-> (EpochSlots -> EpochSlots -> EpochSlots)
-> Ord EpochSlots
EpochSlots -> EpochSlots -> Bool
EpochSlots -> EpochSlots -> Ordering
EpochSlots -> EpochSlots -> EpochSlots
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: EpochSlots -> EpochSlots -> Ordering
compare :: EpochSlots -> EpochSlots -> Ordering
$c< :: EpochSlots -> EpochSlots -> Bool
< :: EpochSlots -> EpochSlots -> Bool
$c<= :: EpochSlots -> EpochSlots -> Bool
<= :: EpochSlots -> EpochSlots -> Bool
$c> :: EpochSlots -> EpochSlots -> Bool
> :: EpochSlots -> EpochSlots -> Bool
$c>= :: EpochSlots -> EpochSlots -> Bool
>= :: EpochSlots -> EpochSlots -> Bool
$cmax :: EpochSlots -> EpochSlots -> EpochSlots
max :: EpochSlots -> EpochSlots -> EpochSlots
$cmin :: EpochSlots -> EpochSlots -> EpochSlots
min :: EpochSlots -> EpochSlots -> EpochSlots
Ord, ReadPrec [EpochSlots]
ReadPrec EpochSlots
Int -> ReadS EpochSlots
ReadS [EpochSlots]
(Int -> ReadS EpochSlots)
-> ReadS [EpochSlots]
-> ReadPrec EpochSlots
-> ReadPrec [EpochSlots]
-> Read EpochSlots
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS EpochSlots
readsPrec :: Int -> ReadS EpochSlots
$creadList :: ReadS [EpochSlots]
readList :: ReadS [EpochSlots]
$creadPrec :: ReadPrec EpochSlots
readPrec :: ReadPrec EpochSlots
$creadListPrec :: ReadPrec [EpochSlots]
readListPrec :: ReadPrec [EpochSlots]
Read, Int -> EpochSlots -> ShowS
[EpochSlots] -> ShowS
EpochSlots -> String
(Int -> EpochSlots -> ShowS)
-> (EpochSlots -> String)
-> ([EpochSlots] -> ShowS)
-> Show EpochSlots
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> EpochSlots -> ShowS
showsPrec :: Int -> EpochSlots -> ShowS
$cshow :: EpochSlots -> String
show :: EpochSlots -> String
$cshowList :: [EpochSlots] -> ShowS
showList :: [EpochSlots] -> ShowS
Show, EpochSlots -> Builder
(EpochSlots -> Builder) -> Buildable EpochSlots
forall p. (p -> Builder) -> Buildable p
$cbuild :: EpochSlots -> Builder
build :: EpochSlots -> Builder
Buildable, (forall x. EpochSlots -> Rep EpochSlots x)
-> (forall x. Rep EpochSlots x -> EpochSlots) -> Generic EpochSlots
forall x. Rep EpochSlots x -> EpochSlots
forall x. EpochSlots -> Rep EpochSlots x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. EpochSlots -> Rep EpochSlots x
from :: forall x. EpochSlots -> Rep EpochSlots x
$cto :: forall x. Rep EpochSlots x -> EpochSlots
to :: forall x. Rep EpochSlots x -> EpochSlots
Generic, Context -> EpochSlots -> IO (Maybe ThunkInfo)
Proxy EpochSlots -> String
(Context -> EpochSlots -> IO (Maybe ThunkInfo))
-> (Context -> EpochSlots -> IO (Maybe ThunkInfo))
-> (Proxy EpochSlots -> String)
-> NoThunks EpochSlots
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
$cnoThunks :: Context -> EpochSlots -> IO (Maybe ThunkInfo)
noThunks :: Context -> EpochSlots -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> EpochSlots -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> EpochSlots -> IO (Maybe ThunkInfo)
$cshowTypeOf :: Proxy EpochSlots -> String
showTypeOf :: Proxy EpochSlots -> String
NoThunks)
instance ToCBOR EpochSlots where
toCBOR :: EpochSlots -> Encoding
toCBOR = EpochSlots -> Encoding
forall a. EncCBOR a => a -> Encoding
toByronCBOR
instance FromCBOR EpochSlots where
fromCBOR :: forall s. Decoder s EpochSlots
fromCBOR = Decoder s EpochSlots
forall a s. DecCBOR a => Decoder s a
fromByronCBOR
instance EncCBOR EpochSlots where
encCBOR :: EpochSlots -> Encoding
encCBOR = Word64 -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR (Word64 -> Encoding)
-> (EpochSlots -> Word64) -> EpochSlots -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. EpochSlots -> Word64
unEpochSlots
instance DecCBOR EpochSlots where
decCBOR :: forall s. Decoder s EpochSlots
decCBOR = Word64 -> EpochSlots
EpochSlots (Word64 -> EpochSlots) -> Decoder s Word64 -> Decoder s EpochSlots
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word64
forall s. Decoder s Word64
forall a s. DecCBOR a => Decoder s a
decCBOR
data WithEpochSlots a = WithEpochSlots
{ forall a. WithEpochSlots a -> EpochSlots
epochSlots :: EpochSlots
, forall a. WithEpochSlots a -> a
unWithEpochSlots :: a
}
deriving (Int -> WithEpochSlots a -> ShowS
[WithEpochSlots a] -> ShowS
WithEpochSlots a -> String
(Int -> WithEpochSlots a -> ShowS)
-> (WithEpochSlots a -> String)
-> ([WithEpochSlots a] -> ShowS)
-> Show (WithEpochSlots a)
forall a. Show a => Int -> WithEpochSlots a -> ShowS
forall a. Show a => [WithEpochSlots a] -> ShowS
forall a. Show a => WithEpochSlots a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> WithEpochSlots a -> ShowS
showsPrec :: Int -> WithEpochSlots a -> ShowS
$cshow :: forall a. Show a => WithEpochSlots a -> String
show :: WithEpochSlots a -> String
$cshowList :: forall a. Show a => [WithEpochSlots a] -> ShowS
showList :: [WithEpochSlots a] -> ShowS
Show, WithEpochSlots a -> WithEpochSlots a -> Bool
(WithEpochSlots a -> WithEpochSlots a -> Bool)
-> (WithEpochSlots a -> WithEpochSlots a -> Bool)
-> Eq (WithEpochSlots a)
forall a. Eq a => WithEpochSlots a -> WithEpochSlots a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => WithEpochSlots a -> WithEpochSlots a -> Bool
== :: WithEpochSlots a -> WithEpochSlots a -> Bool
$c/= :: forall a. Eq a => WithEpochSlots a -> WithEpochSlots a -> Bool
/= :: WithEpochSlots a -> WithEpochSlots a -> Bool
Eq)
epochFirstSlot :: EpochSlots -> EpochNumber -> SlotNumber
epochFirstSlot :: EpochSlots -> EpochNumber -> SlotNumber
epochFirstSlot (EpochSlots Word64
n) (EpochNumber Word64
k) = Word64 -> SlotNumber
SlotNumber (Word64 -> SlotNumber) -> Word64 -> SlotNumber
forall a b. (a -> b) -> a -> b
$ Word64
n Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
* Word64
k