{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

module Ouroboros.Consensus.HardFork.Combinator.Info (
    -- * Era info
    LedgerEraInfo (..)
  , SingleEraInfo (..)
  ) where

import           Codec.Serialise (Serialise)
import           Data.Text (Text)
import           GHC.Generics (Generic)
import           NoThunks.Class (NoThunks (..))

{-------------------------------------------------------------------------------
  Era info
-------------------------------------------------------------------------------}

-- | Information about an era (mostly for type errors)
data SingleEraInfo blk = SingleEraInfo {
      forall blk. SingleEraInfo blk -> Text
singleEraName :: !Text
    }
  deriving stock    ((forall x. SingleEraInfo blk -> Rep (SingleEraInfo blk) x)
-> (forall x. Rep (SingleEraInfo blk) x -> SingleEraInfo blk)
-> Generic (SingleEraInfo blk)
forall x. Rep (SingleEraInfo blk) x -> SingleEraInfo blk
forall x. SingleEraInfo blk -> Rep (SingleEraInfo blk) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall blk x. Rep (SingleEraInfo blk) x -> SingleEraInfo blk
forall blk x. SingleEraInfo blk -> Rep (SingleEraInfo blk) x
$cfrom :: forall blk x. SingleEraInfo blk -> Rep (SingleEraInfo blk) x
from :: forall x. SingleEraInfo blk -> Rep (SingleEraInfo blk) x
$cto :: forall blk x. Rep (SingleEraInfo blk) x -> SingleEraInfo blk
to :: forall x. Rep (SingleEraInfo blk) x -> SingleEraInfo blk
Generic, SingleEraInfo blk -> SingleEraInfo blk -> Bool
(SingleEraInfo blk -> SingleEraInfo blk -> Bool)
-> (SingleEraInfo blk -> SingleEraInfo blk -> Bool)
-> Eq (SingleEraInfo blk)
forall blk. SingleEraInfo blk -> SingleEraInfo blk -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall blk. SingleEraInfo blk -> SingleEraInfo blk -> Bool
== :: SingleEraInfo blk -> SingleEraInfo blk -> Bool
$c/= :: forall blk. SingleEraInfo blk -> SingleEraInfo blk -> Bool
/= :: SingleEraInfo blk -> SingleEraInfo blk -> Bool
Eq, Int -> SingleEraInfo blk -> ShowS
[SingleEraInfo blk] -> ShowS
SingleEraInfo blk -> String
(Int -> SingleEraInfo blk -> ShowS)
-> (SingleEraInfo blk -> String)
-> ([SingleEraInfo blk] -> ShowS)
-> Show (SingleEraInfo blk)
forall blk. Int -> SingleEraInfo blk -> ShowS
forall blk. [SingleEraInfo blk] -> ShowS
forall blk. SingleEraInfo blk -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall blk. Int -> SingleEraInfo blk -> ShowS
showsPrec :: Int -> SingleEraInfo blk -> ShowS
$cshow :: forall blk. SingleEraInfo blk -> String
show :: SingleEraInfo blk -> String
$cshowList :: forall blk. [SingleEraInfo blk] -> ShowS
showList :: [SingleEraInfo blk] -> ShowS
Show)
  deriving anyclass (Context -> SingleEraInfo blk -> IO (Maybe ThunkInfo)
Proxy (SingleEraInfo blk) -> String
(Context -> SingleEraInfo blk -> IO (Maybe ThunkInfo))
-> (Context -> SingleEraInfo blk -> IO (Maybe ThunkInfo))
-> (Proxy (SingleEraInfo blk) -> String)
-> NoThunks (SingleEraInfo blk)
forall blk. Context -> SingleEraInfo blk -> IO (Maybe ThunkInfo)
forall blk. Proxy (SingleEraInfo blk) -> String
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
$cnoThunks :: forall blk. Context -> SingleEraInfo blk -> IO (Maybe ThunkInfo)
noThunks :: Context -> SingleEraInfo blk -> IO (Maybe ThunkInfo)
$cwNoThunks :: forall blk. Context -> SingleEraInfo blk -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> SingleEraInfo blk -> IO (Maybe ThunkInfo)
$cshowTypeOf :: forall blk. Proxy (SingleEraInfo blk) -> String
showTypeOf :: Proxy (SingleEraInfo blk) -> String
NoThunks, [SingleEraInfo blk] -> Encoding
SingleEraInfo blk -> Encoding
(SingleEraInfo blk -> Encoding)
-> (forall s. Decoder s (SingleEraInfo blk))
-> ([SingleEraInfo blk] -> Encoding)
-> (forall s. Decoder s [SingleEraInfo blk])
-> Serialise (SingleEraInfo blk)
forall s. Decoder s [SingleEraInfo blk]
forall s. Decoder s (SingleEraInfo blk)
forall blk. [SingleEraInfo blk] -> Encoding
forall blk. SingleEraInfo blk -> Encoding
forall a.
(a -> Encoding)
-> (forall s. Decoder s a)
-> ([a] -> Encoding)
-> (forall s. Decoder s [a])
-> Serialise a
forall blk s. Decoder s [SingleEraInfo blk]
forall blk s. Decoder s (SingleEraInfo blk)
$cencode :: forall blk. SingleEraInfo blk -> Encoding
encode :: SingleEraInfo blk -> Encoding
$cdecode :: forall blk s. Decoder s (SingleEraInfo blk)
decode :: forall s. Decoder s (SingleEraInfo blk)
$cencodeList :: forall blk. [SingleEraInfo blk] -> Encoding
encodeList :: [SingleEraInfo blk] -> Encoding
$cdecodeList :: forall blk s. Decoder s [SingleEraInfo blk]
decodeList :: forall s. Decoder s [SingleEraInfo blk]
Serialise)

-- | Additional newtype wrapper around 'SingleEraInfo'
--
-- This is primarily useful for use in error messages: it marks which era
-- info came from the ledger, and which came from a tx/block/header/etc.
newtype LedgerEraInfo blk = LedgerEraInfo {
      forall blk. LedgerEraInfo blk -> SingleEraInfo blk
getLedgerEraInfo :: SingleEraInfo blk
    }
  deriving stock   (LedgerEraInfo blk -> LedgerEraInfo blk -> Bool
(LedgerEraInfo blk -> LedgerEraInfo blk -> Bool)
-> (LedgerEraInfo blk -> LedgerEraInfo blk -> Bool)
-> Eq (LedgerEraInfo blk)
forall blk. LedgerEraInfo blk -> LedgerEraInfo blk -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall blk. LedgerEraInfo blk -> LedgerEraInfo blk -> Bool
== :: LedgerEraInfo blk -> LedgerEraInfo blk -> Bool
$c/= :: forall blk. LedgerEraInfo blk -> LedgerEraInfo blk -> Bool
/= :: LedgerEraInfo blk -> LedgerEraInfo blk -> Bool
Eq, Int -> LedgerEraInfo blk -> ShowS
[LedgerEraInfo blk] -> ShowS
LedgerEraInfo blk -> String
(Int -> LedgerEraInfo blk -> ShowS)
-> (LedgerEraInfo blk -> String)
-> ([LedgerEraInfo blk] -> ShowS)
-> Show (LedgerEraInfo blk)
forall blk. Int -> LedgerEraInfo blk -> ShowS
forall blk. [LedgerEraInfo blk] -> ShowS
forall blk. LedgerEraInfo blk -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall blk. Int -> LedgerEraInfo blk -> ShowS
showsPrec :: Int -> LedgerEraInfo blk -> ShowS
$cshow :: forall blk. LedgerEraInfo blk -> String
show :: LedgerEraInfo blk -> String
$cshowList :: forall blk. [LedgerEraInfo blk] -> ShowS
showList :: [LedgerEraInfo blk] -> ShowS
Show)
  deriving newtype (Context -> LedgerEraInfo blk -> IO (Maybe ThunkInfo)
Proxy (LedgerEraInfo blk) -> String
(Context -> LedgerEraInfo blk -> IO (Maybe ThunkInfo))
-> (Context -> LedgerEraInfo blk -> IO (Maybe ThunkInfo))
-> (Proxy (LedgerEraInfo blk) -> String)
-> NoThunks (LedgerEraInfo blk)
forall blk. Context -> LedgerEraInfo blk -> IO (Maybe ThunkInfo)
forall blk. Proxy (LedgerEraInfo blk) -> String
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
$cnoThunks :: forall blk. Context -> LedgerEraInfo blk -> IO (Maybe ThunkInfo)
noThunks :: Context -> LedgerEraInfo blk -> IO (Maybe ThunkInfo)
$cwNoThunks :: forall blk. Context -> LedgerEraInfo blk -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> LedgerEraInfo blk -> IO (Maybe ThunkInfo)
$cshowTypeOf :: forall blk. Proxy (LedgerEraInfo blk) -> String
showTypeOf :: Proxy (LedgerEraInfo blk) -> String
NoThunks, [LedgerEraInfo blk] -> Encoding
LedgerEraInfo blk -> Encoding
(LedgerEraInfo blk -> Encoding)
-> (forall s. Decoder s (LedgerEraInfo blk))
-> ([LedgerEraInfo blk] -> Encoding)
-> (forall s. Decoder s [LedgerEraInfo blk])
-> Serialise (LedgerEraInfo blk)
forall s. Decoder s [LedgerEraInfo blk]
forall s. Decoder s (LedgerEraInfo blk)
forall blk. [LedgerEraInfo blk] -> Encoding
forall blk. LedgerEraInfo blk -> Encoding
forall a.
(a -> Encoding)
-> (forall s. Decoder s a)
-> ([a] -> Encoding)
-> (forall s. Decoder s [a])
-> Serialise a
forall blk s. Decoder s [LedgerEraInfo blk]
forall blk s. Decoder s (LedgerEraInfo blk)
$cencode :: forall blk. LedgerEraInfo blk -> Encoding
encode :: LedgerEraInfo blk -> Encoding
$cdecode :: forall blk s. Decoder s (LedgerEraInfo blk)
decode :: forall s. Decoder s (LedgerEraInfo blk)
$cencodeList :: forall blk. [LedgerEraInfo blk] -> Encoding
encodeList :: [LedgerEraInfo blk] -> Encoding
$cdecodeList :: forall blk s. Decoder s [LedgerEraInfo blk]
decodeList :: forall s. Decoder s [LedgerEraInfo blk]
Serialise)