{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}

-- | This module contains just the type of protocol parameters.
module Cardano.Ledger.Shelley.PParams (
  emptyShelleyPParams,
  emptyShelleyPParamsUpdate,
  ShelleyPParams (..),
  emptyPParams,
  HKD,
  PPUpdateEnv (..),
  ProposedPPUpdates (..),
  emptyPPPUpdates,
  Update (..),
  pvCanFollow,
  hasLegalProtVerUpdate,

  -- * JSON helpers
  shelleyCommonPParamsHKDPairs,
  shelleyCommonPParamsHKDPairsV6,
  shelleyCommonPParamsHKDPairsV8,

  -- * Deprecated
  updatePParams,
  upgradeUpdate,
)
where

import Cardano.Ledger.BaseTypes (
  EpochInterval (..),
  NonNegativeInterval,
  Nonce (NeutralNonce),
  ProtVer (..),
  StrictMaybe (..),
  UnitInterval,
  invalidKey,
  strictMaybeToMaybe,
  succVersion,
 )
import Cardano.Ledger.Binary (
  DecCBOR (..),
  DecCBORGroup (..),
  EncCBOR (..),
  EncCBORGroup (..),
  FromCBOR (..),
  ToCBOR (..),
  decodeMapContents,
  decodeRecordNamed,
  decodeWord,
  encodeListLen,
  encodeMapLen,
  encodeWord,
 )
import Cardano.Ledger.Binary.Coders (Decode (From, RecD), decode, (<!))
import Cardano.Ledger.Coin (Coin (..))
import Cardano.Ledger.Core
import Cardano.Ledger.Crypto
import Cardano.Ledger.HKD (HKD, HKDFunctor (..))
import Cardano.Ledger.Keys (GenDelegs, KeyHash, KeyRole (..))
import Cardano.Ledger.Orphans ()
import Cardano.Ledger.Shelley.Era (ShelleyEra)
import Cardano.Ledger.Slot (EpochNo (..), SlotNo (..))
import Control.DeepSeq (NFData)
import Control.Monad (unless)
import Data.Aeson (
  FromJSON (..),
  Key,
  KeyValue,
  ToJSON (..),
  object,
  pairs,
  (.!=),
  (.:),
  (.:?),
  (.=),
 )
import qualified Data.Aeson as Aeson
import Data.Foldable (fold)
import Data.Functor.Identity (Identity)
import Data.List (nub)
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Maybe (mapMaybe)
import Data.Proxy
import Data.Void
import Data.Word (Word16, Word32)
import GHC.Generics (Generic)
import Lens.Micro (lens, (^.))
import NoThunks.Class (NoThunks (..))
import Numeric.Natural (Natural)

-- ====================================================================

-- | Protocol parameters.
data ShelleyPParams f era = ShelleyPParams
  { forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Coin
sppMinFeeA :: !(HKD f Coin)
  -- ^ The linear factor for the minimum fee calculation
  , forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Coin
sppMinFeeB :: !(HKD f Coin)
  -- ^ The constant factor for the minimum fee calculation
  , forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Word32
sppMaxBBSize :: !(HKD f Word32)
  -- ^ Maximal block body size
  , forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Word32
sppMaxTxSize :: !(HKD f Word32)
  -- ^ Maximal transaction size
  , forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Word16
sppMaxBHSize :: !(HKD f Word16)
  -- ^ Maximal block header size
  , forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Coin
sppKeyDeposit :: !(HKD f Coin)
  -- ^ The amount of a key registration deposit
  , forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Coin
sppPoolDeposit :: !(HKD f Coin)
  -- ^ The amount of a pool registration deposit
  , forall (f :: * -> *) era.
ShelleyPParams f era -> HKD f EpochInterval
sppEMax :: !(HKD f EpochInterval)
  -- ^ epoch bound on pool retirement
  , forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Natural
sppNOpt :: !(HKD f Natural)
  -- ^ Desired number of pools
  , forall (f :: * -> *) era.
ShelleyPParams f era -> HKD f NonNegativeInterval
sppA0 :: !(HKD f NonNegativeInterval)
  -- ^ Pool influence
  , forall (f :: * -> *) era.
ShelleyPParams f era -> HKD f UnitInterval
sppRho :: !(HKD f UnitInterval)
  -- ^ Monetary expansion
  , forall (f :: * -> *) era.
ShelleyPParams f era -> HKD f UnitInterval
sppTau :: !(HKD f UnitInterval)
  -- ^ Treasury expansion
  , forall (f :: * -> *) era.
ShelleyPParams f era -> HKD f UnitInterval
sppD :: !(HKD f UnitInterval)
  -- ^ Decentralization parameter
  , forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Nonce
sppExtraEntropy :: !(HKD f Nonce)
  -- ^ Extra entropy
  , forall (f :: * -> *) era. ShelleyPParams f era -> HKD f ProtVer
sppProtocolVersion :: !(HKD f ProtVer)
  -- ^ Protocol version
  , forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Coin
sppMinUTxOValue :: !(HKD f Coin)
  -- ^ Minimum UTxO value
  , forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Coin
sppMinPoolCost :: !(HKD f Coin)
  -- ^ Minimum Stake Pool Cost
  }
  deriving (forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (f :: * -> *) era x.
Rep (ShelleyPParams f era) x -> ShelleyPParams f era
forall (f :: * -> *) era x.
ShelleyPParams f era -> Rep (ShelleyPParams f era) x
$cto :: forall (f :: * -> *) era x.
Rep (ShelleyPParams f era) x -> ShelleyPParams f era
$cfrom :: forall (f :: * -> *) era x.
ShelleyPParams f era -> Rep (ShelleyPParams f era) x
Generic)

deriving instance Eq (ShelleyPParams Identity era)

deriving instance Ord (ShelleyPParams Identity era)

deriving instance Show (ShelleyPParams Identity era)

instance NoThunks (ShelleyPParams Identity era)

instance NFData (ShelleyPParams Identity era)

deriving instance Eq (ShelleyPParams StrictMaybe era)

deriving instance Ord (ShelleyPParams StrictMaybe era)

deriving instance Show (ShelleyPParams StrictMaybe era)

instance NoThunks (ShelleyPParams StrictMaybe era)

instance NFData (ShelleyPParams StrictMaybe era)

instance Crypto c => EraPParams (ShelleyEra c) where
  type PParamsHKD f (ShelleyEra c) = ShelleyPParams f (ShelleyEra c)

  type UpgradePParams f (ShelleyEra c) = Void
  type DowngradePParams f (ShelleyEra c) = Void

  emptyPParamsIdentity :: PParamsHKD Identity (ShelleyEra c)
emptyPParamsIdentity = forall era. Era era => ShelleyPParams Identity era
emptyShelleyPParams
  emptyPParamsStrictMaybe :: PParamsHKD StrictMaybe (ShelleyEra c)
emptyPParamsStrictMaybe = forall era. ShelleyPParams StrictMaybe era
emptyShelleyPParamsUpdate

  -- These two functions are impossible for two reasons:
  -- 1. Upgrade/DowngradePParams are Void
  -- 2. ByronEra does not have an instance for EraPParams
  --
  -- Using either one of these two functions with ShelleyEra will result in a build error:
  upgradePParamsHKD :: forall (f :: * -> *).
(HKDApplicative f, EraPParams (PreviousEra (ShelleyEra c))) =>
UpgradePParams f (ShelleyEra c)
-> PParamsHKD f (PreviousEra (ShelleyEra c))
-> PParamsHKD f (ShelleyEra c)
upgradePParamsHKD = forall a. HasCallStack => String -> a
error String
"IMPOSSIBLE! There cannot be PParams that can be upgraded to Shelley"
  downgradePParamsHKD :: forall (f :: * -> *).
(HKDFunctor f, EraPParams (PreviousEra (ShelleyEra c))) =>
DowngradePParams f (ShelleyEra c)
-> PParamsHKD f (ShelleyEra c)
-> PParamsHKD f (PreviousEra (ShelleyEra c))
downgradePParamsHKD = forall a. HasCallStack => String -> a
error String
"IMPOSSIBLE! There cannot be PParams that can be downgraded from Shelley"

  hkdMinFeeAL :: forall (f :: * -> *).
HKDFunctor f =>
Lens' (PParamsHKD f (ShelleyEra c)) (HKD f Coin)
hkdMinFeeAL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Coin
sppMinFeeA forall a b. (a -> b) -> a -> b
$ \PParamsHKD f (ShelleyEra c)
pp HKD f Coin
x -> PParamsHKD f (ShelleyEra c)
pp {sppMinFeeA :: HKD f Coin
sppMinFeeA = HKD f Coin
x}
  hkdMinFeeBL :: forall (f :: * -> *).
HKDFunctor f =>
Lens' (PParamsHKD f (ShelleyEra c)) (HKD f Coin)
hkdMinFeeBL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Coin
sppMinFeeB forall a b. (a -> b) -> a -> b
$ \PParamsHKD f (ShelleyEra c)
pp HKD f Coin
x -> PParamsHKD f (ShelleyEra c)
pp {sppMinFeeB :: HKD f Coin
sppMinFeeB = HKD f Coin
x}
  hkdMaxBBSizeL :: forall (f :: * -> *).
HKDFunctor f =>
Lens' (PParamsHKD f (ShelleyEra c)) (HKD f Word32)
hkdMaxBBSizeL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Word32
sppMaxBBSize forall a b. (a -> b) -> a -> b
$ \PParamsHKD f (ShelleyEra c)
pp HKD f Word32
x -> PParamsHKD f (ShelleyEra c)
pp {sppMaxBBSize :: HKD f Word32
sppMaxBBSize = HKD f Word32
x}
  hkdMaxTxSizeL :: forall (f :: * -> *).
HKDFunctor f =>
Lens' (PParamsHKD f (ShelleyEra c)) (HKD f Word32)
hkdMaxTxSizeL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Word32
sppMaxTxSize forall a b. (a -> b) -> a -> b
$ \PParamsHKD f (ShelleyEra c)
pp HKD f Word32
x -> PParamsHKD f (ShelleyEra c)
pp {sppMaxTxSize :: HKD f Word32
sppMaxTxSize = HKD f Word32
x}
  hkdMaxBHSizeL :: forall (f :: * -> *).
HKDFunctor f =>
Lens' (PParamsHKD f (ShelleyEra c)) (HKD f Word16)
hkdMaxBHSizeL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Word16
sppMaxBHSize forall a b. (a -> b) -> a -> b
$ \PParamsHKD f (ShelleyEra c)
pp HKD f Word16
x -> PParamsHKD f (ShelleyEra c)
pp {sppMaxBHSize :: HKD f Word16
sppMaxBHSize = HKD f Word16
x}
  hkdKeyDepositL :: forall (f :: * -> *).
HKDFunctor f =>
Lens' (PParamsHKD f (ShelleyEra c)) (HKD f Coin)
hkdKeyDepositL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Coin
sppKeyDeposit forall a b. (a -> b) -> a -> b
$ \PParamsHKD f (ShelleyEra c)
pp HKD f Coin
x -> PParamsHKD f (ShelleyEra c)
pp {sppKeyDeposit :: HKD f Coin
sppKeyDeposit = HKD f Coin
x}
  hkdPoolDepositL :: forall (f :: * -> *).
HKDFunctor f =>
Lens' (PParamsHKD f (ShelleyEra c)) (HKD f Coin)
hkdPoolDepositL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Coin
sppPoolDeposit forall a b. (a -> b) -> a -> b
$ \PParamsHKD f (ShelleyEra c)
pp HKD f Coin
x -> PParamsHKD f (ShelleyEra c)
pp {sppPoolDeposit :: HKD f Coin
sppPoolDeposit = HKD f Coin
x}
  hkdEMaxL :: forall (f :: * -> *).
HKDFunctor f =>
Lens' (PParamsHKD f (ShelleyEra c)) (HKD f EpochInterval)
hkdEMaxL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens forall (f :: * -> *) era.
ShelleyPParams f era -> HKD f EpochInterval
sppEMax forall a b. (a -> b) -> a -> b
$ \PParamsHKD f (ShelleyEra c)
pp HKD f EpochInterval
x -> PParamsHKD f (ShelleyEra c)
pp {sppEMax :: HKD f EpochInterval
sppEMax = HKD f EpochInterval
x}
  hkdNOptL :: forall (f :: * -> *).
HKDFunctor f =>
Lens' (PParamsHKD f (ShelleyEra c)) (HKD f Natural)
hkdNOptL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Natural
sppNOpt forall a b. (a -> b) -> a -> b
$ \PParamsHKD f (ShelleyEra c)
pp HKD f Natural
x -> PParamsHKD f (ShelleyEra c)
pp {sppNOpt :: HKD f Natural
sppNOpt = HKD f Natural
x}
  hkdA0L :: forall (f :: * -> *).
HKDFunctor f =>
Lens' (PParamsHKD f (ShelleyEra c)) (HKD f NonNegativeInterval)
hkdA0L = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens forall (f :: * -> *) era.
ShelleyPParams f era -> HKD f NonNegativeInterval
sppA0 forall a b. (a -> b) -> a -> b
$ \PParamsHKD f (ShelleyEra c)
pp HKD f NonNegativeInterval
x -> PParamsHKD f (ShelleyEra c)
pp {sppA0 :: HKD f NonNegativeInterval
sppA0 = HKD f NonNegativeInterval
x}
  hkdRhoL :: forall (f :: * -> *).
HKDFunctor f =>
Lens' (PParamsHKD f (ShelleyEra c)) (HKD f UnitInterval)
hkdRhoL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens forall (f :: * -> *) era.
ShelleyPParams f era -> HKD f UnitInterval
sppRho forall a b. (a -> b) -> a -> b
$ \PParamsHKD f (ShelleyEra c)
pp HKD f UnitInterval
x -> PParamsHKD f (ShelleyEra c)
pp {sppRho :: HKD f UnitInterval
sppRho = HKD f UnitInterval
x}
  hkdTauL :: forall (f :: * -> *).
HKDFunctor f =>
Lens' (PParamsHKD f (ShelleyEra c)) (HKD f UnitInterval)
hkdTauL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens forall (f :: * -> *) era.
ShelleyPParams f era -> HKD f UnitInterval
sppTau forall a b. (a -> b) -> a -> b
$ \PParamsHKD f (ShelleyEra c)
pp HKD f UnitInterval
x -> PParamsHKD f (ShelleyEra c)
pp {sppTau :: HKD f UnitInterval
sppTau = HKD f UnitInterval
x}
  hkdDL :: forall (f :: * -> *).
(HKDFunctor f, ProtVerAtMost (ShelleyEra c) 6) =>
Lens' (PParamsHKD f (ShelleyEra c)) (HKD f UnitInterval)
hkdDL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens forall (f :: * -> *) era.
ShelleyPParams f era -> HKD f UnitInterval
sppD forall a b. (a -> b) -> a -> b
$ \PParamsHKD f (ShelleyEra c)
pp HKD f UnitInterval
x -> PParamsHKD f (ShelleyEra c)
pp {sppD :: HKD f UnitInterval
sppD = HKD f UnitInterval
x}
  hkdExtraEntropyL :: forall (f :: * -> *).
(HKDFunctor f, ProtVerAtMost (ShelleyEra c) 6) =>
Lens' (PParamsHKD f (ShelleyEra c)) (HKD f Nonce)
hkdExtraEntropyL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Nonce
sppExtraEntropy forall a b. (a -> b) -> a -> b
$ \PParamsHKD f (ShelleyEra c)
pp HKD f Nonce
x -> PParamsHKD f (ShelleyEra c)
pp {sppExtraEntropy :: HKD f Nonce
sppExtraEntropy = HKD f Nonce
x}
  hkdProtocolVersionL :: forall (f :: * -> *).
(HKDFunctor f, ProtVerAtMost (ShelleyEra c) 8) =>
Lens' (PParamsHKD f (ShelleyEra c)) (HKD f ProtVer)
hkdProtocolVersionL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens forall (f :: * -> *) era. ShelleyPParams f era -> HKD f ProtVer
sppProtocolVersion forall a b. (a -> b) -> a -> b
$ \PParamsHKD f (ShelleyEra c)
pp HKD f ProtVer
x -> PParamsHKD f (ShelleyEra c)
pp {sppProtocolVersion :: HKD f ProtVer
sppProtocolVersion = HKD f ProtVer
x}
  hkdMinUTxOValueL :: forall (f :: * -> *).
(HKDFunctor f, ProtVerAtMost (ShelleyEra c) 4) =>
Lens' (PParamsHKD f (ShelleyEra c)) (HKD f Coin)
hkdMinUTxOValueL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Coin
sppMinUTxOValue forall a b. (a -> b) -> a -> b
$ \PParamsHKD f (ShelleyEra c)
pp HKD f Coin
x -> PParamsHKD f (ShelleyEra c)
pp {sppMinUTxOValue :: HKD f Coin
sppMinUTxOValue = HKD f Coin
x}
  hkdMinPoolCostL :: forall (f :: * -> *).
HKDFunctor f =>
Lens' (PParamsHKD f (ShelleyEra c)) (HKD f Coin)
hkdMinPoolCostL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Coin
sppMinPoolCost forall a b. (a -> b) -> a -> b
$ \PParamsHKD f (ShelleyEra c)
pp HKD f Coin
x -> PParamsHKD f (ShelleyEra c)
pp {sppMinPoolCost :: HKD f Coin
sppMinPoolCost = HKD f Coin
x}

instance Era era => EncCBOR (ShelleyPParams Identity era) where
  encCBOR :: ShelleyPParams Identity era -> Encoding
encCBOR
    ShelleyPParams {HKD Identity Natural
HKD Identity Word16
HKD Identity Word32
HKD Identity Coin
HKD Identity ProtVer
HKD Identity NonNegativeInterval
HKD Identity UnitInterval
HKD Identity Nonce
HKD Identity EpochInterval
sppMinPoolCost :: HKD Identity Coin
sppMinUTxOValue :: HKD Identity Coin
sppProtocolVersion :: HKD Identity ProtVer
sppExtraEntropy :: HKD Identity Nonce
sppD :: HKD Identity UnitInterval
sppTau :: HKD Identity UnitInterval
sppRho :: HKD Identity UnitInterval
sppA0 :: HKD Identity NonNegativeInterval
sppNOpt :: HKD Identity Natural
sppEMax :: HKD Identity EpochInterval
sppPoolDeposit :: HKD Identity Coin
sppKeyDeposit :: HKD Identity Coin
sppMaxBHSize :: HKD Identity Word16
sppMaxTxSize :: HKD Identity Word32
sppMaxBBSize :: HKD Identity Word32
sppMinFeeB :: HKD Identity Coin
sppMinFeeA :: HKD Identity Coin
sppMinPoolCost :: forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Coin
sppMinUTxOValue :: forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Coin
sppProtocolVersion :: forall (f :: * -> *) era. ShelleyPParams f era -> HKD f ProtVer
sppExtraEntropy :: forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Nonce
sppD :: forall (f :: * -> *) era.
ShelleyPParams f era -> HKD f UnitInterval
sppTau :: forall (f :: * -> *) era.
ShelleyPParams f era -> HKD f UnitInterval
sppRho :: forall (f :: * -> *) era.
ShelleyPParams f era -> HKD f UnitInterval
sppA0 :: forall (f :: * -> *) era.
ShelleyPParams f era -> HKD f NonNegativeInterval
sppNOpt :: forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Natural
sppEMax :: forall (f :: * -> *) era.
ShelleyPParams f era -> HKD f EpochInterval
sppPoolDeposit :: forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Coin
sppKeyDeposit :: forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Coin
sppMaxBHSize :: forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Word16
sppMaxTxSize :: forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Word32
sppMaxBBSize :: forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Word32
sppMinFeeB :: forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Coin
sppMinFeeA :: forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Coin
..} =
      Word -> Encoding
encodeListLen Word
18
        forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR HKD Identity Coin
sppMinFeeA
        forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR HKD Identity Coin
sppMinFeeB
        forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR HKD Identity Word32
sppMaxBBSize
        forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR HKD Identity Word32
sppMaxTxSize
        forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR HKD Identity Word16
sppMaxBHSize
        forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR HKD Identity Coin
sppKeyDeposit
        forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR HKD Identity Coin
sppPoolDeposit
        forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR HKD Identity EpochInterval
sppEMax
        forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR HKD Identity Natural
sppNOpt
        forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR HKD Identity NonNegativeInterval
sppA0
        forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR HKD Identity UnitInterval
sppRho
        forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR HKD Identity UnitInterval
sppTau
        forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR HKD Identity UnitInterval
sppD
        forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR HKD Identity Nonce
sppExtraEntropy
        forall a. Semigroup a => a -> a -> a
<> forall a. EncCBORGroup a => a -> Encoding
encCBORGroup HKD Identity ProtVer
sppProtocolVersion
        forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR HKD Identity Coin
sppMinUTxOValue
        forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR HKD Identity Coin
sppMinPoolCost

instance Era era => DecCBOR (ShelleyPParams Identity era) where
  decCBOR :: forall s. Decoder s (ShelleyPParams Identity era)
decCBOR = do
    forall a s. Text -> (a -> Int) -> Decoder s a -> Decoder s a
decodeRecordNamed Text
"ShelleyPParams" (forall a b. a -> b -> a
const Int
18) forall a b. (a -> b) -> a -> b
$
      forall (f :: * -> *) era.
HKD f Coin
-> HKD f Coin
-> HKD f Word32
-> HKD f Word32
-> HKD f Word16
-> HKD f Coin
-> HKD f Coin
-> HKD f EpochInterval
-> HKD f Natural
-> HKD f NonNegativeInterval
-> HKD f UnitInterval
-> HKD f UnitInterval
-> HKD f UnitInterval
-> HKD f Nonce
-> HKD f ProtVer
-> HKD f Coin
-> HKD f Coin
-> ShelleyPParams f era
ShelleyPParams @Identity
        forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a s. DecCBOR a => Decoder s a
decCBOR -- sppMinFeeA         :: Integer
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a s. DecCBOR a => Decoder s a
decCBOR -- sppMinFeeB         :: Natural
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a s. DecCBOR a => Decoder s a
decCBOR -- sppMaxBBSize       :: Natural
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a s. DecCBOR a => Decoder s a
decCBOR -- sppMaxTxSize       :: Natural
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a s. DecCBOR a => Decoder s a
decCBOR -- sppMaxBHSize       :: Natural
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a s. DecCBOR a => Decoder s a
decCBOR -- sppKeyDeposit      :: Coin
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a s. DecCBOR a => Decoder s a
decCBOR -- sppPoolDeposit     :: Coin
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a s. DecCBOR a => Decoder s a
decCBOR -- sppEMax            :: EpochNo
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a s. DecCBOR a => Decoder s a
decCBOR -- sppNOpt            :: Natural
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a s. DecCBOR a => Decoder s a
decCBOR -- sppA0              :: NonNegativeInterval
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a s. DecCBOR a => Decoder s a
decCBOR -- sppRho             :: UnitInterval
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a s. DecCBOR a => Decoder s a
decCBOR -- sppTau             :: UnitInterval
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a s. DecCBOR a => Decoder s a
decCBOR -- sppD               :: UnitInterval
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a s. DecCBOR a => Decoder s a
decCBOR -- sppExtraEntropy    :: Nonce
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a s. DecCBORGroup a => Decoder s a
decCBORGroup -- sppProtocolVersion :: ProtVer
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a s. DecCBOR a => Decoder s a
decCBOR -- sppMinUTxOValue    :: Natural
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a s. DecCBOR a => Decoder s a
decCBOR -- sppMinPoolCost     :: Natural

instance Era era => ToCBOR (ShelleyPParams Identity era) where
  toCBOR :: ShelleyPParams Identity era -> Encoding
toCBOR = forall era t. (Era era, EncCBOR t) => t -> Encoding
toEraCBOR @era

instance Era era => FromCBOR (ShelleyPParams Identity era) where
  fromCBOR :: forall s. Decoder s (ShelleyPParams Identity era)
fromCBOR = forall era t s. (Era era, DecCBOR t) => Decoder s t
fromEraCBOR @era

instance
  ( EraPParams era
  , PParamsHKD Identity era ~ ShelleyPParams Identity era
  , ProtVerAtMost era 4
  , ProtVerAtMost era 6
  , ProtVerAtMost era 8
  ) =>
  ToJSON (ShelleyPParams Identity era)
  where
  toJSON :: ShelleyPParams Identity era -> Value
toJSON = [Pair] -> Value
object forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era a e.
(EraPParams era, ProtVerAtMost era 4, ProtVerAtMost era 6,
 ProtVerAtMost era 8, KeyValue e a) =>
PParamsHKD Identity era -> [a]
shelleyPParamsPairs
  toEncoding :: ShelleyPParams Identity era -> Encoding
toEncoding = Series -> Encoding
pairs forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era a e.
(EraPParams era, ProtVerAtMost era 4, ProtVerAtMost era 6,
 ProtVerAtMost era 8, KeyValue e a) =>
PParamsHKD Identity era -> [a]
shelleyPParamsPairs

shelleyPParamsPairs ::
  forall era a e.
  (EraPParams era, ProtVerAtMost era 4, ProtVerAtMost era 6, ProtVerAtMost era 8, KeyValue e a) =>
  PParamsHKD Identity era ->
  [a]
shelleyPParamsPairs :: forall era a e.
(EraPParams era, ProtVerAtMost era 4, ProtVerAtMost era 6,
 ProtVerAtMost era 8, KeyValue e a) =>
PParamsHKD Identity era -> [a]
shelleyPParamsPairs PParamsHKD Identity era
pp =
  forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
(.=)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (f :: * -> *) era.
(HKDFunctor f, EraPParams era, ProtVerAtMost era 4,
 ProtVerAtMost era 6, ProtVerAtMost era 8) =>
Proxy f -> PParamsHKD f era -> [(Key, HKD f Value)]
shelleyPParamsHKDPairs (forall {k} (t :: k). Proxy t
Proxy @Identity) PParamsHKD Identity era
pp

instance FromJSON (ShelleyPParams Identity era) where
  parseJSON :: Value -> Parser (ShelleyPParams Identity era)
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"ShelleyPParams" forall a b. (a -> b) -> a -> b
$ \Object
obj -> do
      forall (f :: * -> *) era.
HKD f Coin
-> HKD f Coin
-> HKD f Word32
-> HKD f Word32
-> HKD f Word16
-> HKD f Coin
-> HKD f Coin
-> HKD f EpochInterval
-> HKD f Natural
-> HKD f NonNegativeInterval
-> HKD f UnitInterval
-> HKD f UnitInterval
-> HKD f UnitInterval
-> HKD f Nonce
-> HKD f ProtVer
-> HKD f Coin
-> HKD f Coin
-> ShelleyPParams f era
ShelleyPParams
        forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"txFeePerByte"
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"txFeeFixed"
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"maxBlockBodySize"
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"maxTxSize"
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"maxBlockHeaderSize"
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"stakeAddressDeposit"
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"stakePoolDeposit"
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"poolRetireMaxEpoch"
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"stakePoolTargetNum"
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"poolPledgeInfluence"
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"monetaryExpansion"
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"treasuryCut"
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"decentralization"
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"extraPraosEntropy"
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"protocolVersion"
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"minUTxOValue" forall a. Parser (Maybe a) -> a -> Parser a
.!= forall a. Monoid a => a
mempty
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"minPoolCost" forall a. Parser (Maybe a) -> a -> Parser a
.!= forall a. Monoid a => a
mempty

emptyShelleyPParams :: forall era. Era era => ShelleyPParams Identity era
emptyShelleyPParams :: forall era. Era era => ShelleyPParams Identity era
emptyShelleyPParams =
  ShelleyPParams
    { sppMinFeeA :: HKD Identity Coin
sppMinFeeA = Integer -> Coin
Coin Integer
0
    , sppMinFeeB :: HKD Identity Coin
sppMinFeeB = Integer -> Coin
Coin Integer
0
    , sppMaxBBSize :: HKD Identity Word32
sppMaxBBSize = Word32
0
    , sppMaxTxSize :: HKD Identity Word32
sppMaxTxSize = Word32
2048
    , sppMaxBHSize :: HKD Identity Word16
sppMaxBHSize = Word16
0
    , sppKeyDeposit :: HKD Identity Coin
sppKeyDeposit = Integer -> Coin
Coin Integer
0
    , sppPoolDeposit :: HKD Identity Coin
sppPoolDeposit = Integer -> Coin
Coin Integer
0
    , sppEMax :: HKD Identity EpochInterval
sppEMax = Word32 -> EpochInterval
EpochInterval Word32
0
    , sppNOpt :: HKD Identity Natural
sppNOpt = Natural
100
    , sppA0 :: HKD Identity NonNegativeInterval
sppA0 = forall a. Bounded a => a
minBound
    , sppRho :: HKD Identity UnitInterval
sppRho = forall a. Bounded a => a
minBound
    , sppTau :: HKD Identity UnitInterval
sppTau = forall a. Bounded a => a
minBound
    , sppD :: HKD Identity UnitInterval
sppD = forall a. Bounded a => a
minBound
    , sppExtraEntropy :: HKD Identity Nonce
sppExtraEntropy = Nonce
NeutralNonce
    , sppProtocolVersion :: HKD Identity ProtVer
sppProtocolVersion = Version -> Natural -> ProtVer
ProtVer (forall era. Era era => Version
eraProtVerLow @era) Natural
0
    , sppMinUTxOValue :: HKD Identity Coin
sppMinUTxOValue = forall a. Monoid a => a
mempty
    , sppMinPoolCost :: HKD Identity Coin
sppMinPoolCost = forall a. Monoid a => a
mempty
    }

emptyShelleyPParamsUpdate :: ShelleyPParams StrictMaybe era
emptyShelleyPParamsUpdate :: forall era. ShelleyPParams StrictMaybe era
emptyShelleyPParamsUpdate =
  ShelleyPParams
    { sppMinFeeA :: HKD StrictMaybe Coin
sppMinFeeA = forall a. StrictMaybe a
SNothing
    , sppMinFeeB :: HKD StrictMaybe Coin
sppMinFeeB = forall a. StrictMaybe a
SNothing
    , sppMaxBBSize :: HKD StrictMaybe Word32
sppMaxBBSize = forall a. StrictMaybe a
SNothing
    , sppMaxTxSize :: HKD StrictMaybe Word32
sppMaxTxSize = forall a. StrictMaybe a
SNothing
    , sppMaxBHSize :: HKD StrictMaybe Word16
sppMaxBHSize = forall a. StrictMaybe a
SNothing
    , sppKeyDeposit :: HKD StrictMaybe Coin
sppKeyDeposit = forall a. StrictMaybe a
SNothing
    , sppPoolDeposit :: HKD StrictMaybe Coin
sppPoolDeposit = forall a. StrictMaybe a
SNothing
    , sppEMax :: HKD StrictMaybe EpochInterval
sppEMax = forall a. StrictMaybe a
SNothing
    , sppNOpt :: HKD StrictMaybe Natural
sppNOpt = forall a. StrictMaybe a
SNothing
    , sppA0 :: HKD StrictMaybe NonNegativeInterval
sppA0 = forall a. StrictMaybe a
SNothing
    , sppRho :: HKD StrictMaybe UnitInterval
sppRho = forall a. StrictMaybe a
SNothing
    , sppTau :: HKD StrictMaybe UnitInterval
sppTau = forall a. StrictMaybe a
SNothing
    , sppD :: HKD StrictMaybe UnitInterval
sppD = forall a. StrictMaybe a
SNothing
    , sppExtraEntropy :: HKD StrictMaybe Nonce
sppExtraEntropy = forall a. StrictMaybe a
SNothing
    , sppProtocolVersion :: HKD StrictMaybe ProtVer
sppProtocolVersion = forall a. StrictMaybe a
SNothing
    , sppMinUTxOValue :: HKD StrictMaybe Coin
sppMinUTxOValue = forall a. StrictMaybe a
SNothing
    , sppMinPoolCost :: HKD StrictMaybe Coin
sppMinPoolCost = forall a. StrictMaybe a
SNothing
    }

-- | Update Proposal
data Update era
  = Update !(ProposedPPUpdates era) !EpochNo
  deriving (forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall era x. Rep (Update era) x -> Update era
forall era x. Update era -> Rep (Update era) x
$cto :: forall era x. Rep (Update era) x -> Update era
$cfrom :: forall era x. Update era -> Rep (Update era) x
Generic)

deriving instance Eq (PParamsUpdate era) => Eq (Update era)

instance NFData (PParamsUpdate era) => NFData (Update era)

deriving instance Show (PParamsUpdate era) => Show (Update era)

instance NoThunks (PParamsUpdate era) => NoThunks (Update era)

instance (Era era, EncCBOR (PParamsUpdate era)) => EncCBOR (Update era) where
  encCBOR :: Update era -> Encoding
encCBOR (Update ProposedPPUpdates era
ppUpdate EpochNo
e) =
    Word -> Encoding
encodeListLen Word
2 forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR ProposedPPUpdates era
ppUpdate forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR EpochNo
e

instance
  (Era era, DecCBOR (PParamsUpdate era)) =>
  DecCBOR (Update era)
  where
  decCBOR :: forall s. Decoder s (Update era)
decCBOR = forall (w :: Wrapped) t s. Decode w t -> Decoder s t
decode forall a b. (a -> b) -> a -> b
$ forall t. t -> Decode ('Closed 'Dense) t
RecD forall era. ProposedPPUpdates era -> EpochNo -> Update era
Update forall (w1 :: Wrapped) a t (w :: Density).
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! forall t (w :: Wrapped). DecCBOR t => Decode w t
From forall (w1 :: Wrapped) a t (w :: Density).
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! forall t (w :: Wrapped). DecCBOR t => Decode w t
From

data PPUpdateEnv era = PPUpdateEnv SlotNo (GenDelegs era)
  deriving (Int -> PPUpdateEnv era -> ShowS
forall era. Int -> PPUpdateEnv era -> ShowS
forall era. [PPUpdateEnv era] -> ShowS
forall era. PPUpdateEnv era -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PPUpdateEnv era] -> ShowS
$cshowList :: forall era. [PPUpdateEnv era] -> ShowS
show :: PPUpdateEnv era -> String
$cshow :: forall era. PPUpdateEnv era -> String
showsPrec :: Int -> PPUpdateEnv era -> ShowS
$cshowsPrec :: forall era. Int -> PPUpdateEnv era -> ShowS
Show, PPUpdateEnv era -> PPUpdateEnv era -> Bool
forall era. PPUpdateEnv era -> PPUpdateEnv era -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PPUpdateEnv era -> PPUpdateEnv era -> Bool
$c/= :: forall era. PPUpdateEnv era -> PPUpdateEnv era -> Bool
== :: PPUpdateEnv era -> PPUpdateEnv era -> Bool
$c== :: forall era. PPUpdateEnv era -> PPUpdateEnv era -> Bool
Eq, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall era x. Rep (PPUpdateEnv era) x -> PPUpdateEnv era
forall era x. PPUpdateEnv era -> Rep (PPUpdateEnv era) x
$cto :: forall era x. Rep (PPUpdateEnv era) x -> PPUpdateEnv era
$cfrom :: forall era x. PPUpdateEnv era -> Rep (PPUpdateEnv era) x
Generic)

instance NoThunks (PPUpdateEnv era)

instance Era era => EncCBOR (ShelleyPParams StrictMaybe era) where
  encCBOR :: ShelleyPParams StrictMaybe era -> Encoding
encCBOR ShelleyPParams StrictMaybe era
ppup =
    let l :: [Encoding]
l =
          forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe
            forall a. StrictMaybe a -> Maybe a
strictMaybeToMaybe
            [ forall {t}. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
0 forall a. EncCBOR a => a -> Encoding
encCBOR forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Coin
sppMinFeeA ShelleyPParams StrictMaybe era
ppup
            , forall {t}. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
1 forall a. EncCBOR a => a -> Encoding
encCBOR forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Coin
sppMinFeeB ShelleyPParams StrictMaybe era
ppup
            , forall {t}. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
2 forall a. EncCBOR a => a -> Encoding
encCBOR forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Word32
sppMaxBBSize ShelleyPParams StrictMaybe era
ppup
            , forall {t}. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
3 forall a. EncCBOR a => a -> Encoding
encCBOR forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Word32
sppMaxTxSize ShelleyPParams StrictMaybe era
ppup
            , forall {t}. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
4 forall a. EncCBOR a => a -> Encoding
encCBOR forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Word16
sppMaxBHSize ShelleyPParams StrictMaybe era
ppup
            , forall {t}. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
5 forall a. EncCBOR a => a -> Encoding
encCBOR forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Coin
sppKeyDeposit ShelleyPParams StrictMaybe era
ppup
            , forall {t}. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
6 forall a. EncCBOR a => a -> Encoding
encCBOR forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Coin
sppPoolDeposit ShelleyPParams StrictMaybe era
ppup
            , forall {t}. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
7 forall a. EncCBOR a => a -> Encoding
encCBOR forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (f :: * -> *) era.
ShelleyPParams f era -> HKD f EpochInterval
sppEMax ShelleyPParams StrictMaybe era
ppup
            , forall {t}. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
8 forall a. EncCBOR a => a -> Encoding
encCBOR forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Natural
sppNOpt ShelleyPParams StrictMaybe era
ppup
            , forall {t}. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
9 forall a. EncCBOR a => a -> Encoding
encCBOR forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (f :: * -> *) era.
ShelleyPParams f era -> HKD f NonNegativeInterval
sppA0 ShelleyPParams StrictMaybe era
ppup
            , forall {t}. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
10 forall a. EncCBOR a => a -> Encoding
encCBOR forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (f :: * -> *) era.
ShelleyPParams f era -> HKD f UnitInterval
sppRho ShelleyPParams StrictMaybe era
ppup
            , forall {t}. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
11 forall a. EncCBOR a => a -> Encoding
encCBOR forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (f :: * -> *) era.
ShelleyPParams f era -> HKD f UnitInterval
sppTau ShelleyPParams StrictMaybe era
ppup
            , forall {t}. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
12 forall a. EncCBOR a => a -> Encoding
encCBOR forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (f :: * -> *) era.
ShelleyPParams f era -> HKD f UnitInterval
sppD ShelleyPParams StrictMaybe era
ppup
            , forall {t}. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
13 forall a. EncCBOR a => a -> Encoding
encCBOR forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Nonce
sppExtraEntropy ShelleyPParams StrictMaybe era
ppup
            , forall {t}. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
14 forall a. EncCBOR a => a -> Encoding
encCBOR forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (f :: * -> *) era. ShelleyPParams f era -> HKD f ProtVer
sppProtocolVersion ShelleyPParams StrictMaybe era
ppup
            , forall {t}. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
15 forall a. EncCBOR a => a -> Encoding
encCBOR forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Coin
sppMinUTxOValue ShelleyPParams StrictMaybe era
ppup
            , forall {t}. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
16 forall a. EncCBOR a => a -> Encoding
encCBOR forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (f :: * -> *) era. ShelleyPParams f era -> HKD f Coin
sppMinPoolCost ShelleyPParams StrictMaybe era
ppup
            ]
        n :: Word
n = forall a b. (Integral a, Num b) => a -> b
fromIntegral forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t a -> Int
length [Encoding]
l
     in Word -> Encoding
encodeMapLen Word
n forall a. Semigroup a => a -> a -> a
<> forall (t :: * -> *) m. (Foldable t, Monoid m) => t m -> m
fold [Encoding]
l
    where
      encodeMapElement :: Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
i t -> Encoding
encoder t
x = forall a. a -> StrictMaybe a
SJust (Word -> Encoding
encodeWord Word
i forall a. Semigroup a => a -> a -> a
<> t -> Encoding
encoder t
x)

instance Era era => DecCBOR (ShelleyPParams StrictMaybe era) where
  decCBOR :: forall s. Decoder s (ShelleyPParams StrictMaybe era)
decCBOR = do
    [(Int,
  ShelleyPParams StrictMaybe era -> ShelleyPParams StrictMaybe era)]
mapParts <-
      forall s a. Decoder s a -> Decoder s [a]
decodeMapContents forall a b. (a -> b) -> a -> b
$
        forall s. Decoder s Word
decodeWord forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
          Word
0 -> forall a s. DecCBOR a => Decoder s a
decCBOR forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Coin
x -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
0, \ShelleyPParams StrictMaybe era
up -> ShelleyPParams StrictMaybe era
up {sppMinFeeA :: HKD StrictMaybe Coin
sppMinFeeA = forall a. a -> StrictMaybe a
SJust Coin
x})
          Word
1 -> forall a s. DecCBOR a => Decoder s a
decCBOR forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Coin
x -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
1, \ShelleyPParams StrictMaybe era
up -> ShelleyPParams StrictMaybe era
up {sppMinFeeB :: HKD StrictMaybe Coin
sppMinFeeB = forall a. a -> StrictMaybe a
SJust Coin
x})
          Word
2 -> forall a s. DecCBOR a => Decoder s a
decCBOR forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Word32
x -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
2, \ShelleyPParams StrictMaybe era
up -> ShelleyPParams StrictMaybe era
up {sppMaxBBSize :: HKD StrictMaybe Word32
sppMaxBBSize = forall a. a -> StrictMaybe a
SJust Word32
x})
          Word
3 -> forall a s. DecCBOR a => Decoder s a
decCBOR forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Word32
x -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
3, \ShelleyPParams StrictMaybe era
up -> ShelleyPParams StrictMaybe era
up {sppMaxTxSize :: HKD StrictMaybe Word32
sppMaxTxSize = forall a. a -> StrictMaybe a
SJust Word32
x})
          Word
4 -> forall a s. DecCBOR a => Decoder s a
decCBOR forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Word16
x -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
4, \ShelleyPParams StrictMaybe era
up -> ShelleyPParams StrictMaybe era
up {sppMaxBHSize :: HKD StrictMaybe Word16
sppMaxBHSize = forall a. a -> StrictMaybe a
SJust Word16
x})
          Word
5 -> forall a s. DecCBOR a => Decoder s a
decCBOR forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Coin
x -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
5, \ShelleyPParams StrictMaybe era
up -> ShelleyPParams StrictMaybe era
up {sppKeyDeposit :: HKD StrictMaybe Coin
sppKeyDeposit = forall a. a -> StrictMaybe a
SJust Coin
x})
          Word
6 -> forall a s. DecCBOR a => Decoder s a
decCBOR forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Coin
x -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
6, \ShelleyPParams StrictMaybe era
up -> ShelleyPParams StrictMaybe era
up {sppPoolDeposit :: HKD StrictMaybe Coin
sppPoolDeposit = forall a. a -> StrictMaybe a
SJust Coin
x})
          Word
7 -> forall a s. DecCBOR a => Decoder s a
decCBOR forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \EpochInterval
x -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
7, \ShelleyPParams StrictMaybe era
up -> ShelleyPParams StrictMaybe era
up {sppEMax :: HKD StrictMaybe EpochInterval
sppEMax = forall a. a -> StrictMaybe a
SJust EpochInterval
x})
          Word
8 -> forall a s. DecCBOR a => Decoder s a
decCBOR forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Natural
x -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
8, \ShelleyPParams StrictMaybe era
up -> ShelleyPParams StrictMaybe era
up {sppNOpt :: HKD StrictMaybe Natural
sppNOpt = forall a. a -> StrictMaybe a
SJust Natural
x})
          Word
9 -> forall a s. DecCBOR a => Decoder s a
decCBOR forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \NonNegativeInterval
x -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
9, \ShelleyPParams StrictMaybe era
up -> ShelleyPParams StrictMaybe era
up {sppA0 :: HKD StrictMaybe NonNegativeInterval
sppA0 = forall a. a -> StrictMaybe a
SJust NonNegativeInterval
x})
          Word
10 -> forall a s. DecCBOR a => Decoder s a
decCBOR forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \UnitInterval
x -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
10, \ShelleyPParams StrictMaybe era
up -> ShelleyPParams StrictMaybe era
up {sppRho :: HKD StrictMaybe UnitInterval
sppRho = forall a. a -> StrictMaybe a
SJust UnitInterval
x})
          Word
11 -> forall a s. DecCBOR a => Decoder s a
decCBOR forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \UnitInterval
x -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
11, \ShelleyPParams StrictMaybe era
up -> ShelleyPParams StrictMaybe era
up {sppTau :: HKD StrictMaybe UnitInterval
sppTau = forall a. a -> StrictMaybe a
SJust UnitInterval
x})
          Word
12 -> forall a s. DecCBOR a => Decoder s a
decCBOR forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \UnitInterval
x -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
12, \ShelleyPParams StrictMaybe era
up -> ShelleyPParams StrictMaybe era
up {sppD :: HKD StrictMaybe UnitInterval
sppD = forall a. a -> StrictMaybe a
SJust UnitInterval
x})
          Word
13 -> forall a s. DecCBOR a => Decoder s a
decCBOR forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Nonce
x -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
13, \ShelleyPParams StrictMaybe era
up -> ShelleyPParams StrictMaybe era
up {sppExtraEntropy :: HKD StrictMaybe Nonce
sppExtraEntropy = forall a. a -> StrictMaybe a
SJust Nonce
x})
          Word
14 -> forall a s. DecCBOR a => Decoder s a
decCBOR forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \ProtVer
x -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
14, \ShelleyPParams StrictMaybe era
up -> ShelleyPParams StrictMaybe era
up {sppProtocolVersion :: HKD StrictMaybe ProtVer
sppProtocolVersion = forall a. a -> StrictMaybe a
SJust ProtVer
x})
          Word
15 -> forall a s. DecCBOR a => Decoder s a
decCBOR forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Coin
x -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
15, \ShelleyPParams StrictMaybe era
up -> ShelleyPParams StrictMaybe era
up {sppMinUTxOValue :: HKD StrictMaybe Coin
sppMinUTxOValue = forall a. a -> StrictMaybe a
SJust Coin
x})
          Word
16 -> forall a s. DecCBOR a => Decoder s a
decCBOR forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Coin
x -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
16, \ShelleyPParams StrictMaybe era
up -> ShelleyPParams StrictMaybe era
up {sppMinPoolCost :: HKD StrictMaybe Coin
sppMinPoolCost = forall a. a -> StrictMaybe a
SJust Coin
x})
          Word
k -> forall (m :: * -> *) a. MonadFail m => Word -> m a
invalidKey Word
k
    let fields :: [Int]
fields = forall a b. (a, b) -> a
fst forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(Int,
  ShelleyPParams StrictMaybe era -> ShelleyPParams StrictMaybe era)]
mapParts :: [Int]
    forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless
      (forall a. Eq a => [a] -> [a]
nub [Int]
fields forall a. Eq a => a -> a -> Bool
== [Int]
fields)
      (forall (m :: * -> *) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$ String
"duplicate keys: " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show [Int]
fields)
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr forall a b. (a -> b) -> a -> b
($) forall era. ShelleyPParams StrictMaybe era
emptyShelleyPParamsUpdate (forall a b. (a, b) -> b
snd forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(Int,
  ShelleyPParams StrictMaybe era -> ShelleyPParams StrictMaybe era)]
mapParts)

instance Era era => ToCBOR (ShelleyPParams StrictMaybe era) where
  toCBOR :: ShelleyPParams StrictMaybe era -> Encoding
toCBOR = forall era t. (Era era, EncCBOR t) => t -> Encoding
toEraCBOR @era

instance Era era => FromCBOR (ShelleyPParams StrictMaybe era) where
  fromCBOR :: forall s. Decoder s (ShelleyPParams StrictMaybe era)
fromCBOR = forall era t s. (Era era, DecCBOR t) => Decoder s t
fromEraCBOR @era

instance
  ( EraPParams era
  , PParamsHKD StrictMaybe era ~ ShelleyPParams StrictMaybe era
  , ProtVerAtMost era 4
  , ProtVerAtMost era 6
  , ProtVerAtMost era 8
  ) =>
  ToJSON (ShelleyPParams StrictMaybe era)
  where
  toJSON :: ShelleyPParams StrictMaybe era -> Value
toJSON = [Pair] -> Value
object forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era a e.
(EraPParams era, ProtVerAtMost era 4, ProtVerAtMost era 6,
 ProtVerAtMost era 8, KeyValue e a) =>
PParamsHKD StrictMaybe era -> [a]
shelleyPParamsUpdatePairs
  toEncoding :: ShelleyPParams StrictMaybe era -> Encoding
toEncoding = Series -> Encoding
pairs forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era a e.
(EraPParams era, ProtVerAtMost era 4, ProtVerAtMost era 6,
 ProtVerAtMost era 8, KeyValue e a) =>
PParamsHKD StrictMaybe era -> [a]
shelleyPParamsUpdatePairs

shelleyPParamsUpdatePairs ::
  forall era a e.
  (EraPParams era, ProtVerAtMost era 4, ProtVerAtMost era 6, ProtVerAtMost era 8, KeyValue e a) =>
  PParamsHKD StrictMaybe era ->
  [a]
shelleyPParamsUpdatePairs :: forall era a e.
(EraPParams era, ProtVerAtMost era 4, ProtVerAtMost era 6,
 ProtVerAtMost era 8, KeyValue e a) =>
PParamsHKD StrictMaybe era -> [a]
shelleyPParamsUpdatePairs PParamsHKD StrictMaybe era
pp =
  [ Key
k forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Value
v
  | (Key
k, SJust Value
v) <- forall (f :: * -> *) era.
(HKDFunctor f, EraPParams era, ProtVerAtMost era 4,
 ProtVerAtMost era 6, ProtVerAtMost era 8) =>
Proxy f -> PParamsHKD f era -> [(Key, HKD f Value)]
shelleyPParamsHKDPairs (forall {k} (t :: k). Proxy t
Proxy @StrictMaybe) PParamsHKD StrictMaybe era
pp
  ]

shelleyPParamsHKDPairs ::
  forall f era.
  (HKDFunctor f, EraPParams era, ProtVerAtMost era 4, ProtVerAtMost era 6, ProtVerAtMost era 8) =>
  Proxy f ->
  PParamsHKD f era ->
  [(Key, HKD f Aeson.Value)]
shelleyPParamsHKDPairs :: forall (f :: * -> *) era.
(HKDFunctor f, EraPParams era, ProtVerAtMost era 4,
 ProtVerAtMost era 6, ProtVerAtMost era 8) =>
Proxy f -> PParamsHKD f era -> [(Key, HKD f Value)]
shelleyPParamsHKDPairs Proxy f
px PParamsHKD f era
pp =
  forall (f :: * -> *) era.
(HKDFunctor f, EraPParams era) =>
Proxy f -> PParamsHKD f era -> [(Key, HKD f Value)]
shelleyCommonPParamsHKDPairs Proxy f
px PParamsHKD f era
pp
    forall a. [a] -> [a] -> [a]
++ forall (f :: * -> *) era.
(HKDFunctor f, EraPParams era, ProtVerAtMost era 6) =>
Proxy f -> PParamsHKD f era -> [(Key, HKD f Value)]
shelleyCommonPParamsHKDPairsV6 Proxy f
px PParamsHKD f era
pp
    forall a. [a] -> [a] -> [a]
++ forall (f :: * -> *) era.
(HKDFunctor f, EraPParams era, ProtVerAtMost era 8) =>
Proxy f -> PParamsHKD f era -> [(Key, HKD f Value)]
shelleyCommonPParamsHKDPairsV8 Proxy f
px PParamsHKD f era
pp
    forall a. [a] -> [a] -> [a]
++ [(Key
"minUTxOValue", forall (f :: * -> *) (proxy :: (* -> *) -> *) a b.
HKDFunctor f =>
proxy f -> (a -> b) -> HKD f a -> HKD f b
hkdMap Proxy f
px (forall a. ToJSON a => a -> Value
toJSON @Coin) (PParamsHKD f era
pp forall s a. s -> Getting a s a -> a
^. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f, ProtVerAtMost era 4) =>
Lens' (PParamsHKD f era) (HKD f Coin)
hkdMinUTxOValueL @era @f))]

-- | These are the fields that are common only up to major protocol version 6
shelleyCommonPParamsHKDPairsV6 ::
  forall f era.
  (HKDFunctor f, EraPParams era, ProtVerAtMost era 6) =>
  Proxy f ->
  PParamsHKD f era ->
  [(Key, HKD f Aeson.Value)]
shelleyCommonPParamsHKDPairsV6 :: forall (f :: * -> *) era.
(HKDFunctor f, EraPParams era, ProtVerAtMost era 6) =>
Proxy f -> PParamsHKD f era -> [(Key, HKD f Value)]
shelleyCommonPParamsHKDPairsV6 Proxy f
px PParamsHKD f era
pp =
  [ (Key
"decentralization", forall (f :: * -> *) (proxy :: (* -> *) -> *) a b.
HKDFunctor f =>
proxy f -> (a -> b) -> HKD f a -> HKD f b
hkdMap Proxy f
px (forall a. ToJSON a => a -> Value
toJSON @UnitInterval) (PParamsHKD f era
pp forall s a. s -> Getting a s a -> a
^. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f, ProtVerAtMost era 6) =>
Lens' (PParamsHKD f era) (HKD f UnitInterval)
hkdDL @era @f))
  , (Key
"extraPraosEntropy", forall (f :: * -> *) (proxy :: (* -> *) -> *) a b.
HKDFunctor f =>
proxy f -> (a -> b) -> HKD f a -> HKD f b
hkdMap Proxy f
px (forall a. ToJSON a => a -> Value
toJSON @Nonce) (PParamsHKD f era
pp forall s a. s -> Getting a s a -> a
^. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f, ProtVerAtMost era 6) =>
Lens' (PParamsHKD f era) (HKD f Nonce)
hkdExtraEntropyL @era @f))
  ]

shelleyCommonPParamsHKDPairsV8 ::
  forall f era.
  (HKDFunctor f, EraPParams era, ProtVerAtMost era 8) =>
  Proxy f ->
  PParamsHKD f era ->
  [(Key, HKD f Aeson.Value)]
shelleyCommonPParamsHKDPairsV8 :: forall (f :: * -> *) era.
(HKDFunctor f, EraPParams era, ProtVerAtMost era 8) =>
Proxy f -> PParamsHKD f era -> [(Key, HKD f Value)]
shelleyCommonPParamsHKDPairsV8 Proxy f
px PParamsHKD f era
pp =
  [ (Key
"protocolVersion", forall (f :: * -> *) (proxy :: (* -> *) -> *) a b.
HKDFunctor f =>
proxy f -> (a -> b) -> HKD f a -> HKD f b
hkdMap Proxy f
px (forall a. ToJSON a => a -> Value
toJSON @ProtVer) (PParamsHKD f era
pp forall s a. s -> Getting a s a -> a
^. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f, ProtVerAtMost era 8) =>
Lens' (PParamsHKD f era) (HKD f ProtVer)
hkdProtocolVersionL @era @f))
  ]

-- | These are the fields that are common across all eras
shelleyCommonPParamsHKDPairs ::
  forall f era.
  (HKDFunctor f, EraPParams era) =>
  Proxy f ->
  PParamsHKD f era ->
  [(Key, HKD f Aeson.Value)]
shelleyCommonPParamsHKDPairs :: forall (f :: * -> *) era.
(HKDFunctor f, EraPParams era) =>
Proxy f -> PParamsHKD f era -> [(Key, HKD f Value)]
shelleyCommonPParamsHKDPairs Proxy f
px PParamsHKD f era
pp =
  [ (Key
"txFeePerByte", forall (f :: * -> *) (proxy :: (* -> *) -> *) a b.
HKDFunctor f =>
proxy f -> (a -> b) -> HKD f a -> HKD f b
hkdMap Proxy f
px (forall a. ToJSON a => a -> Value
toJSON @Coin) (PParamsHKD f era
pp forall s a. s -> Getting a s a -> a
^. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f Coin)
hkdMinFeeAL @_ @f :: HKD f Coin))
  , (Key
"txFeeFixed", forall (f :: * -> *) (proxy :: (* -> *) -> *) a b.
HKDFunctor f =>
proxy f -> (a -> b) -> HKD f a -> HKD f b
hkdMap Proxy f
px (forall a. ToJSON a => a -> Value
toJSON @Coin) (PParamsHKD f era
pp forall s a. s -> Getting a s a -> a
^. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f Coin)
hkdMinFeeBL @era @f))
  , (Key
"maxBlockBodySize", forall (f :: * -> *) (proxy :: (* -> *) -> *) a b.
HKDFunctor f =>
proxy f -> (a -> b) -> HKD f a -> HKD f b
hkdMap Proxy f
px (forall a. ToJSON a => a -> Value
toJSON @Word32) (PParamsHKD f era
pp forall s a. s -> Getting a s a -> a
^. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f Word32)
hkdMaxBBSizeL @era @f))
  , (Key
"maxTxSize", forall (f :: * -> *) (proxy :: (* -> *) -> *) a b.
HKDFunctor f =>
proxy f -> (a -> b) -> HKD f a -> HKD f b
hkdMap Proxy f
px (forall a. ToJSON a => a -> Value
toJSON @Word32) (PParamsHKD f era
pp forall s a. s -> Getting a s a -> a
^. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f Word32)
hkdMaxTxSizeL @era @f))
  , (Key
"maxBlockHeaderSize", forall (f :: * -> *) (proxy :: (* -> *) -> *) a b.
HKDFunctor f =>
proxy f -> (a -> b) -> HKD f a -> HKD f b
hkdMap Proxy f
px (forall a. ToJSON a => a -> Value
toJSON @Word16) (PParamsHKD f era
pp forall s a. s -> Getting a s a -> a
^. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f Word16)
hkdMaxBHSizeL @era @f))
  , (Key
"stakeAddressDeposit", forall (f :: * -> *) (proxy :: (* -> *) -> *) a b.
HKDFunctor f =>
proxy f -> (a -> b) -> HKD f a -> HKD f b
hkdMap Proxy f
px (forall a. ToJSON a => a -> Value
toJSON @Coin) (PParamsHKD f era
pp forall s a. s -> Getting a s a -> a
^. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f Coin)
hkdKeyDepositL @era @f))
  , (Key
"stakePoolDeposit", forall (f :: * -> *) (proxy :: (* -> *) -> *) a b.
HKDFunctor f =>
proxy f -> (a -> b) -> HKD f a -> HKD f b
hkdMap Proxy f
px (forall a. ToJSON a => a -> Value
toJSON @Coin) (PParamsHKD f era
pp forall s a. s -> Getting a s a -> a
^. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f Coin)
hkdPoolDepositL @era @f))
  , (Key
"poolRetireMaxEpoch", forall (f :: * -> *) (proxy :: (* -> *) -> *) a b.
HKDFunctor f =>
proxy f -> (a -> b) -> HKD f a -> HKD f b
hkdMap Proxy f
px (forall a. ToJSON a => a -> Value
toJSON @EpochInterval) (PParamsHKD f era
pp forall s a. s -> Getting a s a -> a
^. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f EpochInterval)
hkdEMaxL @era @f))
  , (Key
"stakePoolTargetNum", forall (f :: * -> *) (proxy :: (* -> *) -> *) a b.
HKDFunctor f =>
proxy f -> (a -> b) -> HKD f a -> HKD f b
hkdMap Proxy f
px (forall a. ToJSON a => a -> Value
toJSON @Natural) (PParamsHKD f era
pp forall s a. s -> Getting a s a -> a
^. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f Natural)
hkdNOptL @era @f))
  , (Key
"poolPledgeInfluence", forall (f :: * -> *) (proxy :: (* -> *) -> *) a b.
HKDFunctor f =>
proxy f -> (a -> b) -> HKD f a -> HKD f b
hkdMap Proxy f
px (forall a. ToJSON a => a -> Value
toJSON @NonNegativeInterval) (PParamsHKD f era
pp forall s a. s -> Getting a s a -> a
^. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f NonNegativeInterval)
hkdA0L @era @f))
  , (Key
"monetaryExpansion", forall (f :: * -> *) (proxy :: (* -> *) -> *) a b.
HKDFunctor f =>
proxy f -> (a -> b) -> HKD f a -> HKD f b
hkdMap Proxy f
px (forall a. ToJSON a => a -> Value
toJSON @UnitInterval) (PParamsHKD f era
pp forall s a. s -> Getting a s a -> a
^. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f UnitInterval)
hkdRhoL @era @f))
  , (Key
"treasuryCut", forall (f :: * -> *) (proxy :: (* -> *) -> *) a b.
HKDFunctor f =>
proxy f -> (a -> b) -> HKD f a -> HKD f b
hkdMap Proxy f
px (forall a. ToJSON a => a -> Value
toJSON @UnitInterval) (PParamsHKD f era
pp forall s a. s -> Getting a s a -> a
^. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f UnitInterval)
hkdTauL @era @f))
  , (Key
"minPoolCost", forall (f :: * -> *) (proxy :: (* -> *) -> *) a b.
HKDFunctor f =>
proxy f -> (a -> b) -> HKD f a -> HKD f b
hkdMap Proxy f
px (forall a. ToJSON a => a -> Value
toJSON @Coin) (PParamsHKD f era
pp forall s a. s -> Getting a s a -> a
^. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f Coin)
hkdMinPoolCostL @era @f))
  ]

-- | Update operation for protocol parameters structure @PParams@
newtype ProposedPPUpdates era
  = ProposedPPUpdates (Map (KeyHash 'Genesis (EraCrypto era)) (PParamsUpdate era))
  deriving (forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall era x.
Rep (ProposedPPUpdates era) x -> ProposedPPUpdates era
forall era x.
ProposedPPUpdates era -> Rep (ProposedPPUpdates era) x
$cto :: forall era x.
Rep (ProposedPPUpdates era) x -> ProposedPPUpdates era
$cfrom :: forall era x.
ProposedPPUpdates era -> Rep (ProposedPPUpdates era) x
Generic, NonEmpty (ProposedPPUpdates era) -> ProposedPPUpdates era
ProposedPPUpdates era
-> ProposedPPUpdates era -> ProposedPPUpdates era
forall b.
Integral b =>
b -> ProposedPPUpdates era -> ProposedPPUpdates era
forall era.
NonEmpty (ProposedPPUpdates era) -> ProposedPPUpdates era
forall era.
ProposedPPUpdates era
-> ProposedPPUpdates era -> ProposedPPUpdates era
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
forall era b.
Integral b =>
b -> ProposedPPUpdates era -> ProposedPPUpdates era
stimes :: forall b.
Integral b =>
b -> ProposedPPUpdates era -> ProposedPPUpdates era
$cstimes :: forall era b.
Integral b =>
b -> ProposedPPUpdates era -> ProposedPPUpdates era
sconcat :: NonEmpty (ProposedPPUpdates era) -> ProposedPPUpdates era
$csconcat :: forall era.
NonEmpty (ProposedPPUpdates era) -> ProposedPPUpdates era
<> :: ProposedPPUpdates era
-> ProposedPPUpdates era -> ProposedPPUpdates era
$c<> :: forall era.
ProposedPPUpdates era
-> ProposedPPUpdates era -> ProposedPPUpdates era
Semigroup, ProposedPPUpdates era
[ProposedPPUpdates era] -> ProposedPPUpdates era
ProposedPPUpdates era
-> ProposedPPUpdates era -> ProposedPPUpdates era
forall era. Semigroup (ProposedPPUpdates era)
forall era. ProposedPPUpdates era
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall era. [ProposedPPUpdates era] -> ProposedPPUpdates era
forall era.
ProposedPPUpdates era
-> ProposedPPUpdates era -> ProposedPPUpdates era
mconcat :: [ProposedPPUpdates era] -> ProposedPPUpdates era
$cmconcat :: forall era. [ProposedPPUpdates era] -> ProposedPPUpdates era
mappend :: ProposedPPUpdates era
-> ProposedPPUpdates era -> ProposedPPUpdates era
$cmappend :: forall era.
ProposedPPUpdates era
-> ProposedPPUpdates era -> ProposedPPUpdates era
mempty :: ProposedPPUpdates era
$cmempty :: forall era. ProposedPPUpdates era
Monoid)

deriving instance Eq (PParamsUpdate era) => Eq (ProposedPPUpdates era)

deriving instance NFData (PParamsUpdate era) => NFData (ProposedPPUpdates era)

deriving instance Show (PParamsUpdate era) => Show (ProposedPPUpdates era)

instance NoThunks (PParamsUpdate era) => NoThunks (ProposedPPUpdates era)

deriving instance (Era era, ToCBOR (PParamsUpdate era)) => ToCBOR (ProposedPPUpdates era)

deriving instance (Era era, FromCBOR (PParamsUpdate era)) => FromCBOR (ProposedPPUpdates era)

deriving instance (Era era, EncCBOR (PParamsUpdate era)) => EncCBOR (ProposedPPUpdates era)

deriving instance (Era era, DecCBOR (PParamsUpdate era)) => DecCBOR (ProposedPPUpdates era)

instance EraPParams era => ToJSON (ProposedPPUpdates era) where
  toJSON :: ProposedPPUpdates era -> Value
toJSON (ProposedPPUpdates Map (KeyHash 'Genesis (EraCrypto era)) (PParamsUpdate era)
ppUpdates) = forall a. ToJSON a => a -> Value
toJSON forall a b. (a -> b) -> a -> b
$ forall k a. Map k a -> [(k, a)]
Map.toList Map (KeyHash 'Genesis (EraCrypto era)) (PParamsUpdate era)
ppUpdates
  toEncoding :: ProposedPPUpdates era -> Encoding
toEncoding (ProposedPPUpdates Map (KeyHash 'Genesis (EraCrypto era)) (PParamsUpdate era)
ppUpdates) = forall a. ToJSON a => a -> Encoding
toEncoding forall a b. (a -> b) -> a -> b
$ forall k a. Map k a -> [(k, a)]
Map.toList Map (KeyHash 'Genesis (EraCrypto era)) (PParamsUpdate era)
ppUpdates

emptyPPPUpdates :: ProposedPPUpdates era
emptyPPPUpdates :: forall era. ProposedPPUpdates era
emptyPPPUpdates = forall era.
Map (KeyHash 'Genesis (EraCrypto era)) (PParamsUpdate era)
-> ProposedPPUpdates era
ProposedPPUpdates forall k a. Map k a
Map.empty

updatePParams :: EraPParams era => PParams era -> PParamsUpdate era -> PParams era
updatePParams :: forall era.
EraPParams era =>
PParams era -> PParamsUpdate era -> PParams era
updatePParams = forall era.
EraPParams era =>
PParams era -> PParamsUpdate era -> PParams era
applyPPUpdates
{-# DEPRECATED updatePParams "Use applyPPUpdates instead" #-}

-- | Check whether the new protocol version is a legitimate version bump with respect to the
-- previous one.
pvCanFollow ::
  -- | Previous protocol version
  ProtVer ->
  -- | New protocol version
  ProtVer ->
  Bool
pvCanFollow :: ProtVer -> ProtVer -> Bool
pvCanFollow (ProtVer Version
curMajor Natural
curMinor) (ProtVer Version
newMajor Natural
newMinor) =
  (forall (m :: * -> *). MonadFail m => Version -> m Version
succVersion Version
curMajor, Natural
0) forall a. Eq a => a -> a -> Bool
== (forall a. a -> Maybe a
Just Version
newMajor, Natural
newMinor)
    Bool -> Bool -> Bool
|| (Version
curMajor, Natural
curMinor forall a. Num a => a -> a -> a
+ Natural
1) forall a. Eq a => a -> a -> Bool
== (Version
newMajor, Natural
newMinor)

-- | Check whether `PParamsUpdate` contains a valid `ProtVer` update. When a protocol version
-- update is not included in `PParamsUpdate` it is considered a legal update.
hasLegalProtVerUpdate ::
  (ProtVerAtMost era 8, EraPParams era) => PParams era -> PParamsUpdate era -> Bool
hasLegalProtVerUpdate :: forall era.
(ProtVerAtMost era 8, EraPParams era) =>
PParams era -> PParamsUpdate era -> Bool
hasLegalProtVerUpdate PParams era
pp PParamsUpdate era
ppu =
  case PParamsUpdate era
ppu forall s a. s -> Getting a s a -> a
^. forall era.
(EraPParams era, ProtVerAtMost era 8) =>
Lens' (PParamsUpdate era) (StrictMaybe ProtVer)
ppuProtocolVersionL of
    StrictMaybe ProtVer
SNothing -> Bool
True
    SJust ProtVer
newProtVer -> ProtVer -> ProtVer -> Bool
pvCanFollow (PParams era
pp forall s a. s -> Getting a s a -> a
^. forall era. EraPParams era => Lens' (PParams era) ProtVer
ppProtocolVersionL) ProtVer
newProtVer

upgradeUpdate ::
  forall era.
  ( EraPParams era
  , EraPParams (PreviousEra era)
  , EraCrypto (PreviousEra era) ~ EraCrypto era
  ) =>
  UpgradePParams StrictMaybe era ->
  Update (PreviousEra era) ->
  Update era
upgradeUpdate :: forall era.
(EraPParams era, EraPParams (PreviousEra era),
 EraCrypto (PreviousEra era) ~ EraCrypto era) =>
UpgradePParams StrictMaybe era
-> Update (PreviousEra era) -> Update era
upgradeUpdate UpgradePParams StrictMaybe era
args (Update ProposedPPUpdates (PreviousEra era)
pp EpochNo
epoch) = forall era. ProposedPPUpdates era -> EpochNo -> Update era
Update (forall era.
(EraPParams era, EraPParams (PreviousEra era),
 EraCrypto (PreviousEra era) ~ EraCrypto era) =>
UpgradePParams StrictMaybe era
-> ProposedPPUpdates (PreviousEra era) -> ProposedPPUpdates era
upgradeProposedPPUpdates @era UpgradePParams StrictMaybe era
args ProposedPPUpdates (PreviousEra era)
pp) EpochNo
epoch

upgradeProposedPPUpdates ::
  ( EraPParams era
  , EraPParams (PreviousEra era)
  , EraCrypto (PreviousEra era) ~ EraCrypto era
  ) =>
  UpgradePParams StrictMaybe era ->
  ProposedPPUpdates (PreviousEra era) ->
  ProposedPPUpdates era
upgradeProposedPPUpdates :: forall era.
(EraPParams era, EraPParams (PreviousEra era),
 EraCrypto (PreviousEra era) ~ EraCrypto era) =>
UpgradePParams StrictMaybe era
-> ProposedPPUpdates (PreviousEra era) -> ProposedPPUpdates era
upgradeProposedPPUpdates UpgradePParams StrictMaybe era
args (ProposedPPUpdates Map
  (KeyHash 'Genesis (EraCrypto (PreviousEra era)))
  (PParamsUpdate (PreviousEra era))
ppus) =
  forall era.
Map (KeyHash 'Genesis (EraCrypto era)) (PParamsUpdate era)
-> ProposedPPUpdates era
ProposedPPUpdates forall a b. (a -> b) -> a -> b
$ forall era.
(EraPParams era, EraPParams (PreviousEra era)) =>
UpgradePParams StrictMaybe era
-> PParamsUpdate (PreviousEra era) -> PParamsUpdate era
upgradePParamsUpdate UpgradePParams StrictMaybe era
args forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Map
  (KeyHash 'Genesis (EraCrypto (PreviousEra era)))
  (PParamsUpdate (PreviousEra era))
ppus