{-# LANGUAGE FlexibleContexts           #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE RecordWildCards            #-}
{-# LANGUAGE TypeFamilies               #-}

module Ouroboros.Consensus.Node.ProtocolInfo (
    NumCoreNodes (..)
  , ProtocolClientInfo (..)
  , ProtocolInfo (..)
  , enumCoreNodes
  ) where

import           Data.Word
import           NoThunks.Class (NoThunks)

import           Ouroboros.Consensus.Block
import           Ouroboros.Consensus.Config
import           Ouroboros.Consensus.Ledger.Extended
import           Ouroboros.Consensus.NodeId

{-------------------------------------------------------------------------------
  Number of core nodes
-------------------------------------------------------------------------------}

newtype NumCoreNodes = NumCoreNodes Word64
  deriving (Int -> NumCoreNodes -> ShowS
[NumCoreNodes] -> ShowS
NumCoreNodes -> String
(Int -> NumCoreNodes -> ShowS)
-> (NumCoreNodes -> String)
-> ([NumCoreNodes] -> ShowS)
-> Show NumCoreNodes
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NumCoreNodes] -> ShowS
$cshowList :: [NumCoreNodes] -> ShowS
show :: NumCoreNodes -> String
$cshow :: NumCoreNodes -> String
showsPrec :: Int -> NumCoreNodes -> ShowS
$cshowsPrec :: Int -> NumCoreNodes -> ShowS
Show, Context -> NumCoreNodes -> IO (Maybe ThunkInfo)
Proxy NumCoreNodes -> String
(Context -> NumCoreNodes -> IO (Maybe ThunkInfo))
-> (Context -> NumCoreNodes -> IO (Maybe ThunkInfo))
-> (Proxy NumCoreNodes -> String)
-> NoThunks NumCoreNodes
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
showTypeOf :: Proxy NumCoreNodes -> String
$cshowTypeOf :: Proxy NumCoreNodes -> String
wNoThunks :: Context -> NumCoreNodes -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> NumCoreNodes -> IO (Maybe ThunkInfo)
noThunks :: Context -> NumCoreNodes -> IO (Maybe ThunkInfo)
$cnoThunks :: Context -> NumCoreNodes -> IO (Maybe ThunkInfo)
NoThunks)

enumCoreNodes :: NumCoreNodes -> [CoreNodeId]
enumCoreNodes :: NumCoreNodes -> [CoreNodeId]
enumCoreNodes (NumCoreNodes Word64
0)        = []
enumCoreNodes (NumCoreNodes Word64
numNodes) =
    [ Word64 -> CoreNodeId
CoreNodeId Word64
n | Word64
n <- [Word64
0 .. Word64
numNodes Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
- Word64
1] ]

{-------------------------------------------------------------------------------
  Data required to run a protocol
-------------------------------------------------------------------------------}

-- | Data required to run the specified protocol.
data ProtocolInfo m b = ProtocolInfo {
        ProtocolInfo m b -> TopLevelConfig b
pInfoConfig       :: TopLevelConfig b
      , ProtocolInfo m b -> ExtLedgerState b
pInfoInitLedger   :: ExtLedgerState b -- ^ At genesis
      , ProtocolInfo m b -> m [BlockForging m b]
pInfoBlockForging :: m [BlockForging m b]
      }

-- | Data required by clients of a node running the specified protocol.
data ProtocolClientInfo b = ProtocolClientInfo {
       ProtocolClientInfo b -> CodecConfig b
pClientInfoCodecConfig :: CodecConfig b
     }