{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

module Cardano.Chain.Common.BlockCount (
  BlockCount (..),
)
where

import Cardano.Ledger.Binary (
  DecCBOR (..),
  EncCBOR (..),
  FromCBOR (..),
  ToCBOR (..),
  fromByronCBOR,
  toByronCBOR,
 )
import Cardano.Prelude
import Formatting.Buildable (Buildable)
import NoThunks.Class (NoThunks (..))

newtype BlockCount = BlockCount
  { BlockCount -> Word64
unBlockCount :: Word64
  }
  deriving (BlockCount -> BlockCount -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BlockCount -> BlockCount -> Bool
$c/= :: BlockCount -> BlockCount -> Bool
== :: BlockCount -> BlockCount -> Bool
$c== :: BlockCount -> BlockCount -> Bool
Eq, Eq BlockCount
BlockCount -> BlockCount -> Bool
BlockCount -> BlockCount -> Ordering
BlockCount -> BlockCount -> BlockCount
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
min :: BlockCount -> BlockCount -> BlockCount
$cmin :: BlockCount -> BlockCount -> BlockCount
max :: BlockCount -> BlockCount -> BlockCount
$cmax :: BlockCount -> BlockCount -> BlockCount
>= :: BlockCount -> BlockCount -> Bool
$c>= :: BlockCount -> BlockCount -> Bool
> :: BlockCount -> BlockCount -> Bool
$c> :: BlockCount -> BlockCount -> Bool
<= :: BlockCount -> BlockCount -> Bool
$c<= :: BlockCount -> BlockCount -> Bool
< :: BlockCount -> BlockCount -> Bool
$c< :: BlockCount -> BlockCount -> Bool
compare :: BlockCount -> BlockCount -> Ordering
$ccompare :: BlockCount -> BlockCount -> Ordering
Ord, Int -> BlockCount
BlockCount -> Int
BlockCount -> [BlockCount]
BlockCount -> BlockCount
BlockCount -> BlockCount -> [BlockCount]
BlockCount -> BlockCount -> BlockCount -> [BlockCount]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: BlockCount -> BlockCount -> BlockCount -> [BlockCount]
$cenumFromThenTo :: BlockCount -> BlockCount -> BlockCount -> [BlockCount]
enumFromTo :: BlockCount -> BlockCount -> [BlockCount]
$cenumFromTo :: BlockCount -> BlockCount -> [BlockCount]
enumFromThen :: BlockCount -> BlockCount -> [BlockCount]
$cenumFromThen :: BlockCount -> BlockCount -> [BlockCount]
enumFrom :: BlockCount -> [BlockCount]
$cenumFrom :: BlockCount -> [BlockCount]
fromEnum :: BlockCount -> Int
$cfromEnum :: BlockCount -> Int
toEnum :: Int -> BlockCount
$ctoEnum :: Int -> BlockCount
pred :: BlockCount -> BlockCount
$cpred :: BlockCount -> BlockCount
succ :: BlockCount -> BlockCount
$csucc :: BlockCount -> BlockCount
Enum, ReadPrec [BlockCount]
ReadPrec BlockCount
Int -> ReadS BlockCount
ReadS [BlockCount]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BlockCount]
$creadListPrec :: ReadPrec [BlockCount]
readPrec :: ReadPrec BlockCount
$creadPrec :: ReadPrec BlockCount
readList :: ReadS [BlockCount]
$creadList :: ReadS [BlockCount]
readsPrec :: Int -> ReadS BlockCount
$creadsPrec :: Int -> ReadS BlockCount
Read, Int -> BlockCount -> ShowS
[BlockCount] -> ShowS
BlockCount -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BlockCount] -> ShowS
$cshowList :: [BlockCount] -> ShowS
show :: BlockCount -> String
$cshow :: BlockCount -> String
showsPrec :: Int -> BlockCount -> ShowS
$cshowsPrec :: Int -> BlockCount -> ShowS
Show, BlockCount -> Builder
forall p. (p -> Builder) -> Buildable p
build :: BlockCount -> Builder
$cbuild :: BlockCount -> Builder
Buildable, forall x. Rep BlockCount x -> BlockCount
forall x. BlockCount -> Rep BlockCount x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BlockCount x -> BlockCount
$cfrom :: forall x. BlockCount -> Rep BlockCount x
Generic, BlockCount -> ()
forall a. (a -> ()) -> NFData a
rnf :: BlockCount -> ()
$crnf :: BlockCount -> ()
NFData, Context -> BlockCount -> IO (Maybe ThunkInfo)
Proxy BlockCount -> String
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
showTypeOf :: Proxy BlockCount -> String
$cshowTypeOf :: Proxy BlockCount -> String
wNoThunks :: Context -> BlockCount -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> BlockCount -> IO (Maybe ThunkInfo)
noThunks :: Context -> BlockCount -> IO (Maybe ThunkInfo)
$cnoThunks :: Context -> BlockCount -> IO (Maybe ThunkInfo)
NoThunks)

instance ToCBOR BlockCount where
  toCBOR :: BlockCount -> Encoding
toCBOR = forall a. EncCBOR a => a -> Encoding
toByronCBOR

instance FromCBOR BlockCount where
  fromCBOR :: forall s. Decoder s BlockCount
fromCBOR = forall a s. DecCBOR a => Decoder s a
fromByronCBOR

instance EncCBOR BlockCount where
  encCBOR :: BlockCount -> Encoding
encCBOR = forall a. EncCBOR a => a -> Encoding
encCBOR forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. BlockCount -> Word64
unBlockCount
  encodedSizeExpr :: (forall t. EncCBOR t => Proxy t -> Size)
-> Proxy BlockCount -> Size
encodedSizeExpr forall t. EncCBOR t => Proxy t -> Size
size Proxy BlockCount
pxy = forall t. EncCBOR t => Proxy t -> Size
size (BlockCount -> Word64
unBlockCount forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Proxy BlockCount
pxy)

instance DecCBOR BlockCount where
  decCBOR :: forall s. Decoder s BlockCount
decCBOR = Word64 -> BlockCount
BlockCount forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a s. DecCBOR a => Decoder s a
decCBOR