99{-# OPTIONS_GHC -Wno-orphans #-}
1010
1111module Cardano.Ledger.Conway.Transition (
12- ConwayEraTransition (.. ),
1312 TransitionConfig (.. ),
1413 toConwayTransitionConfigPairs ,
15- registerDelegs ,
16- registerInitialDReps ,
1714) where
1815
1916import Cardano.Ledger.Alonzo.Transition (toAlonzoTransitionConfigPairs )
@@ -23,11 +20,8 @@ import Cardano.Ledger.Conway.Core (Era (..))
2320import Cardano.Ledger.Conway.Era
2421import Cardano.Ledger.Conway.Genesis (ConwayGenesis (.. ), toConwayGenesisPairs )
2522import Cardano.Ledger.Conway.Translation ()
26- import Cardano.Ledger.Conway.TxCert (Delegatee , getStakePoolDelegatee , getVoteDelegatee )
27- import Cardano.Ledger.Credential (Credential )
23+ import Cardano.Ledger.Conway.TxCert (getStakePoolDelegatee , getVoteDelegatee )
2824import Cardano.Ledger.Crypto
29- import Cardano.Ledger.DRep (DRepState )
30- import Cardano.Ledger.Keys (KeyRole (.. ))
3125import Cardano.Ledger.Shelley.LedgerState (
3226 NewEpochState ,
3327 certDStateL ,
@@ -51,29 +45,15 @@ import Data.Aeson (
5145 withObject ,
5246 (.:) ,
5347 )
54- import Data.ListMap (ListMap )
5548import qualified Data.ListMap as ListMap
5649import qualified Data.Map.Strict as Map
5750import Data.Maybe.Strict (StrictMaybe (.. ), maybeToStrictMaybe )
5851import GHC.Generics
5952import Lens.Micro
6053import NoThunks.Class (NoThunks (.. ))
6154
62- class EraTransition era => ConwayEraTransition era where
63- tcDelegsL ::
64- Lens'
65- (TransitionConfig era )
66- (ListMap (Credential 'Staking (EraCrypto era )) (Delegatee (EraCrypto era )))
67-
68- tcInitialDRepsL ::
69- Lens'
70- (TransitionConfig era )
71- (ListMap (Credential 'DRepRole (EraCrypto era )) (DRepState (EraCrypto era )))
72-
73- tcConwayGenesisL :: Lens' (TransitionConfig era ) (ConwayGenesis (EraCrypto era ))
74-
7555registerDRepsThenDelegs ::
76- ConwayEraTransition era =>
56+ ( era ~ ConwayEra c , Crypto c ) =>
7757 TransitionConfig era ->
7858 NewEpochState era ->
7959 NewEpochState era
@@ -100,16 +80,9 @@ instance Crypto c => EraTransition (ConwayEra c) where
10080 tcTranslationContextL =
10181 lens ctcConwayGenesis (\ ctc ag -> ctc {ctcConwayGenesis = ag})
10282
103- instance Crypto c => ConwayEraTransition (ConwayEra c ) where
104- tcConwayGenesisL = lens ctcConwayGenesis (\ g x -> g {ctcConwayGenesis = x})
105-
106- tcDelegsL =
107- protectMainnetLens " ConwayDelegs" null $
108- tcConwayGenesisL . lens cgDelegs (\ g x -> g {cgDelegs = x})
109-
110- tcInitialDRepsL =
111- protectMainnetLens " InitialDReps" null $
112- tcConwayGenesisL . lens cgInitialDReps (\ g x -> g {cgInitialDReps = x})
83+ tcConwayGenesisL ::
84+ Lens' (TransitionConfig (ConwayEra c )) (ConwayGenesis (EraCrypto (ConwayEra c )))
85+ tcConwayGenesisL = lens ctcConwayGenesis (\ g x -> g {ctcConwayGenesis = x})
11386
11487instance Crypto c => NoThunks (TransitionConfig (ConwayEra c ))
11588
@@ -132,18 +105,23 @@ instance Crypto c => FromJSON (TransitionConfig (ConwayEra c)) where
132105 pure $ mkTransitionConfig pc ag
133106
134107registerInitialDReps ::
135- ConwayEraTransition era =>
108+ forall era c .
109+ (era ~ ConwayEra c , Crypto c ) =>
136110 TransitionConfig era ->
137111 NewEpochState era ->
138112 NewEpochState era
139113registerInitialDReps cfg =
140114 nesEsL . esLStateL . lsCertStateL . certVStateL . vsDRepsL .~ drepsMap
141115 where
142116 drepsMap = ListMap. toMap $ cfg ^. tcInitialDRepsL
117+ where
118+ tcInitialDRepsL =
119+ protectMainnetLens " InitialDReps" null $
120+ tcConwayGenesisL . lens cgInitialDReps (\ g x -> g {cgInitialDReps = x})
143121
144122registerDelegs ::
145- forall era .
146- ConwayEraTransition era =>
123+ forall era c .
124+ ( era ~ ConwayEra c , Crypto c ) =>
147125 TransitionConfig era ->
148126 NewEpochState era ->
149127 NewEpochState era
@@ -152,6 +130,11 @@ registerDelegs cfg =
152130 %~ \ m -> ListMap. foldrWithKey (\ (k, v) -> Map. insertWith joinUMElems k $ delegateeToUMElem v) m delegs
153131 where
154132 delegs = cfg ^. tcDelegsL
133+ where
134+ tcDelegsL =
135+ protectMainnetLens " ConwayDelegs" null $
136+ tcConwayGenesisL . lens cgDelegs (\ g x -> g {cgDelegs = x})
137+
155138 delegateeToUMElem d =
156139 UMElem
157140 SNothing
0 commit comments