{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE EmptyDataDeriving #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilyDependencies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE UndecidableSuperClasses #-}
{-# OPTIONS_GHC -Wno-redundant-constraints #-}
module Cardano.Ledger.Core.Era (
Era (..),
ByronEra,
EraRule,
EraRuleFailure,
EraRuleEvent,
VoidEraRule,
absurdEraRule,
InjectRuleFailure (..),
InjectRuleEvent (..),
AtMostEra,
AtLeastEra,
ExactEra,
ProtVerAtMost,
ProtVerAtLeast,
ProtVerInBounds,
atLeastEra,
atMostEra,
notSupportedInThisEra,
notSupportedInThisEraL,
eraProtVerLow,
eraProtVerHigh,
eraProtVersions,
toEraCBOR,
fromEraCBOR,
fromEraShareCBOR,
eraDecoder,
)
where
import Cardano.Ledger.Binary
import qualified Cardano.Ledger.Binary.Plain as Plain
import Control.DeepSeq (NFData (..))
import Control.State.Transition.Extended (PredicateFailure, STS (..))
import Data.Kind (Constraint, Type)
import Data.Typeable (Typeable)
import GHC.Stack (HasCallStack)
import GHC.TypeLits
import Lens.Micro
class
( Typeable era
, KnownNat (ProtVerLow era)
, KnownNat (ProtVerHigh era)
, ProtVerLow era <= ProtVerHigh era
, MinVersion <= ProtVerLow era
, MinVersion <= ProtVerHigh era
,
CmpNat (ProtVerLow era) MaxVersion ~ 'LT
, CmpNat (ProtVerHigh era) MaxVersion ~ 'LT
,
ProtVerLow era <= MaxVersion
, ProtVerHigh era <= MaxVersion
) =>
Era era
where
type PreviousEra era = (r :: Type) | r -> era
type ProtVerLow era :: Nat
type ProtVerHigh era :: Nat
type ProtVerHigh era = ProtVerLow era
eraName :: String
data ByronEra
data VoidEra
instance Era ByronEra where
type PreviousEra ByronEra = VoidEra
type ProtVerLow ByronEra = 0
type ProtVerHigh ByronEra = 1
eraName :: String
eraName = String
"Byron"
type family EraRule (rule :: Symbol) era = (r :: Type) | r -> rule
type family EraRuleFailure (rule :: Symbol) era = (r :: Type) | r -> rule era
type family EraRuleEvent (rule :: Symbol) era = (r :: Type) | r -> rule era
data VoidEraRule (rule :: Symbol) era
deriving (Int -> VoidEraRule rule era -> ShowS
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall (rule :: Symbol) era. Int -> VoidEraRule rule era -> ShowS
forall (rule :: Symbol) era. [VoidEraRule rule era] -> ShowS
forall (rule :: Symbol) era. VoidEraRule rule era -> String
showList :: [VoidEraRule rule era] -> ShowS
$cshowList :: forall (rule :: Symbol) era. [VoidEraRule rule era] -> ShowS
show :: VoidEraRule rule era -> String
$cshow :: forall (rule :: Symbol) era. VoidEraRule rule era -> String
showsPrec :: Int -> VoidEraRule rule era -> ShowS
$cshowsPrec :: forall (rule :: Symbol) era. Int -> VoidEraRule rule era -> ShowS
Show, VoidEraRule rule era -> VoidEraRule rule era -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall (rule :: Symbol) era.
VoidEraRule rule era -> VoidEraRule rule era -> Bool
/= :: VoidEraRule rule era -> VoidEraRule rule era -> Bool
$c/= :: forall (rule :: Symbol) era.
VoidEraRule rule era -> VoidEraRule rule era -> Bool
== :: VoidEraRule rule era -> VoidEraRule rule era -> Bool
$c== :: forall (rule :: Symbol) era.
VoidEraRule rule era -> VoidEraRule rule era -> Bool
Eq, VoidEraRule rule era -> VoidEraRule rule era -> Ordering
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
forall (rule :: Symbol) era. Eq (VoidEraRule rule era)
forall (rule :: Symbol) era.
VoidEraRule rule era -> VoidEraRule rule era -> Bool
forall (rule :: Symbol) era.
VoidEraRule rule era -> VoidEraRule rule era -> Ordering
forall (rule :: Symbol) era.
VoidEraRule rule era
-> VoidEraRule rule era -> VoidEraRule rule era
min :: VoidEraRule rule era
-> VoidEraRule rule era -> VoidEraRule rule era
$cmin :: forall (rule :: Symbol) era.
VoidEraRule rule era
-> VoidEraRule rule era -> VoidEraRule rule era
max :: VoidEraRule rule era
-> VoidEraRule rule era -> VoidEraRule rule era
$cmax :: forall (rule :: Symbol) era.
VoidEraRule rule era
-> VoidEraRule rule era -> VoidEraRule rule era
>= :: VoidEraRule rule era -> VoidEraRule rule era -> Bool
$c>= :: forall (rule :: Symbol) era.
VoidEraRule rule era -> VoidEraRule rule era -> Bool
> :: VoidEraRule rule era -> VoidEraRule rule era -> Bool
$c> :: forall (rule :: Symbol) era.
VoidEraRule rule era -> VoidEraRule rule era -> Bool
<= :: VoidEraRule rule era -> VoidEraRule rule era -> Bool
$c<= :: forall (rule :: Symbol) era.
VoidEraRule rule era -> VoidEraRule rule era -> Bool
< :: VoidEraRule rule era -> VoidEraRule rule era -> Bool
$c< :: forall (rule :: Symbol) era.
VoidEraRule rule era -> VoidEraRule rule era -> Bool
compare :: VoidEraRule rule era -> VoidEraRule rule era -> Ordering
$ccompare :: forall (rule :: Symbol) era.
VoidEraRule rule era -> VoidEraRule rule era -> Ordering
Ord)
instance NFData (VoidEraRule (rule :: Symbol) era) where
rnf :: VoidEraRule rule era -> ()
rnf = forall (rule :: Symbol) era a. VoidEraRule rule era -> a
absurdEraRule
instance (KnownSymbol rule, Era era) => ToCBOR (VoidEraRule (rule :: Symbol) era) where
toCBOR :: VoidEraRule rule era -> Encoding
toCBOR = forall (rule :: Symbol) era a. VoidEraRule rule era -> a
absurdEraRule
instance (KnownSymbol rule, Era era) => EncCBOR (VoidEraRule (rule :: Symbol) era)
instance (KnownSymbol rule, Era era) => FromCBOR (VoidEraRule (rule :: Symbol) era) where
fromCBOR :: forall s. Decoder s (VoidEraRule rule era)
fromCBOR = forall (m :: * -> *) e a. (MonadFail m, Buildable e) => e -> m a
cborError DecoderError
DecoderErrorVoid
instance (KnownSymbol rule, Era era) => DecCBOR (VoidEraRule (rule :: Symbol) era)
absurdEraRule :: VoidEraRule rule era -> a
absurdEraRule :: forall (rule :: Symbol) era a. VoidEraRule rule era -> a
absurdEraRule VoidEraRule rule era
a = case VoidEraRule rule era
a of {}
type instance EraRuleFailure "EPOCH" era = VoidEraRule "EPOCH" era
type instance EraRuleFailure "NEWEPOCH" era = VoidEraRule "NEWEPOCH" era
type instance EraRuleFailure "MIR" era = VoidEraRule "MIR" era
type instance EraRuleFailure "NEWPP" era = VoidEraRule "NEWPP" era
type instance EraRuleFailure "SNAP" era = VoidEraRule "SNAP" era
type instance EraRuleFailure "TICK" era = VoidEraRule "TICK" era
type instance EraRuleFailure "TICKF" era = VoidEraRule "TICKF" era
type instance EraRuleFailure "UPEC" era = VoidEraRule "UPEC" era
type instance EraRuleFailure "RUPD" era = VoidEraRule "RUPD" era
type instance EraRuleFailure "POOLREAP" era = VoidEraRule "POOLREAP" era
class
EraRuleFailure rule era ~ PredicateFailure (EraRule rule era) =>
InjectRuleFailure (rule :: Symbol) t era
where
injectFailure :: t era -> EraRuleFailure rule era
default injectFailure :: t era ~ EraRuleFailure rule era => t era -> EraRuleFailure rule era
injectFailure = forall a. a -> a
id
class
EraRuleEvent rule era ~ Event (EraRule rule era) =>
InjectRuleEvent (rule :: Symbol) t era
where
injectEvent :: t era -> EraRuleEvent rule era
default injectEvent :: t era ~ EraRuleEvent rule era => t era -> EraRuleEvent rule era
injectEvent = forall a. a -> a
id
type family ProtVerIsInBounds (check :: Symbol) era (v :: Nat) (b :: Bool) :: Constraint where
ProtVerIsInBounds check era v 'True = ()
ProtVerIsInBounds check era v 'False =
TypeError
( 'ShowType era
':<>: 'Text " protocol version bounds are: ["
':<>: 'ShowType (ProtVerLow era)
':<>: 'Text ", "
':<>: 'ShowType (ProtVerHigh era)
':<>: 'Text "], but required is "
':<>: 'Text check
':<>: 'Text " "
':<>: 'ShowType v
)
type family ProtVerAtLeast era (l :: Nat) :: Constraint where
ProtVerAtLeast era l = ProtVerIsInBounds "at least" era l (l <=? ProtVerHigh era)
type family ProtVerAtMost era (h :: Nat) :: Constraint where
ProtVerAtMost era h = ProtVerIsInBounds "at most" era h (ProtVerLow era <=? h)
type ProtVerInBounds era l h = (ProtVerAtLeast era l, ProtVerAtMost era h)
type ExactEra inEra era =
ProtVerInBounds era (ProtVerLow inEra) (ProtVerHigh inEra)
type AtLeastEra atLeastEra era =
ProtVerAtLeast era (ProtVerLow atLeastEra)
type AtMostEra eraMostEra era =
ProtVerAtMost era (ProtVerHigh eraMostEra)
eraProtVerLow :: forall era. Era era => Version
eraProtVerLow :: forall era. Era era => Version
eraProtVerLow = forall (v :: Nat).
(KnownNat v, MinVersion <= v, v <= MaxVersion) =>
Version
natVersion @(ProtVerLow era)
eraProtVerHigh :: forall era. Era era => Version
eraProtVerHigh :: forall era. Era era => Version
eraProtVerHigh = forall (v :: Nat).
(KnownNat v, MinVersion <= v, v <= MaxVersion) =>
Version
natVersion @(ProtVerHigh era)
eraProtVersions :: forall era. Era era => [Version]
eraProtVersions :: forall era. Era era => [Version]
eraProtVersions = [forall era. Era era => Version
eraProtVerLow @era .. forall era. Era era => Version
eraProtVerHigh @era]
atLeastEra :: AtLeastEra eraName era => ()
atLeastEra :: forall eraName era. AtLeastEra eraName era => ()
atLeastEra = ()
atMostEra :: AtMostEra eraName era => ()
atMostEra :: forall eraName era. AtMostEra eraName era => ()
atMostEra = ()
notSupportedInThisEra :: HasCallStack => a
notSupportedInThisEra :: forall a. HasCallStack => a
notSupportedInThisEra = forall a. HasCallStack => String -> a
error String
"Impossible: Function is not supported in this era"
notSupportedInThisEraL :: HasCallStack => Lens' a b
notSupportedInThisEraL :: forall a b. HasCallStack => Lens' a b
notSupportedInThisEraL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens forall a. HasCallStack => a
notSupportedInThisEra forall a. HasCallStack => a
notSupportedInThisEra
toEraCBOR :: forall era t. (Era era, EncCBOR t) => t -> Plain.Encoding
toEraCBOR :: forall era t. (Era era, EncCBOR t) => t -> Encoding
toEraCBOR = Version -> Encoding -> Encoding
toPlainEncoding (forall era. Era era => Version
eraProtVerLow @era) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. EncCBOR a => a -> Encoding
encCBOR
{-# INLINE toEraCBOR #-}
fromEraCBOR :: forall era t s. (Era era, DecCBOR t) => Plain.Decoder s t
fromEraCBOR :: forall era t s. (Era era, DecCBOR t) => Decoder s t
fromEraCBOR = forall era t s. Era era => Decoder s t -> Decoder s t
eraDecoder @era forall a s. DecCBOR a => Decoder s a
decCBOR
{-# INLINE fromEraCBOR #-}
fromEraShareCBOR :: forall era t s. (Era era, DecShareCBOR t) => Plain.Decoder s t
fromEraShareCBOR :: forall era t s. (Era era, DecShareCBOR t) => Decoder s t
fromEraShareCBOR = forall era t s. Era era => Decoder s t -> Decoder s t
eraDecoder @era forall a s. DecShareCBOR a => Decoder s a
decNoShareCBOR
{-# INLINE fromEraShareCBOR #-}
eraDecoder :: forall era t s. Era era => Decoder s t -> Plain.Decoder s t
eraDecoder :: forall era t s. Era era => Decoder s t -> Decoder s t
eraDecoder = forall s a.
Maybe ByteString -> Version -> Decoder s a -> Decoder s a
toPlainDecoder forall a. Maybe a
Nothing (forall era. Era era => Version
eraProtVerLow @era)
{-# INLINE eraDecoder #-}