{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Cardano.Ledger.Conway.Genesis (
  ConwayGenesis (..),
  toConwayGenesisPairs,
  cgDelegsL,
) where

import Cardano.Ledger.Binary (
  DecCBOR (..),
  EncCBOR (..),
  FromCBOR (..),
  ToCBOR (..),
 )
import Cardano.Ledger.Binary.Coders
import Cardano.Ledger.Conway.Era (ConwayEra)
import Cardano.Ledger.Conway.Governance
import Cardano.Ledger.Conway.PParams (UpgradeConwayPParams, toUpgradeConwayPParamsUpdatePairs)
import Cardano.Ledger.Conway.TxCert (Delegatee)
import Cardano.Ledger.Core
import Cardano.Ledger.Credential (Credential)
import Cardano.Ledger.DRep (DRepState)
import Cardano.Ledger.Genesis (EraGenesis (..))
import Data.Aeson (
  FromJSON (..),
  KeyValue (..),
  ToJSON (..),
  Value (..),
  object,
  pairs,
  withObject,
  (.!=),
  (.:),
  (.:?),
 )
import Data.Functor.Identity (Identity)
import Data.ListMap (ListMap)
import GHC.Generics (Generic)
import Lens.Micro (Lens', lens)
import NoThunks.Class (NoThunks)

data ConwayGenesis = ConwayGenesis
  { ConwayGenesis -> UpgradeConwayPParams Identity
cgUpgradePParams :: !(UpgradeConwayPParams Identity)
  , ConwayGenesis -> Constitution ConwayEra
cgConstitution :: !(Constitution ConwayEra)
  , ConwayGenesis -> Committee ConwayEra
cgCommittee :: !(Committee ConwayEra)
  , ConwayGenesis -> ListMap (Credential 'Staking) Delegatee
cgDelegs :: ListMap (Credential 'Staking) Delegatee
  , ConwayGenesis -> ListMap (Credential 'DRepRole) DRepState
cgInitialDReps :: ListMap (Credential 'DRepRole) DRepState
  }
  deriving (ConwayGenesis -> ConwayGenesis -> Bool
(ConwayGenesis -> ConwayGenesis -> Bool)
-> (ConwayGenesis -> ConwayGenesis -> Bool) -> Eq ConwayGenesis
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ConwayGenesis -> ConwayGenesis -> Bool
== :: ConwayGenesis -> ConwayGenesis -> Bool
$c/= :: ConwayGenesis -> ConwayGenesis -> Bool
/= :: ConwayGenesis -> ConwayGenesis -> Bool
Eq, (forall x. ConwayGenesis -> Rep ConwayGenesis x)
-> (forall x. Rep ConwayGenesis x -> ConwayGenesis)
-> Generic ConwayGenesis
forall x. Rep ConwayGenesis x -> ConwayGenesis
forall x. ConwayGenesis -> Rep ConwayGenesis x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ConwayGenesis -> Rep ConwayGenesis x
from :: forall x. ConwayGenesis -> Rep ConwayGenesis x
$cto :: forall x. Rep ConwayGenesis x -> ConwayGenesis
to :: forall x. Rep ConwayGenesis x -> ConwayGenesis
Generic, Int -> ConwayGenesis -> ShowS
[ConwayGenesis] -> ShowS
ConwayGenesis -> String
(Int -> ConwayGenesis -> ShowS)
-> (ConwayGenesis -> String)
-> ([ConwayGenesis] -> ShowS)
-> Show ConwayGenesis
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ConwayGenesis -> ShowS
showsPrec :: Int -> ConwayGenesis -> ShowS
$cshow :: ConwayGenesis -> String
show :: ConwayGenesis -> String
$cshowList :: [ConwayGenesis] -> ShowS
showList :: [ConwayGenesis] -> ShowS
Show)

cgDelegsL :: Lens' ConwayGenesis (ListMap (Credential 'Staking) Delegatee)
cgDelegsL :: Lens' ConwayGenesis (ListMap (Credential 'Staking) Delegatee)
cgDelegsL = (ConwayGenesis -> ListMap (Credential 'Staking) Delegatee)
-> (ConwayGenesis
    -> ListMap (Credential 'Staking) Delegatee -> ConwayGenesis)
-> Lens' ConwayGenesis (ListMap (Credential 'Staking) Delegatee)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens ConwayGenesis -> ListMap (Credential 'Staking) Delegatee
cgDelegs (\ConwayGenesis
x ListMap (Credential 'Staking) Delegatee
y -> ConwayGenesis
x {cgDelegs = y})

instance EraGenesis ConwayEra where
  type Genesis ConwayEra = ConwayGenesis

instance NoThunks ConwayGenesis

-- | Genesis are always encoded with the version of era they are defined in.
instance FromCBOR ConwayGenesis where
  fromCBOR :: forall s. Decoder s ConwayGenesis
fromCBOR =
    forall era t s. Era era => Decoder s t -> Decoder s t
eraDecoder @ConwayEra (Decoder s ConwayGenesis -> Decoder s ConwayGenesis)
-> Decoder s ConwayGenesis -> Decoder s ConwayGenesis
forall a b. (a -> b) -> a -> b
$
      Decode ('Closed 'Dense) ConwayGenesis -> Decoder s ConwayGenesis
forall t (w :: Wrapped) s. Typeable t => Decode w t -> Decoder s t
decode (Decode ('Closed 'Dense) ConwayGenesis -> Decoder s ConwayGenesis)
-> Decode ('Closed 'Dense) ConwayGenesis -> Decoder s ConwayGenesis
forall a b. (a -> b) -> a -> b
$
        (UpgradeConwayPParams Identity
 -> Constitution ConwayEra
 -> Committee ConwayEra
 -> ListMap (Credential 'Staking) Delegatee
 -> ListMap (Credential 'DRepRole) DRepState
 -> ConwayGenesis)
-> Decode
     ('Closed 'Dense)
     (UpgradeConwayPParams Identity
      -> Constitution ConwayEra
      -> Committee ConwayEra
      -> ListMap (Credential 'Staking) Delegatee
      -> ListMap (Credential 'DRepRole) DRepState
      -> ConwayGenesis)
forall t. t -> Decode ('Closed 'Dense) t
RecD UpgradeConwayPParams Identity
-> Constitution ConwayEra
-> Committee ConwayEra
-> ListMap (Credential 'Staking) Delegatee
-> ListMap (Credential 'DRepRole) DRepState
-> ConwayGenesis
ConwayGenesis Decode
  ('Closed 'Dense)
  (UpgradeConwayPParams Identity
   -> Constitution ConwayEra
   -> Committee ConwayEra
   -> ListMap (Credential 'Staking) Delegatee
   -> ListMap (Credential 'DRepRole) DRepState
   -> ConwayGenesis)
-> Decode ('Closed Any) (UpgradeConwayPParams Identity)
-> Decode
     ('Closed 'Dense)
     (Constitution ConwayEra
      -> Committee ConwayEra
      -> ListMap (Credential 'Staking) Delegatee
      -> ListMap (Credential 'DRepRole) DRepState
      -> ConwayGenesis)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) (UpgradeConwayPParams Identity)
forall t (w :: Wrapped). DecCBOR t => Decode w t
From Decode
  ('Closed 'Dense)
  (Constitution ConwayEra
   -> Committee ConwayEra
   -> ListMap (Credential 'Staking) Delegatee
   -> ListMap (Credential 'DRepRole) DRepState
   -> ConwayGenesis)
-> Decode ('Closed Any) (Constitution ConwayEra)
-> Decode
     ('Closed 'Dense)
     (Committee ConwayEra
      -> ListMap (Credential 'Staking) Delegatee
      -> ListMap (Credential 'DRepRole) DRepState
      -> ConwayGenesis)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) (Constitution ConwayEra)
forall t (w :: Wrapped). DecCBOR t => Decode w t
From Decode
  ('Closed 'Dense)
  (Committee ConwayEra
   -> ListMap (Credential 'Staking) Delegatee
   -> ListMap (Credential 'DRepRole) DRepState
   -> ConwayGenesis)
-> Decode ('Closed Any) (Committee ConwayEra)
-> Decode
     ('Closed 'Dense)
     (ListMap (Credential 'Staking) Delegatee
      -> ListMap (Credential 'DRepRole) DRepState -> ConwayGenesis)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) (Committee ConwayEra)
forall t (w :: Wrapped). DecCBOR t => Decode w t
From Decode
  ('Closed 'Dense)
  (ListMap (Credential 'Staking) Delegatee
   -> ListMap (Credential 'DRepRole) DRepState -> ConwayGenesis)
-> Decode ('Closed Any) (ListMap (Credential 'Staking) Delegatee)
-> Decode
     ('Closed 'Dense)
     (ListMap (Credential 'DRepRole) DRepState -> ConwayGenesis)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) (ListMap (Credential 'Staking) Delegatee)
forall t (w :: Wrapped). DecCBOR t => Decode w t
From Decode
  ('Closed 'Dense)
  (ListMap (Credential 'DRepRole) DRepState -> ConwayGenesis)
-> Decode ('Closed Any) (ListMap (Credential 'DRepRole) DRepState)
-> Decode ('Closed 'Dense) ConwayGenesis
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) (ListMap (Credential 'DRepRole) DRepState)
forall t (w :: Wrapped). DecCBOR t => Decode w t
From

instance ToCBOR ConwayGenesis where
  toCBOR :: ConwayGenesis -> Encoding
toCBOR x :: ConwayGenesis
x@(ConwayGenesis UpgradeConwayPParams Identity
_ Constitution ConwayEra
_ Committee ConwayEra
_ ListMap (Credential 'Staking) Delegatee
_ ListMap (Credential 'DRepRole) DRepState
_) =
    let ConwayGenesis {ListMap (Credential 'Staking) Delegatee
ListMap (Credential 'DRepRole) DRepState
Constitution ConwayEra
Committee ConwayEra
UpgradeConwayPParams Identity
cgUpgradePParams :: ConwayGenesis -> UpgradeConwayPParams Identity
cgConstitution :: ConwayGenesis -> Constitution ConwayEra
cgCommittee :: ConwayGenesis -> Committee ConwayEra
cgDelegs :: ConwayGenesis -> ListMap (Credential 'Staking) Delegatee
cgInitialDReps :: ConwayGenesis -> ListMap (Credential 'DRepRole) DRepState
cgUpgradePParams :: UpgradeConwayPParams Identity
cgConstitution :: Constitution ConwayEra
cgCommittee :: Committee ConwayEra
cgDelegs :: ListMap (Credential 'Staking) Delegatee
cgInitialDReps :: ListMap (Credential 'DRepRole) DRepState
..} = ConwayGenesis
x
     in forall era t. (Era era, EncCBOR t) => t -> Encoding
toEraCBOR @ConwayEra (Encoding -> Encoding)
-> (Encode ('Closed 'Dense) ConwayGenesis -> Encoding)
-> Encode ('Closed 'Dense) ConwayGenesis
-> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Encode ('Closed 'Dense) ConwayGenesis -> Encoding
forall (w :: Wrapped) t. Encode w t -> Encoding
encode (Encode ('Closed 'Dense) ConwayGenesis -> Encoding)
-> Encode ('Closed 'Dense) ConwayGenesis -> Encoding
forall a b. (a -> b) -> a -> b
$
          (UpgradeConwayPParams Identity
 -> Constitution ConwayEra
 -> Committee ConwayEra
 -> ListMap (Credential 'Staking) Delegatee
 -> ListMap (Credential 'DRepRole) DRepState
 -> ConwayGenesis)
-> Encode
     ('Closed 'Dense)
     (UpgradeConwayPParams Identity
      -> Constitution ConwayEra
      -> Committee ConwayEra
      -> ListMap (Credential 'Staking) Delegatee
      -> ListMap (Credential 'DRepRole) DRepState
      -> ConwayGenesis)
forall t. t -> Encode ('Closed 'Dense) t
Rec UpgradeConwayPParams Identity
-> Constitution ConwayEra
-> Committee ConwayEra
-> ListMap (Credential 'Staking) Delegatee
-> ListMap (Credential 'DRepRole) DRepState
-> ConwayGenesis
ConwayGenesis
            Encode
  ('Closed 'Dense)
  (UpgradeConwayPParams Identity
   -> Constitution ConwayEra
   -> Committee ConwayEra
   -> ListMap (Credential 'Staking) Delegatee
   -> ListMap (Credential 'DRepRole) DRepState
   -> ConwayGenesis)
-> Encode ('Closed 'Dense) (UpgradeConwayPParams Identity)
-> Encode
     ('Closed 'Dense)
     (Constitution ConwayEra
      -> Committee ConwayEra
      -> ListMap (Credential 'Staking) Delegatee
      -> ListMap (Credential 'DRepRole) DRepState
      -> ConwayGenesis)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> UpgradeConwayPParams Identity
-> Encode ('Closed 'Dense) (UpgradeConwayPParams Identity)
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To UpgradeConwayPParams Identity
cgUpgradePParams
            Encode
  ('Closed 'Dense)
  (Constitution ConwayEra
   -> Committee ConwayEra
   -> ListMap (Credential 'Staking) Delegatee
   -> ListMap (Credential 'DRepRole) DRepState
   -> ConwayGenesis)
-> Encode ('Closed 'Dense) (Constitution ConwayEra)
-> Encode
     ('Closed 'Dense)
     (Committee ConwayEra
      -> ListMap (Credential 'Staking) Delegatee
      -> ListMap (Credential 'DRepRole) DRepState
      -> ConwayGenesis)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> Constitution ConwayEra
-> Encode ('Closed 'Dense) (Constitution ConwayEra)
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To Constitution ConwayEra
cgConstitution
            Encode
  ('Closed 'Dense)
  (Committee ConwayEra
   -> ListMap (Credential 'Staking) Delegatee
   -> ListMap (Credential 'DRepRole) DRepState
   -> ConwayGenesis)
-> Encode ('Closed 'Dense) (Committee ConwayEra)
-> Encode
     ('Closed 'Dense)
     (ListMap (Credential 'Staking) Delegatee
      -> ListMap (Credential 'DRepRole) DRepState -> ConwayGenesis)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> Committee ConwayEra
-> Encode ('Closed 'Dense) (Committee ConwayEra)
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To Committee ConwayEra
cgCommittee
            Encode
  ('Closed 'Dense)
  (ListMap (Credential 'Staking) Delegatee
   -> ListMap (Credential 'DRepRole) DRepState -> ConwayGenesis)
-> Encode
     ('Closed 'Dense) (ListMap (Credential 'Staking) Delegatee)
-> Encode
     ('Closed 'Dense)
     (ListMap (Credential 'DRepRole) DRepState -> ConwayGenesis)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> ListMap (Credential 'Staking) Delegatee
-> Encode
     ('Closed 'Dense) (ListMap (Credential 'Staking) Delegatee)
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To ListMap (Credential 'Staking) Delegatee
cgDelegs
            Encode
  ('Closed 'Dense)
  (ListMap (Credential 'DRepRole) DRepState -> ConwayGenesis)
-> Encode
     ('Closed 'Dense) (ListMap (Credential 'DRepRole) DRepState)
-> Encode ('Closed 'Dense) ConwayGenesis
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> ListMap (Credential 'DRepRole) DRepState
-> Encode
     ('Closed 'Dense) (ListMap (Credential 'DRepRole) DRepState)
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To ListMap (Credential 'DRepRole) DRepState
cgInitialDReps

instance DecCBOR ConwayGenesis

instance EncCBOR ConwayGenesis

instance ToJSON ConwayGenesis where
  toJSON :: ConwayGenesis -> Value
toJSON = [Pair] -> Value
object ([Pair] -> Value)
-> (ConwayGenesis -> [Pair]) -> ConwayGenesis -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConwayGenesis -> [Pair]
forall e a. KeyValue e a => ConwayGenesis -> [a]
toConwayGenesisPairs
  toEncoding :: ConwayGenesis -> Encoding
toEncoding = Series -> Encoding
pairs (Series -> Encoding)
-> (ConwayGenesis -> Series) -> ConwayGenesis -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Series] -> Series
forall a. Monoid a => [a] -> a
mconcat ([Series] -> Series)
-> (ConwayGenesis -> [Series]) -> ConwayGenesis -> Series
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConwayGenesis -> [Series]
forall e a. KeyValue e a => ConwayGenesis -> [a]
toConwayGenesisPairs

instance FromJSON ConwayGenesis where
  parseJSON :: Value -> Parser ConwayGenesis
parseJSON =
    String
-> (Object -> Parser ConwayGenesis)
-> Value
-> Parser ConwayGenesis
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"ConwayGenesis" ((Object -> Parser ConwayGenesis) -> Value -> Parser ConwayGenesis)
-> (Object -> Parser ConwayGenesis)
-> Value
-> Parser ConwayGenesis
forall a b. (a -> b) -> a -> b
$ \Object
obj -> do
      UpgradeConwayPParams Identity
upgradeProtocolPParams <- Value -> Parser (UpgradeConwayPParams Identity)
forall a. FromJSON a => Value -> Parser a
parseJSON (Object -> Value
Object Object
obj)
      UpgradeConwayPParams Identity
-> Constitution ConwayEra
-> Committee ConwayEra
-> ListMap (Credential 'Staking) Delegatee
-> ListMap (Credential 'DRepRole) DRepState
-> ConwayGenesis
ConwayGenesis
        (UpgradeConwayPParams Identity
 -> Constitution ConwayEra
 -> Committee ConwayEra
 -> ListMap (Credential 'Staking) Delegatee
 -> ListMap (Credential 'DRepRole) DRepState
 -> ConwayGenesis)
-> Parser (UpgradeConwayPParams Identity)
-> Parser
     (Constitution ConwayEra
      -> Committee ConwayEra
      -> ListMap (Credential 'Staking) Delegatee
      -> ListMap (Credential 'DRepRole) DRepState
      -> ConwayGenesis)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> UpgradeConwayPParams Identity
-> Parser (UpgradeConwayPParams Identity)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure UpgradeConwayPParams Identity
upgradeProtocolPParams
        Parser
  (Constitution ConwayEra
   -> Committee ConwayEra
   -> ListMap (Credential 'Staking) Delegatee
   -> ListMap (Credential 'DRepRole) DRepState
   -> ConwayGenesis)
-> Parser (Constitution ConwayEra)
-> Parser
     (Committee ConwayEra
      -> ListMap (Credential 'Staking) Delegatee
      -> ListMap (Credential 'DRepRole) DRepState
      -> ConwayGenesis)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Key -> Parser (Constitution ConwayEra)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"constitution"
        Parser
  (Committee ConwayEra
   -> ListMap (Credential 'Staking) Delegatee
   -> ListMap (Credential 'DRepRole) DRepState
   -> ConwayGenesis)
-> Parser (Committee ConwayEra)
-> Parser
     (ListMap (Credential 'Staking) Delegatee
      -> ListMap (Credential 'DRepRole) DRepState -> ConwayGenesis)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Key -> Parser (Committee ConwayEra)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"committee"
        Parser
  (ListMap (Credential 'Staking) Delegatee
   -> ListMap (Credential 'DRepRole) DRepState -> ConwayGenesis)
-> Parser (ListMap (Credential 'Staking) Delegatee)
-> Parser
     (ListMap (Credential 'DRepRole) DRepState -> ConwayGenesis)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object
-> Key -> Parser (Maybe (ListMap (Credential 'Staking) Delegatee))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"delegs" Parser (Maybe (ListMap (Credential 'Staking) Delegatee))
-> ListMap (Credential 'Staking) Delegatee
-> Parser (ListMap (Credential 'Staking) Delegatee)
forall a. Parser (Maybe a) -> a -> Parser a
.!= ListMap (Credential 'Staking) Delegatee
forall a. Monoid a => a
mempty
        Parser (ListMap (Credential 'DRepRole) DRepState -> ConwayGenesis)
-> Parser (ListMap (Credential 'DRepRole) DRepState)
-> Parser ConwayGenesis
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object
-> Key -> Parser (Maybe (ListMap (Credential 'DRepRole) DRepState))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"initialDReps" Parser (Maybe (ListMap (Credential 'DRepRole) DRepState))
-> ListMap (Credential 'DRepRole) DRepState
-> Parser (ListMap (Credential 'DRepRole) DRepState)
forall a. Parser (Maybe a) -> a -> Parser a
.!= ListMap (Credential 'DRepRole) DRepState
forall a. Monoid a => a
mempty

toConwayGenesisPairs :: KeyValue e a => ConwayGenesis -> [a]
toConwayGenesisPairs :: forall e a. KeyValue e a => ConwayGenesis -> [a]
toConwayGenesisPairs cg :: ConwayGenesis
cg@(ConwayGenesis UpgradeConwayPParams Identity
_ Constitution ConwayEra
_ Committee ConwayEra
_ ListMap (Credential 'Staking) Delegatee
_ ListMap (Credential 'DRepRole) DRepState
_) =
  let ConwayGenesis {ListMap (Credential 'Staking) Delegatee
ListMap (Credential 'DRepRole) DRepState
Constitution ConwayEra
Committee ConwayEra
UpgradeConwayPParams Identity
cgUpgradePParams :: ConwayGenesis -> UpgradeConwayPParams Identity
cgConstitution :: ConwayGenesis -> Constitution ConwayEra
cgCommittee :: ConwayGenesis -> Committee ConwayEra
cgDelegs :: ConwayGenesis -> ListMap (Credential 'Staking) Delegatee
cgInitialDReps :: ConwayGenesis -> ListMap (Credential 'DRepRole) DRepState
cgUpgradePParams :: UpgradeConwayPParams Identity
cgConstitution :: Constitution ConwayEra
cgCommittee :: Committee ConwayEra
cgDelegs :: ListMap (Credential 'Staking) Delegatee
cgInitialDReps :: ListMap (Credential 'DRepRole) DRepState
..} = ConwayGenesis
cg
   in [ Key
"constitution" Key -> Constitution ConwayEra -> a
forall v. ToJSON v => Key -> v -> a
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Constitution ConwayEra
cgConstitution
      , Key
"committee" Key -> Committee ConwayEra -> a
forall v. ToJSON v => Key -> v -> a
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Committee ConwayEra
cgCommittee
      ]
        [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ [Key
"delegs" Key -> ListMap (Credential 'Staking) Delegatee -> a
forall v. ToJSON v => Key -> v -> a
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= ListMap (Credential 'Staking) Delegatee
cgDelegs | Bool -> Bool
not (ListMap (Credential 'Staking) Delegatee -> Bool
forall a. ListMap (Credential 'Staking) a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ListMap (Credential 'Staking) Delegatee
cgDelegs)]
        [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ [Key
"initialDReps" Key -> ListMap (Credential 'DRepRole) DRepState -> a
forall v. ToJSON v => Key -> v -> a
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= ListMap (Credential 'DRepRole) DRepState
cgInitialDReps | Bool -> Bool
not (ListMap (Credential 'DRepRole) DRepState -> Bool
forall a. ListMap (Credential 'DRepRole) a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ListMap (Credential 'DRepRole) DRepState
cgInitialDReps)]
        [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ UpgradeConwayPParams Identity -> [a]
forall e a. KeyValue e a => UpgradeConwayPParams Identity -> [a]
toUpgradeConwayPParamsUpdatePairs UpgradeConwayPParams Identity
cgUpgradePParams