Skip to content

Commit e1c311a

Browse files
committed
Move orphan ToPlutusData instances with their types
1 parent 524d715 commit e1c311a

File tree

4 files changed

+56
-61
lines changed

4 files changed

+56
-61
lines changed

eras/babbage/impl/src/Cardano/Ledger/Babbage/PParams.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ import Cardano.Ledger.Coin (Coin (..))
9292
import Cardano.Ledger.Core (EraPParams (..))
9393
import Cardano.Ledger.HKD (HKD, HKDFunctor (..))
9494
import Cardano.Ledger.Orphans ()
95+
import Cardano.Ledger.Plutus.ToPlutusData (ToPlutusData (..))
9596
import Cardano.Ledger.Shelley.PParams (shelleyCommonPParamsHKDPairsV8)
9697
import Control.DeepSeq (NFData)
9798
import Data.Aeson as Aeson (
@@ -117,6 +118,10 @@ newtype CoinPerByte = CoinPerByte {unCoinPerByte :: Coin}
117118
deriving stock (Eq, Ord)
118119
deriving newtype (EncCBOR, DecCBOR, ToJSON, FromJSON, NFData, NoThunks, Show)
119120

121+
instance ToPlutusData CoinPerByte where
122+
toPlutusData (CoinPerByte c) = toPlutusData @Coin c
123+
fromPlutusData x = CoinPerByte <$> fromPlutusData @Coin x
124+
120125
class AlonzoEraPParams era => BabbageEraPParams era where
121126
hkdCoinsPerUTxOByteL :: HKDFunctor f => Lens' (PParamsHKD f era) (HKD f CoinPerByte)
122127

eras/conway/impl/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## 1.20.0.0
44

5-
* Add `MkConwayTxBody` and all members of `ConwayTxBodyRaw`:
5+
* Add `MkConwayTxBody` and all members of `ConwayTxBodyRaw`:
66
(`ConwayTxBodyRaw`, `ctbrAuxDataHash`, `ctbrCerts`, `ctbrCollateralInputs`,
77
`ctbrCollateralReturn`, `ctbrCurrentTreasuryValue`, `ctbrFee`, `ctbrMint`, `ctbrNetworkId`,
88
`ctbrOutputs`, `ctbrProposalProcedures`, `ctbrReferenceInputs`, `ctbrReqSignerHashes`,
@@ -15,6 +15,7 @@
1515
* Added `ConwayEraCertState` class
1616
* Added `ConwayCertState` and related functions
1717
* Moved `CertState` to `State` module
18+
* Move `ToPutusData` instances for `CoinPerByte`, `DRepVotingThresholds` and `PoolVotingThresholds` with their respective types
1819

1920
## 1.19.0.0
2021

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ import Cardano.Ledger.Plutus.CostModels (
118118
mkCostModels,
119119
)
120120
import Cardano.Ledger.Plutus.Language (Language (PlutusV3))
121+
import Cardano.Ledger.Plutus.ToPlutusData (ToPlutusData (..))
121122
import Cardano.Ledger.Shelley.HardForks (bootstrapPhase)
122123
import Cardano.Ledger.Val (Val (..))
123124
import Control.DeepSeq (NFData (..), rwhnf)
@@ -137,6 +138,7 @@ import GHC.Stack (HasCallStack)
137138
import Lens.Micro
138139
import NoThunks.Class (NoThunks (..))
139140
import Numeric.Natural (Natural)
141+
import qualified PlutusLedgerApi.Common as P (Data (..))
140142

141143
class BabbageEraPParams era => ConwayEraPParams era where
142144
modifiedPPGroups :: PParamsUpdate era -> Set PPGroups
@@ -291,6 +293,24 @@ instance DecCBOR PoolVotingThresholds where
291293
pvtPPSecurityGroup <- decCBOR
292294
pure $ PoolVotingThresholds {..}
293295

296+
instance ToPlutusData PoolVotingThresholds where
297+
toPlutusData x =
298+
P.List
299+
[ toPlutusData (pvtMotionNoConfidence x)
300+
, toPlutusData (pvtCommitteeNormal x)
301+
, toPlutusData (pvtCommitteeNoConfidence x)
302+
, toPlutusData (pvtHardForkInitiation x)
303+
, toPlutusData (pvtPPSecurityGroup x)
304+
]
305+
fromPlutusData (P.List [a, b, c, d, e]) =
306+
PoolVotingThresholds
307+
<$> fromPlutusData a
308+
<*> fromPlutusData b
309+
<*> fromPlutusData c
310+
<*> fromPlutusData d
311+
<*> fromPlutusData e
312+
fromPlutusData _ = Nothing
313+
294314
data DRepVotingThresholds = DRepVotingThresholds
295315
{ dvtMotionNoConfidence :: !UnitInterval
296316
, dvtCommitteeNormal :: !UnitInterval
@@ -344,6 +364,34 @@ instance FromJSON DRepVotingThresholds where
344364
<*> o .: "ppGovGroup"
345365
<*> o .: "treasuryWithdrawal"
346366

367+
instance ToPlutusData DRepVotingThresholds where
368+
toPlutusData x =
369+
P.List
370+
[ toPlutusData (dvtMotionNoConfidence x)
371+
, toPlutusData (dvtCommitteeNormal x)
372+
, toPlutusData (dvtCommitteeNoConfidence x)
373+
, toPlutusData (dvtUpdateToConstitution x)
374+
, toPlutusData (dvtHardForkInitiation x)
375+
, toPlutusData (dvtPPNetworkGroup x)
376+
, toPlutusData (dvtPPEconomicGroup x)
377+
, toPlutusData (dvtPPTechnicalGroup x)
378+
, toPlutusData (dvtPPGovGroup x)
379+
, toPlutusData (dvtTreasuryWithdrawal x)
380+
]
381+
fromPlutusData (P.List [a, b, c, d, e, f, g, h, i, j]) =
382+
DRepVotingThresholds
383+
<$> fromPlutusData a
384+
<*> fromPlutusData b
385+
<*> fromPlutusData c
386+
<*> fromPlutusData d
387+
<*> fromPlutusData e
388+
<*> fromPlutusData f
389+
<*> fromPlutusData g
390+
<*> fromPlutusData h
391+
<*> fromPlutusData i
392+
<*> fromPlutusData j
393+
fromPlutusData _ = Nothing
394+
347395
dvtPPNetworkGroupL :: Lens' DRepVotingThresholds UnitInterval
348396
dvtPPNetworkGroupL = lens dvtPPNetworkGroup (\x y -> x {dvtPPNetworkGroup = y})
349397

eras/conway/impl/src/Cardano/Ledger/Conway/Plutus/Context.hs

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
{-# LANGUAGE MultiParamTypeClasses #-}
66
{-# LANGUAGE TypeApplications #-}
77
{-# LANGUAGE UndecidableSuperClasses #-}
8-
{-# OPTIONS_GHC -Wno-orphans #-}
98

109
module Cardano.Ledger.Conway.Plutus.Context (
1110
pparamUpdateToData,
@@ -25,12 +24,9 @@ import Cardano.Ledger.Alonzo.PParams (
2524
ppuPricesL,
2625
)
2726
import Cardano.Ledger.Alonzo.Plutus.Context (EraPlutusTxInfo)
28-
import Cardano.Ledger.Babbage.PParams (CoinPerByte (..), ppuCoinsPerUTxOByteL)
29-
import Cardano.Ledger.Coin (Coin (..))
27+
import Cardano.Ledger.Babbage.PParams (ppuCoinsPerUTxOByteL)
3028
import Cardano.Ledger.Conway.PParams (
3129
ConwayEraPParams (..),
32-
DRepVotingThresholds (..),
33-
PoolVotingThresholds (..),
3430
ppuCommitteeMaxTermLengthL,
3531
ppuCommitteeMinSizeL,
3632
ppuDRepActivityL,
@@ -103,61 +99,6 @@ pparamUpdateFromData pparamMap (Map pairs) =
10399
pure (ppu & ppuL .~ SJust val, Map.delete tg leftOverMap)
104100
pparamUpdateFromData _ _ = Nothing
105101

106-
-- ===================================================================
107-
-- ToPlutusData instances necessary for (PParamUpdate (CowayEra c))
108-
109-
instance ToPlutusData PoolVotingThresholds where
110-
toPlutusData x =
111-
List
112-
[ toPlutusData (pvtMotionNoConfidence x)
113-
, toPlutusData (pvtCommitteeNormal x)
114-
, toPlutusData (pvtCommitteeNoConfidence x)
115-
, toPlutusData (pvtHardForkInitiation x)
116-
, toPlutusData (pvtPPSecurityGroup x)
117-
]
118-
fromPlutusData (List [a, b, c, d, e]) =
119-
PoolVotingThresholds
120-
<$> fromPlutusData a
121-
<*> fromPlutusData b
122-
<*> fromPlutusData c
123-
<*> fromPlutusData d
124-
<*> fromPlutusData e
125-
fromPlutusData _ = Nothing
126-
127-
instance ToPlutusData DRepVotingThresholds where
128-
toPlutusData x =
129-
List
130-
[ toPlutusData (dvtMotionNoConfidence x)
131-
, toPlutusData (dvtCommitteeNormal x)
132-
, toPlutusData (dvtCommitteeNoConfidence x)
133-
, toPlutusData (dvtUpdateToConstitution x)
134-
, toPlutusData (dvtHardForkInitiation x)
135-
, toPlutusData (dvtPPNetworkGroup x)
136-
, toPlutusData (dvtPPEconomicGroup x)
137-
, toPlutusData (dvtPPTechnicalGroup x)
138-
, toPlutusData (dvtPPGovGroup x)
139-
, toPlutusData (dvtTreasuryWithdrawal x)
140-
]
141-
fromPlutusData (List [a, b, c, d, e, f, g, h, i, j]) =
142-
DRepVotingThresholds
143-
<$> fromPlutusData a
144-
<*> fromPlutusData b
145-
<*> fromPlutusData c
146-
<*> fromPlutusData d
147-
<*> fromPlutusData e
148-
<*> fromPlutusData f
149-
<*> fromPlutusData g
150-
<*> fromPlutusData h
151-
<*> fromPlutusData i
152-
<*> fromPlutusData j
153-
fromPlutusData _ = Nothing
154-
155-
instance ToPlutusData CoinPerByte where
156-
toPlutusData (CoinPerByte c) = toPlutusData @Coin c
157-
fromPlutusData x = CoinPerByte <$> fromPlutusData @Coin x
158-
159-
-- ==========================================================
160-
161102
-- | A Map for the Conway era
162103
conwayPParamMap :: ConwayEraPParams era => Map Word (PParam era)
163104
conwayPParamMap = makePParamMap conwayPParam

0 commit comments

Comments
 (0)