{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TypeFamilies #-} {-# OPTIONS_GHC -Wno-orphans #-} module Cardano.Ledger.Alonzo.Transition ( TransitionConfig (..), toAlonzoTransitionConfigPairs, ) where import Cardano.Ledger.Alonzo.Era import Cardano.Ledger.Alonzo.Genesis (AlonzoGenesis, toAlonzoGenesisPairs) import Cardano.Ledger.Alonzo.Translation () import Cardano.Ledger.Crypto import Cardano.Ledger.Mary import Cardano.Ledger.Mary.Transition (TransitionConfig (MaryTransitionConfig)) import Cardano.Ledger.Shelley.Transition import Data.Aeson ( FromJSON (..), KeyValue (..), ToJSON (..), Value (..), object, pairs, withObject, (.:), ) import GHC.Generics import Lens.Micro import NoThunks.Class (NoThunks (..)) instance Crypto c => EraTransition (AlonzoEra c) where data TransitionConfig (AlonzoEra c) = AlonzoTransitionConfig { forall c. TransitionConfig (AlonzoEra c) -> AlonzoGenesis atcAlonzoGenesis :: !AlonzoGenesis , forall c. TransitionConfig (AlonzoEra c) -> TransitionConfig (MaryEra c) atcMaryTransitionConfig :: !(TransitionConfig (MaryEra c)) } deriving (Int -> TransitionConfig (AlonzoEra c) -> ShowS forall c. Crypto c => Int -> TransitionConfig (AlonzoEra c) -> ShowS forall c. Crypto c => [TransitionConfig (AlonzoEra c)] -> ShowS forall c. Crypto c => TransitionConfig (AlonzoEra c) -> String forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a showList :: [TransitionConfig (AlonzoEra c)] -> ShowS $cshowList :: forall c. Crypto c => [TransitionConfig (AlonzoEra c)] -> ShowS show :: TransitionConfig (AlonzoEra c) -> String $cshow :: forall c. Crypto c => TransitionConfig (AlonzoEra c) -> String showsPrec :: Int -> TransitionConfig (AlonzoEra c) -> ShowS $cshowsPrec :: forall c. Crypto c => Int -> TransitionConfig (AlonzoEra c) -> ShowS Show, TransitionConfig (AlonzoEra c) -> TransitionConfig (AlonzoEra c) -> Bool forall c. Crypto c => TransitionConfig (AlonzoEra c) -> TransitionConfig (AlonzoEra c) -> Bool forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a /= :: TransitionConfig (AlonzoEra c) -> TransitionConfig (AlonzoEra c) -> Bool $c/= :: forall c. Crypto c => TransitionConfig (AlonzoEra c) -> TransitionConfig (AlonzoEra c) -> Bool == :: TransitionConfig (AlonzoEra c) -> TransitionConfig (AlonzoEra c) -> Bool $c== :: forall c. Crypto c => TransitionConfig (AlonzoEra c) -> TransitionConfig (AlonzoEra c) -> Bool Eq, forall a. (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a forall c x. Rep (TransitionConfig (AlonzoEra c)) x -> TransitionConfig (AlonzoEra c) forall c x. TransitionConfig (AlonzoEra c) -> Rep (TransitionConfig (AlonzoEra c)) x $cto :: forall c x. Rep (TransitionConfig (AlonzoEra c)) x -> TransitionConfig (AlonzoEra c) $cfrom :: forall c x. TransitionConfig (AlonzoEra c) -> Rep (TransitionConfig (AlonzoEra c)) x Generic) mkTransitionConfig :: TranslationContext (AlonzoEra c) -> TransitionConfig (PreviousEra (AlonzoEra c)) -> TransitionConfig (AlonzoEra c) mkTransitionConfig = forall c. AlonzoGenesis -> TransitionConfig (MaryEra c) -> TransitionConfig (AlonzoEra c) AlonzoTransitionConfig injectIntoTestState :: TransitionConfig (AlonzoEra c) -> NewEpochState (AlonzoEra c) -> NewEpochState (AlonzoEra c) injectIntoTestState = forall era. EraTransition era => TransitionConfig era -> NewEpochState era -> NewEpochState era registerInitialFundsThenStaking tcPreviousEraConfigL :: EraTransition (PreviousEra (AlonzoEra c)) => Lens' (TransitionConfig (AlonzoEra c)) (TransitionConfig (PreviousEra (AlonzoEra c))) tcPreviousEraConfigL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b lens forall c. TransitionConfig (AlonzoEra c) -> TransitionConfig (MaryEra c) atcMaryTransitionConfig (\TransitionConfig (AlonzoEra c) atc TransitionConfig (MaryEra c) pc -> TransitionConfig (AlonzoEra c) atc {atcMaryTransitionConfig :: TransitionConfig (MaryEra c) atcMaryTransitionConfig = TransitionConfig (MaryEra c) pc}) tcTranslationContextL :: Lens' (TransitionConfig (AlonzoEra c)) (TranslationContext (AlonzoEra c)) tcTranslationContextL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b lens forall c. TransitionConfig (AlonzoEra c) -> AlonzoGenesis atcAlonzoGenesis (\TransitionConfig (AlonzoEra c) atc AlonzoGenesis ag -> TransitionConfig (AlonzoEra c) atc {atcAlonzoGenesis :: AlonzoGenesis atcAlonzoGenesis = AlonzoGenesis ag}) instance Crypto c => NoThunks (TransitionConfig (AlonzoEra c)) instance Crypto c => ToJSON (TransitionConfig (AlonzoEra c)) where toJSON :: TransitionConfig (AlonzoEra c) -> Value toJSON = [Pair] -> Value object forall b c a. (b -> c) -> (a -> b) -> a -> c . forall e a c. (KeyValue e a, Crypto c) => TransitionConfig (AlonzoEra c) -> [a] toAlonzoTransitionConfigPairs toEncoding :: TransitionConfig (AlonzoEra c) -> Encoding toEncoding = Series -> Encoding pairs forall b c a. (b -> c) -> (a -> b) -> a -> c . forall a. Monoid a => [a] -> a mconcat forall b c a. (b -> c) -> (a -> b) -> a -> c . forall e a c. (KeyValue e a, Crypto c) => TransitionConfig (AlonzoEra c) -> [a] toAlonzoTransitionConfigPairs toAlonzoTransitionConfigPairs :: (KeyValue e a, Crypto c) => TransitionConfig (AlonzoEra c) -> [a] toAlonzoTransitionConfigPairs :: forall e a c. (KeyValue e a, Crypto c) => TransitionConfig (AlonzoEra c) -> [a] toAlonzoTransitionConfigPairs TransitionConfig (AlonzoEra c) alonzoConfig = forall e a c. (KeyValue e a, Crypto c) => TransitionConfig (ShelleyEra c) -> [a] toShelleyTransitionConfigPairs TransitionConfig (ShelleyEra c) shelleyConfig forall a. [a] -> [a] -> [a] ++ [Key "alonzo" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv .= [Pair] -> Value object (forall e a. KeyValue e a => AlonzoGenesis -> [a] toAlonzoGenesisPairs (TransitionConfig (AlonzoEra c) alonzoConfig forall s a. s -> Getting a s a -> a ^. forall era. EraTransition era => Lens' (TransitionConfig era) (TranslationContext era) tcTranslationContextL))] where maryConfig :: TransitionConfig (MaryEra c) maryConfig = TransitionConfig (AlonzoEra c) alonzoConfig forall s a. s -> Getting a s a -> a ^. forall era. (EraTransition era, EraTransition (PreviousEra era)) => Lens' (TransitionConfig era) (TransitionConfig (PreviousEra era)) tcPreviousEraConfigL allegraConfig :: TransitionConfig (AllegraEra c) allegraConfig = TransitionConfig (MaryEra c) maryConfig forall s a. s -> Getting a s a -> a ^. forall era. (EraTransition era, EraTransition (PreviousEra era)) => Lens' (TransitionConfig era) (TransitionConfig (PreviousEra era)) tcPreviousEraConfigL shelleyConfig :: TransitionConfig (ShelleyEra c) shelleyConfig = TransitionConfig (AllegraEra c) allegraConfig forall s a. s -> Getting a s a -> a ^. forall era. (EraTransition era, EraTransition (PreviousEra era)) => Lens' (TransitionConfig era) (TransitionConfig (PreviousEra era)) tcPreviousEraConfigL instance Crypto c => FromJSON (TransitionConfig (AlonzoEra c)) where parseJSON :: Value -> Parser (TransitionConfig (AlonzoEra c)) parseJSON = forall a. String -> (Object -> Parser a) -> Value -> Parser a withObject String "AlonzoTransitionConfig" forall a b. (a -> b) -> a -> b $ \Object o -> do AlonzoGenesis pc <- forall a. FromJSON a => Value -> Parser a parseJSON (Object -> Value Object Object o) TransitionConfig (MaryEra c) ag <- Object o forall a. FromJSON a => Object -> Key -> Parser a .: Key "alonzo" forall (f :: * -> *) a. Applicative f => a -> f a pure forall a b. (a -> b) -> a -> b $ forall era. EraTransition era => TranslationContext era -> TransitionConfig (PreviousEra era) -> TransitionConfig era mkTransitionConfig AlonzoGenesis pc TransitionConfig (MaryEra c) ag