Skip to content

Commit 73c9b67

Browse files
committed
Added missing translations
1 parent d8cd874 commit 73c9b67

File tree

2 files changed

+86
-4
lines changed

2 files changed

+86
-4
lines changed

eras/conway/impl/src/Cardano/Ledger/Conway/Governance.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ module Cardano.Ledger.Conway.Governance (
164164
reCommitteeStateL,
165165
DefaultVote (..),
166166
defaultStakePoolVote,
167+
translateProposals,
167168

168169
-- * Exported for testing
169170
pparamsUpdateThreshold,

eras/dijkstra/src/Cardano/Ledger/Dijkstra/Translation.hs

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
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)
1617
import Cardano.Ledger.Conway (ConwayEra)
1718
import 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 (..))
2335
import Cardano.Ledger.Conway.State (ConwayInstantStake (..), EraCertState (..))
2436
import Cardano.Ledger.Core (
2537
EraTx (auxDataTxL, bodyTxL, witsTxL),
@@ -51,10 +63,10 @@ import Cardano.Ledger.Shelley.LedgerState (
5163
lsUTxOStateL,
5264
)
5365
import qualified Cardano.Ledger.UMap as UM
66+
import Data.Coerce (coerce)
5467
import Data.Default (Default (..))
5568
import qualified Data.Map.Strict as Map
5669
import Lens.Micro ((&), (.~), (^.))
57-
import Data.Coerce (coerce)
5870

5971
type 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+
153199
instance 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

156235
instance 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

159240
instance TranslateEra DijkstraEra ConwayGovState where
160241
translateEra ctxt ConwayGovState {..} =

0 commit comments

Comments
 (0)