Skip to content

Commit 0aae025

Browse files
committed
Define FromJSON instance in EraPParams based on pparams
1 parent 18bc75b commit 0aae025

File tree

1 file changed

+8
-8
lines changed
  • libs/cardano-ledger-core/src/Cardano/Ledger/Core

1 file changed

+8
-8
lines changed

libs/cardano-ledger-core/src/Cardano/Ledger/Core/PParams.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ import Cardano.Ledger.HKD (HKD, HKDApplicative, HKDFunctor (..), NoUpdate (..))
9898
import Cardano.Ledger.Plutus.ToPlutusData (ToPlutusData (..))
9999
import Control.DeepSeq (NFData)
100100
import Control.Monad.Identity (Identity)
101-
import Data.Aeson (FromJSON, ToJSON (..), object, pairs, (.=))
102-
import qualified Data.Aeson as Aeson (KeyValue)
101+
import Data.Aeson (FromJSON (..), ToJSON (..), object, pairs, (.:), (.=))
102+
import qualified Data.Aeson as Aeson (KeyValue, withObject)
103103
import qualified Data.Aeson.Key as Aeson (fromText)
104104
import Data.Default (Default (..))
105105
import qualified Data.Foldable as F (foldMap', foldl', foldlM)
@@ -142,8 +142,12 @@ instance EraPParams era => ToJSON (PParams era) where
142142
toJSON = object . jsonPairsPParams
143143
toEncoding = pairs . mconcat . jsonPairsPParams
144144

145-
deriving newtype instance
146-
FromJSON (PParamsHKD Identity era) => FromJSON (PParams era)
145+
instance EraPParams era => FromJSON (PParams era) where
146+
parseJSON =
147+
Aeson.withObject (show . typeRep $ Proxy @(PParams era)) $ \obj ->
148+
let accum acc PParam' {ppName, ppLens} =
149+
set ppLens <$> obj .: Aeson.fromText ppName <*> pure acc
150+
in F.foldlM accum (emptyPParams @era) (eraPParams @era)
147151

148152
instance EraPParams era => EncCBOR (PParams era) where
149153
encCBOR pp =
@@ -235,9 +239,6 @@ instance EraPParams era => ToJSON (PParamsUpdate era) where
235239
toJSON = object . jsonPairsPParamsUpdate
236240
toEncoding = pairs . mconcat . jsonPairsPParamsUpdate
237241

238-
deriving newtype instance
239-
FromJSON (PParamsHKD StrictMaybe era) => FromJSON (PParamsUpdate era)
240-
241242
deriving instance Generic (PParamsUpdate era)
242243

243244
-- Generic derivation of `applyPPUpdates`
@@ -287,7 +288,6 @@ class
287288
, Show (PParamsHKD Identity era)
288289
, NFData (PParamsHKD Identity era)
289290
, NoThunks (PParamsHKD Identity era)
290-
, FromJSON (PParamsHKD Identity era)
291291
, Eq (PParamsHKD StrictMaybe era)
292292
, Ord (PParamsHKD StrictMaybe era)
293293
, Show (PParamsHKD StrictMaybe era)

0 commit comments

Comments
 (0)