Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libs/cardano-ledger-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1.18.0.0

* Add `FromJSON` instance for `PParamUpdate`
* Changed the type of `AtMostEra` and `AtLeastEra` to accept a type level string instead of an actual era type.
* Add `EraName` type family to the `Era` type class and use it for default implementation of
`eraName` type class function.
Expand Down
14 changes: 13 additions & 1 deletion libs/cardano-ledger-core/src/Cardano/Ledger/Core/PParams.hs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ import Cardano.Ledger.HKD (HKD, HKDApplicative, HKDFunctor (..), NoUpdate (..))
import Cardano.Ledger.Plutus.ToPlutusData (ToPlutusData (..))
import Control.DeepSeq (NFData)
import Control.Monad.Identity (Identity)
import Data.Aeson (FromJSON (..), ToJSON (..), withObject, (.:), (.=))
import Data.Aeson (FromJSON (..), ToJSON (..), withObject, (.:), (.:!), (.=))
import qualified Data.Aeson.Key as Aeson (fromText)
import Data.Default (Default (..))
import qualified Data.Foldable as F (foldMap', foldl', foldlM)
Expand Down Expand Up @@ -249,6 +249,18 @@ deriving via
instance
EraPParams era => ToJSON (PParamsUpdate era)

instance EraPParams era => FromJSON (PParamsUpdate era) where
parseJSON =
withObject (show . typeRep $ Proxy @(PParamsUpdate era)) $ \obj ->
let go acc PParam {ppName, ppUpdate} =
maybe id setPpu <$> obj .:! Aeson.fromText ppName <*> pure acc
where
setPpu = maybe (const id) (\PParamUpdate {ppuLens} -> set ppuLens . SJust) ppUpdate
in F.foldlM
go
(emptyPParamsUpdate @era)
(eraPParams @era)

deriving instance Generic (PParamsUpdate era)

-- Generic derivation of `applyPPUpdates`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ roundTripJsonEraSpec =
describe (eraName @era) $ do
describe "RoundTrip JSON" $ do
roundTripJsonSpec @(PParams era)
roundTripJsonSpec @(PParamsUpdate era)
roundTripJsonSpec @(TranslationContext era)

goldenJsonPParamsSpec ::
Expand Down