-
Notifications
You must be signed in to change notification settings - Fork 40
/
Block.hs
32 lines (27 loc) · 973 Bytes
/
Block.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Cardano.Slotting.Block
( BlockNo (..)
)
where
import Cardano.Binary (FromCBOR (..), ToCBOR (..))
import Codec.Serialise (Serialise (..))
import Control.DeepSeq (NFData)
import Data.Aeson (ToJSON, FromJSON)
import Data.Word (Word64)
import GHC.Generics (Generic)
import NoThunks.Class (NoThunks)
import Quiet (Quiet (..))
-- | The 0-based index of the block in the blockchain.
-- BlockNo is <= SlotNo and is only equal at slot N if there is a block
-- for every slot where N <= SlotNo.
newtype BlockNo = BlockNo {unBlockNo :: Word64}
deriving stock (Eq, Ord, Generic)
deriving Show via Quiet BlockNo
deriving newtype (Enum, Bounded, Num, Serialise, NoThunks, NFData, ToJSON, FromJSON)
instance ToCBOR BlockNo where
toCBOR = encode
encodedSizeExpr size = encodedSizeExpr size . fmap unBlockNo
instance FromCBOR BlockNo where
fromCBOR = decode