{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module Bcc.Api.Modes (
ColeMode,
SophieMode,
BccMode,
ConsensusMode(..),
AnyConsensusMode(..),
renderMode,
ConsensusModeIsMultiEra(..),
EraInMode(..),
eraInModeToEra,
anyEraInModeToAnyEra,
AnyEraInMode(..),
toEraInMode,
ConsensusModeParams(..),
AnyConsensusModeParams(..),
Cole.EpochSlots(..),
ConsensusBlockForMode,
ConsensusBlockForEra,
toConsensusEraIndex,
fromConsensusEraIndex,
) where
import Prelude
import Bcc.Api.Eras
import Bcc.Ledger.Crypto (StandardCrypto)
import Data.SOP.Strict (K (K), NS (S, Z))
import Data.Text (Text)
import qualified Shardagnostic.Consensus.Cole.Ledger as Consensus
import qualified Shardagnostic.Consensus.Bcc.Block as Consensus
import qualified Shardagnostic.Consensus.Bcc.ColeHFC as Consensus (ColeBlockHFC)
import Shardagnostic.Consensus.HardFork.Combinator as Consensus (EraIndex (..), eraIndexSucc,
eraIndexZero)
import Shardagnostic.Consensus.Sophie.Eras
(StandardSophie,
StandardEvie,
StandardJen,
StandardAurum)
import qualified Shardagnostic.Consensus.Sophie.Ledger as Consensus
import qualified Shardagnostic.Consensus.Sophie.SophieHFC as Consensus (SophieBlockHFC)
import qualified Bcc.Chain.Slotting as Cole (EpochSlots (..))
data ColeMode
data SophieMode
data BccMode
data AnyConsensusModeParams where
AnyConsensusModeParams :: ConsensusModeParams mode -> AnyConsensusModeParams
deriving instance Show AnyConsensusModeParams
data ConsensusMode mode where
ColeMode :: ConsensusMode ColeMode
SophieMode :: ConsensusMode SophieMode
BccMode :: ConsensusMode BccMode
deriving instance Show (ConsensusMode mode)
data AnyConsensusMode where
AnyConsensusMode :: ConsensusMode mode -> AnyConsensusMode
deriving instance Show AnyConsensusMode
renderMode :: AnyConsensusMode -> Text
renderMode :: AnyConsensusMode -> Text
renderMode (AnyConsensusMode ConsensusMode mode
ColeMode) = Text
"ColeMode"
renderMode (AnyConsensusMode ConsensusMode mode
SophieMode) = Text
"SophieMode"
renderMode (AnyConsensusMode ConsensusMode mode
BccMode) = Text
"BccMode"
data ConsensusModeIsMultiEra mode where
BccModeIsMultiEra :: ConsensusModeIsMultiEra BccMode
deriving instance Show (ConsensusModeIsMultiEra mode)
toEraInMode :: BccEra era -> ConsensusMode mode -> Maybe (EraInMode era mode)
toEraInMode :: BccEra era -> ConsensusMode mode -> Maybe (EraInMode era mode)
toEraInMode BccEra era
ColeEra ConsensusMode mode
ColeMode = EraInMode ColeEra ColeMode -> Maybe (EraInMode ColeEra ColeMode)
forall a. a -> Maybe a
Just EraInMode ColeEra ColeMode
ColeEraInColeMode
toEraInMode BccEra era
SophieEra ConsensusMode mode
SophieMode = EraInMode SophieEra SophieMode
-> Maybe (EraInMode SophieEra SophieMode)
forall a. a -> Maybe a
Just EraInMode SophieEra SophieMode
SophieEraInSophieMode
toEraInMode BccEra era
ColeEra ConsensusMode mode
BccMode = EraInMode ColeEra BccMode -> Maybe (EraInMode ColeEra BccMode)
forall a. a -> Maybe a
Just EraInMode ColeEra BccMode
ColeEraInBccMode
toEraInMode BccEra era
SophieEra ConsensusMode mode
BccMode = EraInMode SophieEra BccMode -> Maybe (EraInMode SophieEra BccMode)
forall a. a -> Maybe a
Just EraInMode SophieEra BccMode
SophieEraInBccMode
toEraInMode BccEra era
EvieEra ConsensusMode mode
BccMode = EraInMode EvieEra BccMode -> Maybe (EraInMode EvieEra BccMode)
forall a. a -> Maybe a
Just EraInMode EvieEra BccMode
EvieEraInBccMode
toEraInMode BccEra era
JenEra ConsensusMode mode
BccMode = EraInMode JenEra BccMode -> Maybe (EraInMode JenEra BccMode)
forall a. a -> Maybe a
Just EraInMode JenEra BccMode
JenEraInBccMode
toEraInMode BccEra era
AurumEra ConsensusMode mode
BccMode = EraInMode AurumEra BccMode -> Maybe (EraInMode AurumEra BccMode)
forall a. a -> Maybe a
Just EraInMode AurumEra BccMode
AurumEraInBccMode
toEraInMode BccEra era
_ ConsensusMode mode
_ = Maybe (EraInMode era mode)
forall a. Maybe a
Nothing
data EraInMode era mode where
ColeEraInColeMode :: EraInMode ColeEra ColeMode
SophieEraInSophieMode :: EraInMode SophieEra SophieMode
ColeEraInBccMode :: EraInMode ColeEra BccMode
SophieEraInBccMode :: EraInMode SophieEra BccMode
EvieEraInBccMode :: EraInMode EvieEra BccMode
JenEraInBccMode :: EraInMode JenEra BccMode
AurumEraInBccMode :: EraInMode AurumEra BccMode
deriving instance Show (EraInMode era mode)
eraInModeToEra :: EraInMode era mode -> BccEra era
eraInModeToEra :: EraInMode era mode -> BccEra era
eraInModeToEra EraInMode era mode
ColeEraInColeMode = BccEra era
BccEra ColeEra
ColeEra
eraInModeToEra EraInMode era mode
SophieEraInSophieMode = BccEra era
BccEra SophieEra
SophieEra
eraInModeToEra EraInMode era mode
ColeEraInBccMode = BccEra era
BccEra ColeEra
ColeEra
eraInModeToEra EraInMode era mode
SophieEraInBccMode = BccEra era
BccEra SophieEra
SophieEra
eraInModeToEra EraInMode era mode
EvieEraInBccMode = BccEra era
BccEra EvieEra
EvieEra
eraInModeToEra EraInMode era mode
JenEraInBccMode = BccEra era
BccEra JenEra
JenEra
eraInModeToEra EraInMode era mode
AurumEraInBccMode = BccEra era
BccEra AurumEra
AurumEra
data AnyEraInMode mode where
AnyEraInMode :: EraInMode era mode -> AnyEraInMode mode
deriving instance Show (AnyEraInMode mode)
anyEraInModeToAnyEra :: AnyEraInMode mode -> AnyBccEra
anyEraInModeToAnyEra :: AnyEraInMode mode -> AnyBccEra
anyEraInModeToAnyEra (AnyEraInMode EraInMode era mode
erainmode) =
case EraInMode era mode
erainmode of
EraInMode era mode
ColeEraInColeMode -> BccEra ColeEra -> AnyBccEra
forall era. IsBccEra era => BccEra era -> AnyBccEra
AnyBccEra BccEra ColeEra
ColeEra
EraInMode era mode
SophieEraInSophieMode -> BccEra SophieEra -> AnyBccEra
forall era. IsBccEra era => BccEra era -> AnyBccEra
AnyBccEra BccEra SophieEra
SophieEra
EraInMode era mode
ColeEraInBccMode -> BccEra ColeEra -> AnyBccEra
forall era. IsBccEra era => BccEra era -> AnyBccEra
AnyBccEra BccEra ColeEra
ColeEra
EraInMode era mode
SophieEraInBccMode -> BccEra SophieEra -> AnyBccEra
forall era. IsBccEra era => BccEra era -> AnyBccEra
AnyBccEra BccEra SophieEra
SophieEra
EraInMode era mode
EvieEraInBccMode -> BccEra EvieEra -> AnyBccEra
forall era. IsBccEra era => BccEra era -> AnyBccEra
AnyBccEra BccEra EvieEra
EvieEra
EraInMode era mode
JenEraInBccMode -> BccEra JenEra -> AnyBccEra
forall era. IsBccEra era => BccEra era -> AnyBccEra
AnyBccEra BccEra JenEra
JenEra
EraInMode era mode
AurumEraInBccMode -> BccEra AurumEra -> AnyBccEra
forall era. IsBccEra era => BccEra era -> AnyBccEra
AnyBccEra BccEra AurumEra
AurumEra
data ConsensusModeParams mode where
ColeModeParams
:: Cole.EpochSlots
-> ConsensusModeParams ColeMode
SophieModeParams
:: ConsensusModeParams SophieMode
BccModeParams
:: Cole.EpochSlots
-> ConsensusModeParams BccMode
deriving instance Show (ConsensusModeParams mode)
type family ConsensusBlockForMode mode where
ConsensusBlockForMode ColeMode = Consensus.ColeBlockHFC
ConsensusBlockForMode SophieMode = Consensus.SophieBlockHFC StandardSophie
ConsensusBlockForMode BccMode = Consensus.BccBlock StandardCrypto
type family ConsensusBlockForEra era where
ConsensusBlockForEra ColeEra = Consensus.ColeBlock
ConsensusBlockForEra SophieEra = Consensus.SophieBlock StandardSophie
ConsensusBlockForEra EvieEra = Consensus.SophieBlock StandardEvie
ConsensusBlockForEra JenEra = Consensus.SophieBlock StandardJen
ConsensusBlockForEra AurumEra = Consensus.SophieBlock StandardAurum
eraIndex0 :: Consensus.EraIndex (x0 : xs)
eraIndex0 :: EraIndex (x0 : xs)
eraIndex0 = EraIndex (x0 : xs)
forall x (xs :: [*]). EraIndex (x : xs)
Consensus.eraIndexZero
eraIndex1 :: Consensus.EraIndex (x1 : x0 : xs)
eraIndex1 :: EraIndex (x1 : x0 : xs)
eraIndex1 = EraIndex (x0 : xs) -> EraIndex (x1 : x0 : xs)
forall (xs :: [*]) x. EraIndex xs -> EraIndex (x : xs)
eraIndexSucc EraIndex (x0 : xs)
forall x (xs :: [*]). EraIndex (x : xs)
eraIndex0
eraIndex2 :: Consensus.EraIndex (x2 : x1 : x0 : xs)
eraIndex2 :: EraIndex (x2 : x1 : x0 : xs)
eraIndex2 = EraIndex (x1 : x0 : xs) -> EraIndex (x2 : x1 : x0 : xs)
forall (xs :: [*]) x. EraIndex xs -> EraIndex (x : xs)
eraIndexSucc EraIndex (x1 : x0 : xs)
forall x1 x0 (xs :: [*]). EraIndex (x1 : x0 : xs)
eraIndex1
eraIndex3 :: Consensus.EraIndex (x3 : x2 : x1 : x0 : xs)
eraIndex3 :: EraIndex (x3 : x2 : x1 : x0 : xs)
eraIndex3 = EraIndex (x2 : x1 : x0 : xs) -> EraIndex (x3 : x2 : x1 : x0 : xs)
forall (xs :: [*]) x. EraIndex xs -> EraIndex (x : xs)
eraIndexSucc EraIndex (x2 : x1 : x0 : xs)
forall x2 x1 x0 (xs :: [*]). EraIndex (x2 : x1 : x0 : xs)
eraIndex2
eraIndex4 :: Consensus.EraIndex (x4 : x3 : x2 : x1 : x0 : xs)
eraIndex4 :: EraIndex (x4 : x3 : x2 : x1 : x0 : xs)
eraIndex4 = EraIndex (x3 : x2 : x1 : x0 : xs)
-> EraIndex (x4 : x3 : x2 : x1 : x0 : xs)
forall (xs :: [*]) x. EraIndex xs -> EraIndex (x : xs)
eraIndexSucc EraIndex (x3 : x2 : x1 : x0 : xs)
forall x3 x2 x1 x0 (xs :: [*]). EraIndex (x3 : x2 : x1 : x0 : xs)
eraIndex3
toConsensusEraIndex :: ConsensusBlockForMode mode ~ Consensus.HardForkBlock xs
=> EraInMode era mode
-> Consensus.EraIndex xs
toConsensusEraIndex :: EraInMode era mode -> EraIndex xs
toConsensusEraIndex EraInMode era mode
ColeEraInColeMode = EraIndex xs
forall x (xs :: [*]). EraIndex (x : xs)
eraIndex0
toConsensusEraIndex EraInMode era mode
SophieEraInSophieMode = EraIndex xs
forall x (xs :: [*]). EraIndex (x : xs)
eraIndex0
toConsensusEraIndex EraInMode era mode
ColeEraInBccMode = EraIndex xs
forall x (xs :: [*]). EraIndex (x : xs)
eraIndex0
toConsensusEraIndex EraInMode era mode
SophieEraInBccMode = EraIndex xs
forall x1 x0 (xs :: [*]). EraIndex (x1 : x0 : xs)
eraIndex1
toConsensusEraIndex EraInMode era mode
EvieEraInBccMode = EraIndex xs
forall x2 x1 x0 (xs :: [*]). EraIndex (x2 : x1 : x0 : xs)
eraIndex2
toConsensusEraIndex EraInMode era mode
JenEraInBccMode = EraIndex xs
forall x3 x2 x1 x0 (xs :: [*]). EraIndex (x3 : x2 : x1 : x0 : xs)
eraIndex3
toConsensusEraIndex EraInMode era mode
AurumEraInBccMode = EraIndex xs
forall x4 x3 x2 x1 x0 (xs :: [*]).
EraIndex (x4 : x3 : x2 : x1 : x0 : xs)
eraIndex4
fromConsensusEraIndex :: ConsensusBlockForMode mode ~ Consensus.HardForkBlock xs
=> ConsensusMode mode
-> Consensus.EraIndex xs
-> AnyEraInMode mode
fromConsensusEraIndex :: ConsensusMode mode -> EraIndex xs -> AnyEraInMode mode
fromConsensusEraIndex ConsensusMode mode
ColeMode = EraIndex xs -> AnyEraInMode mode
EraIndex '[ColeBlock] -> AnyEraInMode ColeMode
fromColeEraIndex
where
fromColeEraIndex :: Consensus.EraIndex
'[Consensus.ColeBlock]
-> AnyEraInMode ColeMode
fromColeEraIndex :: EraIndex '[ColeBlock] -> AnyEraInMode ColeMode
fromColeEraIndex (Consensus.EraIndex (Z (K ()))) =
EraInMode ColeEra ColeMode -> AnyEraInMode ColeMode
forall era mode. EraInMode era mode -> AnyEraInMode mode
AnyEraInMode EraInMode ColeEra ColeMode
ColeEraInColeMode
fromConsensusEraIndex ConsensusMode mode
SophieMode = EraIndex xs -> AnyEraInMode mode
EraIndex '[SophieBlock StandardSophie] -> AnyEraInMode SophieMode
fromSophieEraIndex
where
fromSophieEraIndex :: Consensus.EraIndex
'[Consensus.SophieBlock StandardSophie]
-> AnyEraInMode SophieMode
fromSophieEraIndex :: EraIndex '[SophieBlock StandardSophie] -> AnyEraInMode SophieMode
fromSophieEraIndex (Consensus.EraIndex (Z (K ()))) =
EraInMode SophieEra SophieMode -> AnyEraInMode SophieMode
forall era mode. EraInMode era mode -> AnyEraInMode mode
AnyEraInMode EraInMode SophieEra SophieMode
SophieEraInSophieMode
fromConsensusEraIndex ConsensusMode mode
BccMode = EraIndex xs -> AnyEraInMode mode
EraIndex (BccEras StandardCrypto) -> AnyEraInMode BccMode
fromSophieEraIndex
where
fromSophieEraIndex :: Consensus.EraIndex
(Consensus.BccEras StandardCrypto)
-> AnyEraInMode BccMode
fromSophieEraIndex :: EraIndex (BccEras StandardCrypto) -> AnyEraInMode BccMode
fromSophieEraIndex (Consensus.EraIndex (Z (K ()))) =
EraInMode ColeEra BccMode -> AnyEraInMode BccMode
forall era mode. EraInMode era mode -> AnyEraInMode mode
AnyEraInMode EraInMode ColeEra BccMode
ColeEraInBccMode
fromSophieEraIndex (Consensus.EraIndex (S (Z (K ())))) =
EraInMode SophieEra BccMode -> AnyEraInMode BccMode
forall era mode. EraInMode era mode -> AnyEraInMode mode
AnyEraInMode EraInMode SophieEra BccMode
SophieEraInBccMode
fromSophieEraIndex (Consensus.EraIndex (S (S (Z (K ()))))) =
EraInMode EvieEra BccMode -> AnyEraInMode BccMode
forall era mode. EraInMode era mode -> AnyEraInMode mode
AnyEraInMode EraInMode EvieEra BccMode
EvieEraInBccMode
fromSophieEraIndex (Consensus.EraIndex (S (S (S (Z (K ())))))) =
EraInMode JenEra BccMode -> AnyEraInMode BccMode
forall era mode. EraInMode era mode -> AnyEraInMode mode
AnyEraInMode EraInMode JenEra BccMode
JenEraInBccMode
fromSophieEraIndex (Consensus.EraIndex (S (S (S (S (Z (K ()))))))) =
EraInMode AurumEra BccMode -> AnyEraInMode BccMode
forall era mode. EraInMode era mode -> AnyEraInMode mode
AnyEraInMode EraInMode AurumEra BccMode
AurumEraInBccMode