22{-# LANGUAGE MultiParamTypeClasses #-}
33{-# LANGUAGE RecordWildCards #-}
44{-# LANGUAGE ScopedTypeVariables #-}
5+ {-# LANGUAGE TypeApplications #-}
56{-# LANGUAGE TypeFamilies #-}
67{-# OPTIONS_GHC -Wno-orphans #-}
78
@@ -16,10 +17,21 @@ import Cardano.Ledger.Binary (DecoderError)
1617import Cardano.Ledger.Conway (ConwayEra )
1718import Cardano.Ledger.Conway.Governance (
1819 ConwayGovState (.. ),
20+ DRepPulsingState (.. ),
21+ EnactState (.. ),
22+ GovAction (.. ),
23+ GovActionState (.. ),
24+ ProposalProcedure (.. ),
25+ Proposals ,
26+ PulsingSnapshot ,
27+ RatifyState (.. ),
28+ finishDRepPulser ,
1929 mkEnactState ,
2030 rsEnactStateL ,
21- setCompleteDRepPulsingState , Proposals , DRepPulsingState ,
31+ setCompleteDRepPulsingState ,
32+ translateProposals ,
2233 )
34+ import Cardano.Ledger.Conway.Governance.DRepPulser (PulsingSnapshot (.. ))
2335import Cardano.Ledger.Conway.State (ConwayInstantStake (.. ), EraCertState (.. ))
2436import Cardano.Ledger.Core (
2537 EraTx (auxDataTxL , bodyTxL , witsTxL ),
@@ -51,10 +63,10 @@ import Cardano.Ledger.Shelley.LedgerState (
5163 lsUTxOStateL ,
5264 )
5365import qualified Cardano.Ledger.UMap as UM
66+ import Data.Coerce (coerce )
5467import Data.Default (Default (.. ))
5568import qualified Data.Map.Strict as Map
5669import Lens.Micro ((&) , (.~) , (^.) )
57- import Data.Coerce (coerce )
5870
5971type instance TranslationContext DijkstraEra = ()
6072
@@ -150,11 +162,80 @@ translateCertState ctx scert =
150162 & certDStateL .~ translateEra' ctx (scert ^. certDStateL)
151163 & certPStateL .~ translateEra' ctx (scert ^. certPStateL)
152164
165+ instance TranslateEra DijkstraEra GovAction where
166+ translateEra _ =
167+ pure . \ case
168+ ParameterChange x y z -> ParameterChange (coerce x) (coerce y) z
169+ HardForkInitiation x y -> HardForkInitiation (coerce x) y
170+ TreasuryWithdrawals x y -> TreasuryWithdrawals x y
171+ NoConfidence x -> NoConfidence x
172+ UpdateCommittee x y z w -> UpdateCommittee x y z w
173+ NewConstitution x y -> NewConstitution x (coerce y)
174+ InfoAction -> InfoAction
175+
176+ instance TranslateEra DijkstraEra ProposalProcedure where
177+ translateEra ctxt ProposalProcedure {.. } =
178+ pure $
179+ ProposalProcedure
180+ { pProcDeposit = pProcDeposit
181+ , pProcReturnAddr = pProcReturnAddr
182+ , pProcGovAction = translateEra' ctxt pProcGovAction
183+ , pProcAnchor = pProcAnchor
184+ }
185+
186+ instance TranslateEra DijkstraEra GovActionState where
187+ translateEra ctxt GovActionState {.. } =
188+ pure $
189+ GovActionState
190+ { gasId = gasId
191+ , gasCommitteeVotes = gasCommitteeVotes
192+ , gasDRepVotes = gasDRepVotes
193+ , gasStakePoolVotes = gasStakePoolVotes
194+ , gasProposalProcedure = translateEra' ctxt gasProposalProcedure
195+ , gasProposedIn = gasProposedIn
196+ , gasExpiresAfter = gasExpiresAfter
197+ }
198+
153199instance TranslateEra DijkstraEra Proposals where
154- translateEra _ _ = undefined
200+ translateEra ctxt = pure . translateProposals @ DijkstraEra ctxt
201+
202+ instance TranslateEra DijkstraEra PulsingSnapshot where
203+ translateEra ctxt PulsingSnapshot {.. } =
204+ pure $
205+ PulsingSnapshot
206+ { psProposals = translateEra' ctxt <$> psProposals
207+ , psDRepDistr = psDRepDistr
208+ , psDRepState = psDRepState
209+ , psPoolDistr = psPoolDistr
210+ }
211+
212+ instance TranslateEra DijkstraEra EnactState where
213+ translateEra _ EnactState {.. } =
214+ pure $
215+ EnactState
216+ { ensCommittee = coerce ensCommittee
217+ , ensConstitution = coerce ensConstitution
218+ , ensCurPParams = coerce ensCurPParams
219+ , ensPrevPParams = coerce ensPrevPParams
220+ , ensTreasury = ensTreasury
221+ , ensWithdrawals = ensWithdrawals
222+ , ensPrevGovActionIds = ensPrevGovActionIds
223+ }
224+
225+ instance TranslateEra DijkstraEra RatifyState where
226+ translateEra ctxt RatifyState {.. } =
227+ pure $
228+ RatifyState
229+ { rsEnactState = translateEra' ctxt rsEnactState
230+ , rsEnacted = translateEra' ctxt <$> rsEnacted
231+ , rsExpired = rsExpired
232+ , rsDelayed = rsDelayed
233+ }
155234
156235instance TranslateEra DijkstraEra DRepPulsingState where
157- translateEra _ _ = undefined
236+ translateEra ctxt dps = pure $ DRComplete (translateEra' ctxt x) (translateEra' ctxt y)
237+ where
238+ (x, y) = finishDRepPulser dps
158239
159240instance TranslateEra DijkstraEra ConwayGovState where
160241 translateEra ctxt ConwayGovState {.. } =
0 commit comments