{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}

-- | This module contains just the type of protocol parameters.
module Shelley.Spec.Ledger.PParams
  ( PParams' (..),
    PParams,
    emptyPParams,
    ProtVer (..),
    PPUpdateEnv (..),
    ProposedPPUpdates (..),
    emptyPPPUpdates,
    PParamsUpdate,
    emptyPParamsUpdate,
    Update (..),
    updatePParams,
  )
where

import Cardano.Binary
  ( FromCBOR (..),
    ToCBOR (..),
    decodeWord,
    encodeListLen,
    encodeMapLen,
    encodeWord,
  )
import Cardano.Ledger.Era
import Control.DeepSeq (NFData)
import Control.Monad (unless)
import Data.Aeson (FromJSON (..), ToJSON (..), (.!=), (.:), (.:?), (.=))
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 (fromMaybe, mapMaybe)
import Data.Scientific (Scientific)
import GHC.Generics (Generic)
import NoThunks.Class (NoThunks (..))
import Numeric.Natural (Natural)
import Shelley.Spec.Ledger.BaseTypes
  ( Nonce (NeutralNonce),
    StrictMaybe (..),
    UnitInterval,
    interval0,
    invalidKey,
    strictMaybeToMaybe,
  )
import Shelley.Spec.Ledger.Coin (Coin (..))
import Shelley.Spec.Ledger.Keys (GenDelegs, KeyHash, KeyRole (..))
import Shelley.Spec.Ledger.Orphans ()
import Shelley.Spec.Ledger.Serialization
  ( CBORGroup (..),
    FromCBORGroup (..),
    ToCBORGroup (..),
    decodeMapContents,
    decodeRecordNamed,
    mapFromCBOR,
    mapToCBOR,
    ratioFromCBOR,
    ratioToCBOR,
  )
import Shelley.Spec.Ledger.Slot (EpochNo (..), SlotNo (..))

-- | Higher Kinded Data
type family HKD f a where
  HKD Identity a = a
  HKD f a = f a

-- | Protocol parameters.
--
-- We use the HKD type family so that the protocol parameters type and
-- the type for the updates to the protocol parameters can share records fields.
-- The protocol parameters will have type 'PParams'' 'Identity', and the updates
-- will have type 'PParams'' 'StrictMaybe', though 'Identity' will be hidden from use.
--
-- For example:
--
-- @
--   myParameters =
--     PParams
--       { _minfeeA = 0,
--         _minfeeB = 0,
--         ...
--       }
--
--   myUpdate =
--     PParamsUpdate
--       { _minfeeA = SNothing,
--         _minfeeB = SJust 42,
--         ...
--       }
-- @
data PParams' f era = PParams
  { -- | The linear factor for the minimum fee calculation
    PParams' f era -> HKD f Natural
_minfeeA :: !(HKD f Natural),
    -- | The constant factor for the minimum fee calculation
    PParams' f era -> HKD f Natural
_minfeeB :: !(HKD f Natural),
    -- | Maximal block body size
    PParams' f era -> HKD f Natural
_maxBBSize :: !(HKD f Natural),
    -- | Maximal transaction size
    PParams' f era -> HKD f Natural
_maxTxSize :: !(HKD f Natural),
    -- | Maximal block header size
    PParams' f era -> HKD f Natural
_maxBHSize :: !(HKD f Natural),
    -- | The amount of a key registration deposit
    PParams' f era -> HKD f Coin
_keyDeposit :: !(HKD f Coin),
    -- | The amount of a pool registration deposit
    PParams' f era -> HKD f Coin
_poolDeposit :: !(HKD f Coin),
    -- | epoch bound on pool retirement
    PParams' f era -> HKD f EpochNo
_eMax :: !(HKD f EpochNo),
    -- | Desired number of pools
    PParams' f era -> HKD f Natural
_nOpt :: !(HKD f Natural),
    -- | Pool influence
    PParams' f era -> HKD f Rational
_a0 :: !(HKD f Rational),
    -- | Monetary expansion
    PParams' f era -> HKD f UnitInterval
_rho :: !(HKD f UnitInterval),
    -- | Treasury expansion
    PParams' f era -> HKD f UnitInterval
_tau :: !(HKD f UnitInterval),
    -- | Decentralization parameter
    PParams' f era -> HKD f UnitInterval
_d :: !(HKD f UnitInterval),
    -- | Extra entropy
    PParams' f era -> HKD f Nonce
_extraEntropy :: !(HKD f Nonce),
    -- | Protocol version
    PParams' f era -> HKD f ProtVer
_protocolVersion :: !(HKD f ProtVer),
    -- | Minimum UTxO value
    PParams' f era -> HKD f Coin
_minUTxOValue :: !(HKD f Coin),
    -- | Minimum Stake Pool Cost
    PParams' f era -> HKD f Coin
_minPoolCost :: !(HKD f Coin)
  }
  deriving ((forall x. PParams' f era -> Rep (PParams' f era) x)
-> (forall x. Rep (PParams' f era) x -> PParams' f era)
-> Generic (PParams' f era)
forall x. Rep (PParams' f era) x -> PParams' f era
forall x. PParams' f era -> Rep (PParams' f era) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (f :: * -> *) era x.
Rep (PParams' f era) x -> PParams' f era
forall (f :: * -> *) era x.
PParams' f era -> Rep (PParams' f era) x
$cto :: forall (f :: * -> *) era x.
Rep (PParams' f era) x -> PParams' f era
$cfrom :: forall (f :: * -> *) era x.
PParams' f era -> Rep (PParams' f era) x
Generic)

type PParams era = PParams' Identity era

deriving instance Eq (PParams' Identity era)

deriving instance Show (PParams' Identity era)

deriving instance NFData (PParams' Identity era)

data ProtVer = ProtVer {ProtVer -> Natural
pvMajor :: !Natural, ProtVer -> Natural
pvMinor :: !Natural}
  deriving (Int -> ProtVer -> ShowS
[ProtVer] -> ShowS
ProtVer -> String
(Int -> ProtVer -> ShowS)
-> (ProtVer -> String) -> ([ProtVer] -> ShowS) -> Show ProtVer
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ProtVer] -> ShowS
$cshowList :: [ProtVer] -> ShowS
show :: ProtVer -> String
$cshow :: ProtVer -> String
showsPrec :: Int -> ProtVer -> ShowS
$cshowsPrec :: Int -> ProtVer -> ShowS
Show, ProtVer -> ProtVer -> Bool
(ProtVer -> ProtVer -> Bool)
-> (ProtVer -> ProtVer -> Bool) -> Eq ProtVer
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ProtVer -> ProtVer -> Bool
$c/= :: ProtVer -> ProtVer -> Bool
== :: ProtVer -> ProtVer -> Bool
$c== :: ProtVer -> ProtVer -> Bool
Eq, (forall x. ProtVer -> Rep ProtVer x)
-> (forall x. Rep ProtVer x -> ProtVer) -> Generic ProtVer
forall x. Rep ProtVer x -> ProtVer
forall x. ProtVer -> Rep ProtVer x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ProtVer x -> ProtVer
$cfrom :: forall x. ProtVer -> Rep ProtVer x
Generic, Eq ProtVer
Eq ProtVer
-> (ProtVer -> ProtVer -> Ordering)
-> (ProtVer -> ProtVer -> Bool)
-> (ProtVer -> ProtVer -> Bool)
-> (ProtVer -> ProtVer -> Bool)
-> (ProtVer -> ProtVer -> Bool)
-> (ProtVer -> ProtVer -> ProtVer)
-> (ProtVer -> ProtVer -> ProtVer)
-> Ord ProtVer
ProtVer -> ProtVer -> Bool
ProtVer -> ProtVer -> Ordering
ProtVer -> ProtVer -> ProtVer
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ProtVer -> ProtVer -> ProtVer
$cmin :: ProtVer -> ProtVer -> ProtVer
max :: ProtVer -> ProtVer -> ProtVer
$cmax :: ProtVer -> ProtVer -> ProtVer
>= :: ProtVer -> ProtVer -> Bool
$c>= :: ProtVer -> ProtVer -> Bool
> :: ProtVer -> ProtVer -> Bool
$c> :: ProtVer -> ProtVer -> Bool
<= :: ProtVer -> ProtVer -> Bool
$c<= :: ProtVer -> ProtVer -> Bool
< :: ProtVer -> ProtVer -> Bool
$c< :: ProtVer -> ProtVer -> Bool
compare :: ProtVer -> ProtVer -> Ordering
$ccompare :: ProtVer -> ProtVer -> Ordering
$cp1Ord :: Eq ProtVer
Ord, ProtVer -> ()
(ProtVer -> ()) -> NFData ProtVer
forall a. (a -> ()) -> NFData a
rnf :: ProtVer -> ()
$crnf :: ProtVer -> ()
NFData)
  deriving (Typeable ProtVer
Typeable ProtVer
-> (ProtVer -> Encoding)
-> ((forall t. ToCBOR t => Proxy t -> Size)
    -> Proxy ProtVer -> Size)
-> ((forall t. ToCBOR t => Proxy t -> Size)
    -> Proxy [ProtVer] -> Size)
-> ToCBOR ProtVer
ProtVer -> Encoding
(forall t. ToCBOR t => Proxy t -> Size) -> Proxy [ProtVer] -> Size
(forall t. ToCBOR t => Proxy t -> Size) -> Proxy ProtVer -> Size
forall a.
Typeable a
-> (a -> Encoding)
-> ((forall t. ToCBOR t => Proxy t -> Size) -> Proxy a -> Size)
-> ((forall t. ToCBOR t => Proxy t -> Size) -> Proxy [a] -> Size)
-> ToCBOR a
encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [ProtVer] -> Size
$cencodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [ProtVer] -> Size
encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy ProtVer -> Size
$cencodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy ProtVer -> Size
toCBOR :: ProtVer -> Encoding
$ctoCBOR :: ProtVer -> Encoding
$cp1ToCBOR :: Typeable ProtVer
ToCBOR) via (CBORGroup ProtVer)
  deriving (Typeable ProtVer
Decoder s ProtVer
Typeable ProtVer
-> (forall s. Decoder s ProtVer)
-> (Proxy ProtVer -> Text)
-> FromCBOR ProtVer
Proxy ProtVer -> Text
forall s. Decoder s ProtVer
forall a.
Typeable a
-> (forall s. Decoder s a) -> (Proxy a -> Text) -> FromCBOR a
label :: Proxy ProtVer -> Text
$clabel :: Proxy ProtVer -> Text
fromCBOR :: Decoder s ProtVer
$cfromCBOR :: forall s. Decoder s ProtVer
$cp1FromCBOR :: Typeable ProtVer
FromCBOR) via (CBORGroup ProtVer)

instance NoThunks ProtVer

instance ToJSON ProtVer where
  toJSON :: ProtVer -> Value
toJSON (ProtVer Natural
major Natural
minor) =
    [Pair] -> Value
Aeson.object
      [ Text
"major" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= Natural
major,
        Text
"minor" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= Natural
minor
      ]

instance FromJSON ProtVer where
  parseJSON :: Value -> Parser ProtVer
parseJSON =
    String -> (Object -> Parser ProtVer) -> Value -> Parser ProtVer
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"ProtVer" ((Object -> Parser ProtVer) -> Value -> Parser ProtVer)
-> (Object -> Parser ProtVer) -> Value -> Parser ProtVer
forall a b. (a -> b) -> a -> b
$ \Object
obj ->
      Natural -> Natural -> ProtVer
ProtVer
        (Natural -> Natural -> ProtVer)
-> Parser Natural -> Parser (Natural -> ProtVer)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"major"
        Parser (Natural -> ProtVer) -> Parser Natural -> Parser ProtVer
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"minor"

instance ToCBORGroup ProtVer where
  toCBORGroup :: ProtVer -> Encoding
toCBORGroup (ProtVer Natural
x Natural
y) = Natural -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR Natural
x Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Natural -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR Natural
y
  encodedGroupSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy ProtVer -> Size
encodedGroupSizeExpr forall t. ToCBOR t => Proxy t -> Size
size Proxy ProtVer
proxy =
    (forall t. ToCBOR t => Proxy t -> Size) -> Proxy Word -> Size
forall a.
ToCBOR a =>
(forall t. ToCBOR t => Proxy t -> Size) -> Proxy a -> Size
encodedSizeExpr forall t. ToCBOR t => Proxy t -> Size
size ((\(ProtVer Natural
x Natural
_) -> Natural -> Word
toWord Natural
x) (ProtVer -> Word) -> Proxy ProtVer -> Proxy Word
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Proxy ProtVer
proxy)
      Size -> Size -> Size
forall a. Num a => a -> a -> a
+ (forall t. ToCBOR t => Proxy t -> Size) -> Proxy Word -> Size
forall a.
ToCBOR a =>
(forall t. ToCBOR t => Proxy t -> Size) -> Proxy a -> Size
encodedSizeExpr forall t. ToCBOR t => Proxy t -> Size
size ((\(ProtVer Natural
_ Natural
y) -> Natural -> Word
toWord Natural
y) (ProtVer -> Word) -> Proxy ProtVer -> Proxy Word
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Proxy ProtVer
proxy)
    where
      toWord :: Natural -> Word
      toWord :: Natural -> Word
toWord = Natural -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral

  listLen :: ProtVer -> Word
listLen ProtVer
_ = Word
2
  listLenBound :: Proxy ProtVer -> Word
listLenBound Proxy ProtVer
_ = Word
2

instance FromCBORGroup ProtVer where
  fromCBORGroup :: Decoder s ProtVer
fromCBORGroup = do
    Natural
x <- Decoder s Natural
forall a s. FromCBOR a => Decoder s a
fromCBOR
    Natural
y <- Decoder s Natural
forall a s. FromCBOR a => Decoder s a
fromCBOR
    ProtVer -> Decoder s ProtVer
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ProtVer -> Decoder s ProtVer) -> ProtVer -> Decoder s ProtVer
forall a b. (a -> b) -> a -> b
$ Natural -> Natural -> ProtVer
ProtVer Natural
x Natural
y

instance NoThunks (PParams era)

instance (Era era) => ToCBOR (PParams era) where
  toCBOR :: PParams era -> Encoding
toCBOR
    ( PParams
        { _minfeeA :: forall (f :: * -> *) era. PParams' f era -> HKD f Natural
_minfeeA = HKD Identity Natural
minfeeA',
          _minfeeB :: forall (f :: * -> *) era. PParams' f era -> HKD f Natural
_minfeeB = HKD Identity Natural
minfeeB',
          _maxBBSize :: forall (f :: * -> *) era. PParams' f era -> HKD f Natural
_maxBBSize = HKD Identity Natural
maxBBSize',
          _maxTxSize :: forall (f :: * -> *) era. PParams' f era -> HKD f Natural
_maxTxSize = HKD Identity Natural
maxTxSize',
          _maxBHSize :: forall (f :: * -> *) era. PParams' f era -> HKD f Natural
_maxBHSize = HKD Identity Natural
maxBHSize',
          _keyDeposit :: forall (f :: * -> *) era. PParams' f era -> HKD f Coin
_keyDeposit = HKD Identity Coin
keyDeposit',
          _poolDeposit :: forall (f :: * -> *) era. PParams' f era -> HKD f Coin
_poolDeposit = HKD Identity Coin
poolDeposit',
          _eMax :: forall (f :: * -> *) era. PParams' f era -> HKD f EpochNo
_eMax = HKD Identity EpochNo
eMax',
          _nOpt :: forall (f :: * -> *) era. PParams' f era -> HKD f Natural
_nOpt = HKD Identity Natural
nOpt',
          _a0 :: forall (f :: * -> *) era. PParams' f era -> HKD f Rational
_a0 = HKD Identity Rational
a0',
          _rho :: forall (f :: * -> *) era. PParams' f era -> HKD f UnitInterval
_rho = HKD Identity UnitInterval
rho',
          _tau :: forall (f :: * -> *) era. PParams' f era -> HKD f UnitInterval
_tau = HKD Identity UnitInterval
tau',
          _d :: forall (f :: * -> *) era. PParams' f era -> HKD f UnitInterval
_d = HKD Identity UnitInterval
d',
          _extraEntropy :: forall (f :: * -> *) era. PParams' f era -> HKD f Nonce
_extraEntropy = HKD Identity Nonce
extraEntropy',
          _protocolVersion :: forall (f :: * -> *) era. PParams' f era -> HKD f ProtVer
_protocolVersion = HKD Identity ProtVer
protocolVersion',
          _minUTxOValue :: forall (f :: * -> *) era. PParams' f era -> HKD f Coin
_minUTxOValue = HKD Identity Coin
minUTxOValue',
          _minPoolCost :: forall (f :: * -> *) era. PParams' f era -> HKD f Coin
_minPoolCost = HKD Identity Coin
minPoolCost'
        }
      ) =
      Word -> Encoding
encodeListLen Word
18
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Natural -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR Natural
HKD Identity Natural
minfeeA'
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Natural -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR Natural
HKD Identity Natural
minfeeB'
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Natural -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR Natural
HKD Identity Natural
maxBBSize'
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Natural -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR Natural
HKD Identity Natural
maxTxSize'
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Natural -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR Natural
HKD Identity Natural
maxBHSize'
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Coin -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR Coin
HKD Identity Coin
keyDeposit'
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Coin -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR Coin
HKD Identity Coin
poolDeposit'
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> EpochNo -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR EpochNo
HKD Identity EpochNo
eMax'
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Natural -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR Natural
HKD Identity Natural
nOpt'
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Rational -> Encoding
forall a. ToCBOR a => Ratio a -> Encoding
ratioToCBOR Rational
HKD Identity Rational
a0'
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> UnitInterval -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR UnitInterval
HKD Identity UnitInterval
rho'
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> UnitInterval -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR UnitInterval
HKD Identity UnitInterval
tau'
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> UnitInterval -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR UnitInterval
HKD Identity UnitInterval
d'
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Nonce -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR Nonce
HKD Identity Nonce
extraEntropy'
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> ProtVer -> Encoding
forall a. ToCBORGroup a => a -> Encoding
toCBORGroup ProtVer
HKD Identity ProtVer
protocolVersion'
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Coin -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR Coin
HKD Identity Coin
minUTxOValue'
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Coin -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR Coin
HKD Identity Coin
minPoolCost'

instance (Era era) => FromCBOR (PParams era) where
  fromCBOR :: Decoder s (PParams era)
fromCBOR = do
    Text
-> (PParams era -> Int)
-> Decoder s (PParams era)
-> Decoder s (PParams era)
forall a s. Text -> (a -> Int) -> Decoder s a -> Decoder s a
decodeRecordNamed Text
"PParams" (Int -> PParams era -> Int
forall a b. a -> b -> a
const Int
18) (Decoder s (PParams era) -> Decoder s (PParams era))
-> Decoder s (PParams era) -> Decoder s (PParams era)
forall a b. (a -> b) -> a -> b
$
      Natural
-> Natural
-> Natural
-> Natural
-> Natural
-> Coin
-> Coin
-> EpochNo
-> Natural
-> Rational
-> UnitInterval
-> UnitInterval
-> UnitInterval
-> Nonce
-> ProtVer
-> Coin
-> Coin
-> PParams era
forall (f :: * -> *) era.
HKD f Natural
-> HKD f Natural
-> HKD f Natural
-> HKD f Natural
-> HKD f Natural
-> HKD f Coin
-> HKD f Coin
-> HKD f EpochNo
-> HKD f Natural
-> HKD f Rational
-> HKD f UnitInterval
-> HKD f UnitInterval
-> HKD f UnitInterval
-> HKD f Nonce
-> HKD f ProtVer
-> HKD f Coin
-> HKD f Coin
-> PParams' f era
PParams
        (Natural
 -> Natural
 -> Natural
 -> Natural
 -> Natural
 -> Coin
 -> Coin
 -> EpochNo
 -> Natural
 -> Rational
 -> UnitInterval
 -> UnitInterval
 -> UnitInterval
 -> Nonce
 -> ProtVer
 -> Coin
 -> Coin
 -> PParams era)
-> Decoder s Natural
-> Decoder
     s
     (Natural
      -> Natural
      -> Natural
      -> Natural
      -> Coin
      -> Coin
      -> EpochNo
      -> Natural
      -> Rational
      -> UnitInterval
      -> UnitInterval
      -> UnitInterval
      -> Nonce
      -> ProtVer
      -> Coin
      -> Coin
      -> PParams era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Natural
forall a s. FromCBOR a => Decoder s a
fromCBOR -- _minfeeA         :: Integer
        Decoder
  s
  (Natural
   -> Natural
   -> Natural
   -> Natural
   -> Coin
   -> Coin
   -> EpochNo
   -> Natural
   -> Rational
   -> UnitInterval
   -> UnitInterval
   -> UnitInterval
   -> Nonce
   -> ProtVer
   -> Coin
   -> Coin
   -> PParams era)
-> Decoder s Natural
-> Decoder
     s
     (Natural
      -> Natural
      -> Natural
      -> Coin
      -> Coin
      -> EpochNo
      -> Natural
      -> Rational
      -> UnitInterval
      -> UnitInterval
      -> UnitInterval
      -> Nonce
      -> ProtVer
      -> Coin
      -> Coin
      -> PParams era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s Natural
forall a s. FromCBOR a => Decoder s a
fromCBOR -- _minfeeB         :: Natural
        Decoder
  s
  (Natural
   -> Natural
   -> Natural
   -> Coin
   -> Coin
   -> EpochNo
   -> Natural
   -> Rational
   -> UnitInterval
   -> UnitInterval
   -> UnitInterval
   -> Nonce
   -> ProtVer
   -> Coin
   -> Coin
   -> PParams era)
-> Decoder s Natural
-> Decoder
     s
     (Natural
      -> Natural
      -> Coin
      -> Coin
      -> EpochNo
      -> Natural
      -> Rational
      -> UnitInterval
      -> UnitInterval
      -> UnitInterval
      -> Nonce
      -> ProtVer
      -> Coin
      -> Coin
      -> PParams era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s Natural
forall a s. FromCBOR a => Decoder s a
fromCBOR -- _maxBBSize       :: Natural
        Decoder
  s
  (Natural
   -> Natural
   -> Coin
   -> Coin
   -> EpochNo
   -> Natural
   -> Rational
   -> UnitInterval
   -> UnitInterval
   -> UnitInterval
   -> Nonce
   -> ProtVer
   -> Coin
   -> Coin
   -> PParams era)
-> Decoder s Natural
-> Decoder
     s
     (Natural
      -> Coin
      -> Coin
      -> EpochNo
      -> Natural
      -> Rational
      -> UnitInterval
      -> UnitInterval
      -> UnitInterval
      -> Nonce
      -> ProtVer
      -> Coin
      -> Coin
      -> PParams era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s Natural
forall a s. FromCBOR a => Decoder s a
fromCBOR -- _maxTxSize       :: Natural
        Decoder
  s
  (Natural
   -> Coin
   -> Coin
   -> EpochNo
   -> Natural
   -> Rational
   -> UnitInterval
   -> UnitInterval
   -> UnitInterval
   -> Nonce
   -> ProtVer
   -> Coin
   -> Coin
   -> PParams era)
-> Decoder s Natural
-> Decoder
     s
     (Coin
      -> Coin
      -> EpochNo
      -> Natural
      -> Rational
      -> UnitInterval
      -> UnitInterval
      -> UnitInterval
      -> Nonce
      -> ProtVer
      -> Coin
      -> Coin
      -> PParams era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s Natural
forall a s. FromCBOR a => Decoder s a
fromCBOR -- _maxBHSize       :: Natural
        Decoder
  s
  (Coin
   -> Coin
   -> EpochNo
   -> Natural
   -> Rational
   -> UnitInterval
   -> UnitInterval
   -> UnitInterval
   -> Nonce
   -> ProtVer
   -> Coin
   -> Coin
   -> PParams era)
-> Decoder s Coin
-> Decoder
     s
     (Coin
      -> EpochNo
      -> Natural
      -> Rational
      -> UnitInterval
      -> UnitInterval
      -> UnitInterval
      -> Nonce
      -> ProtVer
      -> Coin
      -> Coin
      -> PParams era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s Coin
forall a s. FromCBOR a => Decoder s a
fromCBOR -- _keyDeposit      :: Coin
        Decoder
  s
  (Coin
   -> EpochNo
   -> Natural
   -> Rational
   -> UnitInterval
   -> UnitInterval
   -> UnitInterval
   -> Nonce
   -> ProtVer
   -> Coin
   -> Coin
   -> PParams era)
-> Decoder s Coin
-> Decoder
     s
     (EpochNo
      -> Natural
      -> Rational
      -> UnitInterval
      -> UnitInterval
      -> UnitInterval
      -> Nonce
      -> ProtVer
      -> Coin
      -> Coin
      -> PParams era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s Coin
forall a s. FromCBOR a => Decoder s a
fromCBOR -- _poolDeposit     :: Coin
        Decoder
  s
  (EpochNo
   -> Natural
   -> Rational
   -> UnitInterval
   -> UnitInterval
   -> UnitInterval
   -> Nonce
   -> ProtVer
   -> Coin
   -> Coin
   -> PParams era)
-> Decoder s EpochNo
-> Decoder
     s
     (Natural
      -> Rational
      -> UnitInterval
      -> UnitInterval
      -> UnitInterval
      -> Nonce
      -> ProtVer
      -> Coin
      -> Coin
      -> PParams era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s EpochNo
forall a s. FromCBOR a => Decoder s a
fromCBOR -- _eMax            :: EpochNo
        Decoder
  s
  (Natural
   -> Rational
   -> UnitInterval
   -> UnitInterval
   -> UnitInterval
   -> Nonce
   -> ProtVer
   -> Coin
   -> Coin
   -> PParams era)
-> Decoder s Natural
-> Decoder
     s
     (Rational
      -> UnitInterval
      -> UnitInterval
      -> UnitInterval
      -> Nonce
      -> ProtVer
      -> Coin
      -> Coin
      -> PParams era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s Natural
forall a s. FromCBOR a => Decoder s a
fromCBOR -- _nOpt            :: Natural
        Decoder
  s
  (Rational
   -> UnitInterval
   -> UnitInterval
   -> UnitInterval
   -> Nonce
   -> ProtVer
   -> Coin
   -> Coin
   -> PParams era)
-> Decoder s Rational
-> Decoder
     s
     (UnitInterval
      -> UnitInterval
      -> UnitInterval
      -> Nonce
      -> ProtVer
      -> Coin
      -> Coin
      -> PParams era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s Rational
forall a s. (Integral a, FromCBOR a) => Decoder s (Ratio a)
ratioFromCBOR -- _a0         :: Rational
        Decoder
  s
  (UnitInterval
   -> UnitInterval
   -> UnitInterval
   -> Nonce
   -> ProtVer
   -> Coin
   -> Coin
   -> PParams era)
-> Decoder s UnitInterval
-> Decoder
     s
     (UnitInterval
      -> UnitInterval -> Nonce -> ProtVer -> Coin -> Coin -> PParams era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s UnitInterval
forall a s. FromCBOR a => Decoder s a
fromCBOR -- _rho             :: UnitInterval
        Decoder
  s
  (UnitInterval
   -> UnitInterval -> Nonce -> ProtVer -> Coin -> Coin -> PParams era)
-> Decoder s UnitInterval
-> Decoder
     s (UnitInterval -> Nonce -> ProtVer -> Coin -> Coin -> PParams era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s UnitInterval
forall a s. FromCBOR a => Decoder s a
fromCBOR -- _tau             :: UnitInterval
        Decoder
  s (UnitInterval -> Nonce -> ProtVer -> Coin -> Coin -> PParams era)
-> Decoder s UnitInterval
-> Decoder s (Nonce -> ProtVer -> Coin -> Coin -> PParams era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s UnitInterval
forall a s. FromCBOR a => Decoder s a
fromCBOR -- _d               :: UnitInterval
        Decoder s (Nonce -> ProtVer -> Coin -> Coin -> PParams era)
-> Decoder s Nonce
-> Decoder s (ProtVer -> Coin -> Coin -> PParams era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s Nonce
forall a s. FromCBOR a => Decoder s a
fromCBOR -- _extraEntropy    :: Nonce
        Decoder s (ProtVer -> Coin -> Coin -> PParams era)
-> Decoder s ProtVer -> Decoder s (Coin -> Coin -> PParams era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s ProtVer
forall a s. FromCBORGroup a => Decoder s a
fromCBORGroup -- _protocolVersion :: ProtVer
        Decoder s (Coin -> Coin -> PParams era)
-> Decoder s Coin -> Decoder s (Coin -> PParams era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s Coin
forall a s. FromCBOR a => Decoder s a
fromCBOR -- _minUTxOValue    :: Natural
        Decoder s (Coin -> PParams era)
-> Decoder s Coin -> Decoder s (PParams era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s Coin
forall a s. FromCBOR a => Decoder s a
fromCBOR -- _minPoolCost     :: Natural

instance ToJSON (PParams era) where
  toJSON :: PParams era -> Value
toJSON PParams era
pp =
    [Pair] -> Value
Aeson.object
      [ Text
"minFeeA" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= PParams era -> HKD Identity Natural
forall (f :: * -> *) era. PParams' f era -> HKD f Natural
_minfeeA PParams era
pp,
        Text
"minFeeB" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= PParams era -> HKD Identity Natural
forall (f :: * -> *) era. PParams' f era -> HKD f Natural
_minfeeB PParams era
pp,
        Text
"maxBlockBodySize" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= PParams era -> HKD Identity Natural
forall (f :: * -> *) era. PParams' f era -> HKD f Natural
_maxBBSize PParams era
pp,
        Text
"maxTxSize" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= PParams era -> HKD Identity Natural
forall (f :: * -> *) era. PParams' f era -> HKD f Natural
_maxTxSize PParams era
pp,
        Text
"maxBlockHeaderSize" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= PParams era -> HKD Identity Natural
forall (f :: * -> *) era. PParams' f era -> HKD f Natural
_maxBHSize PParams era
pp,
        Text
"keyDeposit" Text -> Coin -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= PParams era -> HKD Identity Coin
forall (f :: * -> *) era. PParams' f era -> HKD f Coin
_keyDeposit PParams era
pp,
        Text
"poolDeposit" Text -> Coin -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= PParams era -> HKD Identity Coin
forall (f :: * -> *) era. PParams' f era -> HKD f Coin
_poolDeposit PParams era
pp,
        Text
"eMax" Text -> EpochNo -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= PParams era -> HKD Identity EpochNo
forall (f :: * -> *) era. PParams' f era -> HKD f EpochNo
_eMax PParams era
pp,
        Text
"nOpt" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= PParams era -> HKD Identity Natural
forall (f :: * -> *) era. PParams' f era -> HKD f Natural
_nOpt PParams era
pp,
        Text
"a0" Text -> Scientific -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= (Rational -> Scientific
forall a. Fractional a => Rational -> a
fromRational (PParams era -> HKD Identity Rational
forall (f :: * -> *) era. PParams' f era -> HKD f Rational
_a0 PParams era
pp) :: Scientific),
        Text
"rho" Text -> UnitInterval -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= PParams era -> HKD Identity UnitInterval
forall (f :: * -> *) era. PParams' f era -> HKD f UnitInterval
_rho PParams era
pp,
        Text
"tau" Text -> UnitInterval -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= PParams era -> HKD Identity UnitInterval
forall (f :: * -> *) era. PParams' f era -> HKD f UnitInterval
_tau PParams era
pp,
        Text
"decentralisationParam" Text -> UnitInterval -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= PParams era -> HKD Identity UnitInterval
forall (f :: * -> *) era. PParams' f era -> HKD f UnitInterval
_d PParams era
pp,
        Text
"extraEntropy" Text -> Nonce -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= PParams era -> HKD Identity Nonce
forall (f :: * -> *) era. PParams' f era -> HKD f Nonce
_extraEntropy PParams era
pp,
        Text
"protocolVersion" Text -> ProtVer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= PParams era -> HKD Identity ProtVer
forall (f :: * -> *) era. PParams' f era -> HKD f ProtVer
_protocolVersion PParams era
pp,
        Text
"minUTxOValue" Text -> Coin -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= PParams era -> HKD Identity Coin
forall (f :: * -> *) era. PParams' f era -> HKD f Coin
_minUTxOValue PParams era
pp,
        Text
"minPoolCost" Text -> Coin -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= PParams era -> HKD Identity Coin
forall (f :: * -> *) era. PParams' f era -> HKD f Coin
_minPoolCost PParams era
pp
      ]

instance FromJSON (PParams era) where
  parseJSON :: Value -> Parser (PParams era)
parseJSON =
    String
-> (Object -> Parser (PParams era))
-> Value
-> Parser (PParams era)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"PParams" ((Object -> Parser (PParams era)) -> Value -> Parser (PParams era))
-> (Object -> Parser (PParams era))
-> Value
-> Parser (PParams era)
forall a b. (a -> b) -> a -> b
$ \Object
obj ->
      Natural
-> Natural
-> Natural
-> Natural
-> Natural
-> Coin
-> Coin
-> EpochNo
-> Natural
-> Rational
-> UnitInterval
-> UnitInterval
-> UnitInterval
-> Nonce
-> ProtVer
-> Coin
-> Coin
-> PParams era
forall (f :: * -> *) era.
HKD f Natural
-> HKD f Natural
-> HKD f Natural
-> HKD f Natural
-> HKD f Natural
-> HKD f Coin
-> HKD f Coin
-> HKD f EpochNo
-> HKD f Natural
-> HKD f Rational
-> HKD f UnitInterval
-> HKD f UnitInterval
-> HKD f UnitInterval
-> HKD f Nonce
-> HKD f ProtVer
-> HKD f Coin
-> HKD f Coin
-> PParams' f era
PParams
        (Natural
 -> Natural
 -> Natural
 -> Natural
 -> Natural
 -> Coin
 -> Coin
 -> EpochNo
 -> Natural
 -> Rational
 -> UnitInterval
 -> UnitInterval
 -> UnitInterval
 -> Nonce
 -> ProtVer
 -> Coin
 -> Coin
 -> PParams era)
-> Parser Natural
-> Parser
     (Natural
      -> Natural
      -> Natural
      -> Natural
      -> Coin
      -> Coin
      -> EpochNo
      -> Natural
      -> Rational
      -> UnitInterval
      -> UnitInterval
      -> UnitInterval
      -> Nonce
      -> ProtVer
      -> Coin
      -> Coin
      -> PParams era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"minFeeA"
        Parser
  (Natural
   -> Natural
   -> Natural
   -> Natural
   -> Coin
   -> Coin
   -> EpochNo
   -> Natural
   -> Rational
   -> UnitInterval
   -> UnitInterval
   -> UnitInterval
   -> Nonce
   -> ProtVer
   -> Coin
   -> Coin
   -> PParams era)
-> Parser Natural
-> Parser
     (Natural
      -> Natural
      -> Natural
      -> Coin
      -> Coin
      -> EpochNo
      -> Natural
      -> Rational
      -> UnitInterval
      -> UnitInterval
      -> UnitInterval
      -> Nonce
      -> ProtVer
      -> Coin
      -> Coin
      -> PParams era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"minFeeB"
        Parser
  (Natural
   -> Natural
   -> Natural
   -> Coin
   -> Coin
   -> EpochNo
   -> Natural
   -> Rational
   -> UnitInterval
   -> UnitInterval
   -> UnitInterval
   -> Nonce
   -> ProtVer
   -> Coin
   -> Coin
   -> PParams era)
-> Parser Natural
-> Parser
     (Natural
      -> Natural
      -> Coin
      -> Coin
      -> EpochNo
      -> Natural
      -> Rational
      -> UnitInterval
      -> UnitInterval
      -> UnitInterval
      -> Nonce
      -> ProtVer
      -> Coin
      -> Coin
      -> PParams era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"maxBlockBodySize"
        Parser
  (Natural
   -> Natural
   -> Coin
   -> Coin
   -> EpochNo
   -> Natural
   -> Rational
   -> UnitInterval
   -> UnitInterval
   -> UnitInterval
   -> Nonce
   -> ProtVer
   -> Coin
   -> Coin
   -> PParams era)
-> Parser Natural
-> Parser
     (Natural
      -> Coin
      -> Coin
      -> EpochNo
      -> Natural
      -> Rational
      -> UnitInterval
      -> UnitInterval
      -> UnitInterval
      -> Nonce
      -> ProtVer
      -> Coin
      -> Coin
      -> PParams era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"maxTxSize"
        Parser
  (Natural
   -> Coin
   -> Coin
   -> EpochNo
   -> Natural
   -> Rational
   -> UnitInterval
   -> UnitInterval
   -> UnitInterval
   -> Nonce
   -> ProtVer
   -> Coin
   -> Coin
   -> PParams era)
-> Parser Natural
-> Parser
     (Coin
      -> Coin
      -> EpochNo
      -> Natural
      -> Rational
      -> UnitInterval
      -> UnitInterval
      -> UnitInterval
      -> Nonce
      -> ProtVer
      -> Coin
      -> Coin
      -> PParams era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"maxBlockHeaderSize"
        Parser
  (Coin
   -> Coin
   -> EpochNo
   -> Natural
   -> Rational
   -> UnitInterval
   -> UnitInterval
   -> UnitInterval
   -> Nonce
   -> ProtVer
   -> Coin
   -> Coin
   -> PParams era)
-> Parser Coin
-> Parser
     (Coin
      -> EpochNo
      -> Natural
      -> Rational
      -> UnitInterval
      -> UnitInterval
      -> UnitInterval
      -> Nonce
      -> ProtVer
      -> Coin
      -> Coin
      -> PParams era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Text -> Parser Coin
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"keyDeposit"
        Parser
  (Coin
   -> EpochNo
   -> Natural
   -> Rational
   -> UnitInterval
   -> UnitInterval
   -> UnitInterval
   -> Nonce
   -> ProtVer
   -> Coin
   -> Coin
   -> PParams era)
-> Parser Coin
-> Parser
     (EpochNo
      -> Natural
      -> Rational
      -> UnitInterval
      -> UnitInterval
      -> UnitInterval
      -> Nonce
      -> ProtVer
      -> Coin
      -> Coin
      -> PParams era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Text -> Parser Coin
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"poolDeposit"
        Parser
  (EpochNo
   -> Natural
   -> Rational
   -> UnitInterval
   -> UnitInterval
   -> UnitInterval
   -> Nonce
   -> ProtVer
   -> Coin
   -> Coin
   -> PParams era)
-> Parser EpochNo
-> Parser
     (Natural
      -> Rational
      -> UnitInterval
      -> UnitInterval
      -> UnitInterval
      -> Nonce
      -> ProtVer
      -> Coin
      -> Coin
      -> PParams era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Text -> Parser EpochNo
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"eMax"
        Parser
  (Natural
   -> Rational
   -> UnitInterval
   -> UnitInterval
   -> UnitInterval
   -> Nonce
   -> ProtVer
   -> Coin
   -> Coin
   -> PParams era)
-> Parser Natural
-> Parser
     (Rational
      -> UnitInterval
      -> UnitInterval
      -> UnitInterval
      -> Nonce
      -> ProtVer
      -> Coin
      -> Coin
      -> PParams era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"nOpt"
        Parser
  (Rational
   -> UnitInterval
   -> UnitInterval
   -> UnitInterval
   -> Nonce
   -> ProtVer
   -> Coin
   -> Coin
   -> PParams era)
-> Parser Rational
-> Parser
     (UnitInterval
      -> UnitInterval
      -> UnitInterval
      -> Nonce
      -> ProtVer
      -> Coin
      -> Coin
      -> PParams era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ( (Scientific -> Rational
forall a. Real a => a -> Rational
toRational :: Scientific -> Rational)
                (Scientific -> Rational) -> Parser Scientific -> Parser Rational
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Text -> Parser Scientific
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"a0"
            )
        Parser
  (UnitInterval
   -> UnitInterval
   -> UnitInterval
   -> Nonce
   -> ProtVer
   -> Coin
   -> Coin
   -> PParams era)
-> Parser UnitInterval
-> Parser
     (UnitInterval
      -> UnitInterval -> Nonce -> ProtVer -> Coin -> Coin -> PParams era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Text -> Parser UnitInterval
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"rho"
        Parser
  (UnitInterval
   -> UnitInterval -> Nonce -> ProtVer -> Coin -> Coin -> PParams era)
-> Parser UnitInterval
-> Parser
     (UnitInterval -> Nonce -> ProtVer -> Coin -> Coin -> PParams era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Text -> Parser UnitInterval
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"tau"
        Parser
  (UnitInterval -> Nonce -> ProtVer -> Coin -> Coin -> PParams era)
-> Parser UnitInterval
-> Parser (Nonce -> ProtVer -> Coin -> Coin -> PParams era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Text -> Parser UnitInterval
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"decentralisationParam"
        Parser (Nonce -> ProtVer -> Coin -> Coin -> PParams era)
-> Parser Nonce -> Parser (ProtVer -> Coin -> Coin -> PParams era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Text -> Parser Nonce
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"extraEntropy"
        Parser (ProtVer -> Coin -> Coin -> PParams era)
-> Parser ProtVer -> Parser (Coin -> Coin -> PParams era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Text -> Parser ProtVer
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"protocolVersion"
        Parser (Coin -> Coin -> PParams era)
-> Parser Coin -> Parser (Coin -> PParams era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Text -> Parser (Maybe Coin)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"minUTxOValue" Parser (Maybe Coin) -> Coin -> Parser Coin
forall a. Parser (Maybe a) -> a -> Parser a
.!= Coin
forall a. Monoid a => a
mempty
        Parser (Coin -> PParams era) -> Parser Coin -> Parser (PParams era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Text -> Parser (Maybe Coin)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"minPoolCost" Parser (Maybe Coin) -> Coin -> Parser Coin
forall a. Parser (Maybe a) -> a -> Parser a
.!= Coin
forall a. Monoid a => a
mempty

-- | Returns a basic "empty" `PParams` structure with all zero values.
emptyPParams :: PParams era
emptyPParams :: PParams era
emptyPParams =
  PParams :: forall (f :: * -> *) era.
HKD f Natural
-> HKD f Natural
-> HKD f Natural
-> HKD f Natural
-> HKD f Natural
-> HKD f Coin
-> HKD f Coin
-> HKD f EpochNo
-> HKD f Natural
-> HKD f Rational
-> HKD f UnitInterval
-> HKD f UnitInterval
-> HKD f UnitInterval
-> HKD f Nonce
-> HKD f ProtVer
-> HKD f Coin
-> HKD f Coin
-> PParams' f era
PParams
    { _minfeeA :: HKD Identity Natural
_minfeeA = HKD Identity Natural
0,
      _minfeeB :: HKD Identity Natural
_minfeeB = HKD Identity Natural
0,
      _maxBBSize :: HKD Identity Natural
_maxBBSize = HKD Identity Natural
0,
      _maxTxSize :: HKD Identity Natural
_maxTxSize = HKD Identity Natural
2048,
      _maxBHSize :: HKD Identity Natural
_maxBHSize = HKD Identity Natural
0,
      _keyDeposit :: HKD Identity Coin
_keyDeposit = Integer -> Coin
Coin Integer
0,
      _poolDeposit :: HKD Identity Coin
_poolDeposit = Integer -> Coin
Coin Integer
0,
      _eMax :: HKD Identity EpochNo
_eMax = Word64 -> EpochNo
EpochNo Word64
0,
      _nOpt :: HKD Identity Natural
_nOpt = HKD Identity Natural
100,
      _a0 :: HKD Identity Rational
_a0 = HKD Identity Rational
0,
      _rho :: HKD Identity UnitInterval
_rho = UnitInterval
HKD Identity UnitInterval
interval0,
      _tau :: HKD Identity UnitInterval
_tau = UnitInterval
HKD Identity UnitInterval
interval0,
      _d :: HKD Identity UnitInterval
_d = UnitInterval
HKD Identity UnitInterval
interval0,
      _extraEntropy :: HKD Identity Nonce
_extraEntropy = Nonce
HKD Identity Nonce
NeutralNonce,
      _protocolVersion :: HKD Identity ProtVer
_protocolVersion = Natural -> Natural -> ProtVer
ProtVer Natural
0 Natural
0,
      _minUTxOValue :: HKD Identity Coin
_minUTxOValue = HKD Identity Coin
forall a. Monoid a => a
mempty,
      _minPoolCost :: HKD Identity Coin
_minPoolCost = HKD Identity Coin
forall a. Monoid a => a
mempty
    }

-- | Update Proposal
data Update era
  = Update !(ProposedPPUpdates era) !EpochNo
  deriving (Int -> Update era -> ShowS
[Update era] -> ShowS
Update era -> String
(Int -> Update era -> ShowS)
-> (Update era -> String)
-> ([Update era] -> ShowS)
-> Show (Update era)
forall era. Int -> Update era -> ShowS
forall era. [Update era] -> ShowS
forall era. Update era -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Update era] -> ShowS
$cshowList :: forall era. [Update era] -> ShowS
show :: Update era -> String
$cshow :: forall era. Update era -> String
showsPrec :: Int -> Update era -> ShowS
$cshowsPrec :: forall era. Int -> Update era -> ShowS
Show, Update era -> Update era -> Bool
(Update era -> Update era -> Bool)
-> (Update era -> Update era -> Bool) -> Eq (Update era)
forall era. Update era -> Update era -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Update era -> Update era -> Bool
$c/= :: forall era. Update era -> Update era -> Bool
== :: Update era -> Update era -> Bool
$c== :: forall era. Update era -> Update era -> Bool
Eq, (forall x. Update era -> Rep (Update era) x)
-> (forall x. Rep (Update era) x -> Update era)
-> Generic (Update era)
forall x. Rep (Update era) x -> Update era
forall x. Update era -> Rep (Update era) x
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)

instance NoThunks (Update era)

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

instance Era era => FromCBOR (Update era) where
  fromCBOR :: Decoder s (Update era)
fromCBOR = Text
-> (Update era -> Int)
-> Decoder s (Update era)
-> Decoder s (Update era)
forall a s. Text -> (a -> Int) -> Decoder s a -> Decoder s a
decodeRecordNamed Text
"Update" (Int -> Update era -> Int
forall a b. a -> b -> a
const Int
2) (Decoder s (Update era) -> Decoder s (Update era))
-> Decoder s (Update era) -> Decoder s (Update era)
forall a b. (a -> b) -> a -> b
$ do
    ProposedPPUpdates era
x <- Decoder s (ProposedPPUpdates era)
forall a s. FromCBOR a => Decoder s a
fromCBOR
    EpochNo
y <- Decoder s EpochNo
forall a s. FromCBOR a => Decoder s a
fromCBOR
    Update era -> Decoder s (Update era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ProposedPPUpdates era -> EpochNo -> Update era
forall era. ProposedPPUpdates era -> EpochNo -> Update era
Update ProposedPPUpdates era
x EpochNo
y)

data PPUpdateEnv era = PPUpdateEnv SlotNo (GenDelegs era)
  deriving (Int -> PPUpdateEnv era -> ShowS
[PPUpdateEnv era] -> ShowS
PPUpdateEnv era -> String
(Int -> PPUpdateEnv era -> ShowS)
-> (PPUpdateEnv era -> String)
-> ([PPUpdateEnv era] -> ShowS)
-> Show (PPUpdateEnv era)
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
(PPUpdateEnv era -> PPUpdateEnv era -> Bool)
-> (PPUpdateEnv era -> PPUpdateEnv era -> Bool)
-> Eq (PPUpdateEnv era)
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 x. PPUpdateEnv era -> Rep (PPUpdateEnv era) x)
-> (forall x. Rep (PPUpdateEnv era) x -> PPUpdateEnv era)
-> Generic (PPUpdateEnv era)
forall x. Rep (PPUpdateEnv era) x -> PPUpdateEnv era
forall x. PPUpdateEnv era -> Rep (PPUpdateEnv era) x
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)

type PParamsUpdate era = PParams' StrictMaybe era

deriving instance Eq (PParams' StrictMaybe era)

deriving instance Show (PParams' StrictMaybe era)

deriving instance Ord (PParams' StrictMaybe era)

deriving instance NFData (PParams' StrictMaybe era)

instance NoThunks (PParamsUpdate era)

instance (Era era) => ToCBOR (PParamsUpdate era) where
  toCBOR :: PParamsUpdate era -> Encoding
toCBOR PParamsUpdate era
ppup =
    let l :: [Encoding]
l =
          (StrictMaybe Encoding -> Maybe Encoding)
-> [StrictMaybe Encoding] -> [Encoding]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe
            StrictMaybe Encoding -> Maybe Encoding
forall a. StrictMaybe a -> Maybe a
strictMaybeToMaybe
            [ Word -> (Natural -> Encoding) -> Natural -> StrictMaybe Encoding
forall t. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
0 Natural -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (Natural -> StrictMaybe Encoding)
-> StrictMaybe Natural -> StrictMaybe Encoding
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< PParamsUpdate era -> HKD StrictMaybe Natural
forall (f :: * -> *) era. PParams' f era -> HKD f Natural
_minfeeA PParamsUpdate era
ppup,
              Word -> (Natural -> Encoding) -> Natural -> StrictMaybe Encoding
forall t. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
1 Natural -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (Natural -> StrictMaybe Encoding)
-> StrictMaybe Natural -> StrictMaybe Encoding
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< PParamsUpdate era -> HKD StrictMaybe Natural
forall (f :: * -> *) era. PParams' f era -> HKD f Natural
_minfeeB PParamsUpdate era
ppup,
              Word -> (Natural -> Encoding) -> Natural -> StrictMaybe Encoding
forall t. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
2 Natural -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (Natural -> StrictMaybe Encoding)
-> StrictMaybe Natural -> StrictMaybe Encoding
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< PParamsUpdate era -> HKD StrictMaybe Natural
forall (f :: * -> *) era. PParams' f era -> HKD f Natural
_maxBBSize PParamsUpdate era
ppup,
              Word -> (Natural -> Encoding) -> Natural -> StrictMaybe Encoding
forall t. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
3 Natural -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (Natural -> StrictMaybe Encoding)
-> StrictMaybe Natural -> StrictMaybe Encoding
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< PParamsUpdate era -> HKD StrictMaybe Natural
forall (f :: * -> *) era. PParams' f era -> HKD f Natural
_maxTxSize PParamsUpdate era
ppup,
              Word -> (Natural -> Encoding) -> Natural -> StrictMaybe Encoding
forall t. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
4 Natural -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (Natural -> StrictMaybe Encoding)
-> StrictMaybe Natural -> StrictMaybe Encoding
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< PParamsUpdate era -> HKD StrictMaybe Natural
forall (f :: * -> *) era. PParams' f era -> HKD f Natural
_maxBHSize PParamsUpdate era
ppup,
              Word -> (Coin -> Encoding) -> Coin -> StrictMaybe Encoding
forall t. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
5 Coin -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (Coin -> StrictMaybe Encoding)
-> StrictMaybe Coin -> StrictMaybe Encoding
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< PParamsUpdate era -> HKD StrictMaybe Coin
forall (f :: * -> *) era. PParams' f era -> HKD f Coin
_keyDeposit PParamsUpdate era
ppup,
              Word -> (Coin -> Encoding) -> Coin -> StrictMaybe Encoding
forall t. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
6 Coin -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (Coin -> StrictMaybe Encoding)
-> StrictMaybe Coin -> StrictMaybe Encoding
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< PParamsUpdate era -> HKD StrictMaybe Coin
forall (f :: * -> *) era. PParams' f era -> HKD f Coin
_poolDeposit PParamsUpdate era
ppup,
              Word -> (EpochNo -> Encoding) -> EpochNo -> StrictMaybe Encoding
forall t. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
7 EpochNo -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (EpochNo -> StrictMaybe Encoding)
-> StrictMaybe EpochNo -> StrictMaybe Encoding
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< PParamsUpdate era -> HKD StrictMaybe EpochNo
forall (f :: * -> *) era. PParams' f era -> HKD f EpochNo
_eMax PParamsUpdate era
ppup,
              Word -> (Natural -> Encoding) -> Natural -> StrictMaybe Encoding
forall t. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
8 Natural -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (Natural -> StrictMaybe Encoding)
-> StrictMaybe Natural -> StrictMaybe Encoding
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< PParamsUpdate era -> HKD StrictMaybe Natural
forall (f :: * -> *) era. PParams' f era -> HKD f Natural
_nOpt PParamsUpdate era
ppup,
              Word -> (Rational -> Encoding) -> Rational -> StrictMaybe Encoding
forall t. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
9 Rational -> Encoding
forall a. ToCBOR a => Ratio a -> Encoding
ratioToCBOR (Rational -> StrictMaybe Encoding)
-> StrictMaybe Rational -> StrictMaybe Encoding
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< PParamsUpdate era -> HKD StrictMaybe Rational
forall (f :: * -> *) era. PParams' f era -> HKD f Rational
_a0 PParamsUpdate era
ppup,
              Word
-> (UnitInterval -> Encoding)
-> UnitInterval
-> StrictMaybe Encoding
forall t. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
10 UnitInterval -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (UnitInterval -> StrictMaybe Encoding)
-> StrictMaybe UnitInterval -> StrictMaybe Encoding
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< PParamsUpdate era -> HKD StrictMaybe UnitInterval
forall (f :: * -> *) era. PParams' f era -> HKD f UnitInterval
_rho PParamsUpdate era
ppup,
              Word
-> (UnitInterval -> Encoding)
-> UnitInterval
-> StrictMaybe Encoding
forall t. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
11 UnitInterval -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (UnitInterval -> StrictMaybe Encoding)
-> StrictMaybe UnitInterval -> StrictMaybe Encoding
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< PParamsUpdate era -> HKD StrictMaybe UnitInterval
forall (f :: * -> *) era. PParams' f era -> HKD f UnitInterval
_tau PParamsUpdate era
ppup,
              Word
-> (UnitInterval -> Encoding)
-> UnitInterval
-> StrictMaybe Encoding
forall t. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
12 UnitInterval -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (UnitInterval -> StrictMaybe Encoding)
-> StrictMaybe UnitInterval -> StrictMaybe Encoding
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< PParamsUpdate era -> HKD StrictMaybe UnitInterval
forall (f :: * -> *) era. PParams' f era -> HKD f UnitInterval
_d PParamsUpdate era
ppup,
              Word -> (Nonce -> Encoding) -> Nonce -> StrictMaybe Encoding
forall t. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
13 Nonce -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (Nonce -> StrictMaybe Encoding)
-> StrictMaybe Nonce -> StrictMaybe Encoding
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< PParamsUpdate era -> HKD StrictMaybe Nonce
forall (f :: * -> *) era. PParams' f era -> HKD f Nonce
_extraEntropy PParamsUpdate era
ppup,
              Word -> (ProtVer -> Encoding) -> ProtVer -> StrictMaybe Encoding
forall t. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
14 ProtVer -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (ProtVer -> StrictMaybe Encoding)
-> StrictMaybe ProtVer -> StrictMaybe Encoding
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< PParamsUpdate era -> HKD StrictMaybe ProtVer
forall (f :: * -> *) era. PParams' f era -> HKD f ProtVer
_protocolVersion PParamsUpdate era
ppup,
              Word -> (Coin -> Encoding) -> Coin -> StrictMaybe Encoding
forall t. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
15 Coin -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (Coin -> StrictMaybe Encoding)
-> StrictMaybe Coin -> StrictMaybe Encoding
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< PParamsUpdate era -> HKD StrictMaybe Coin
forall (f :: * -> *) era. PParams' f era -> HKD f Coin
_minUTxOValue PParamsUpdate era
ppup,
              Word -> (Coin -> Encoding) -> Coin -> StrictMaybe Encoding
forall t. Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
16 Coin -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (Coin -> StrictMaybe Encoding)
-> StrictMaybe Coin -> StrictMaybe Encoding
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< PParamsUpdate era -> HKD StrictMaybe Coin
forall (f :: * -> *) era. PParams' f era -> HKD f Coin
_minPoolCost PParamsUpdate era
ppup
            ]
        n :: Word
n = Int -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Word) -> Int -> Word
forall a b. (a -> b) -> a -> b
$ [Encoding] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Encoding]
l
     in Word -> Encoding
encodeMapLen Word
n Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> [Encoding] -> Encoding
forall (t :: * -> *) m. (Foldable t, Monoid m) => t m -> m
fold [Encoding]
l
    where
      encodeMapElement :: Word -> (t -> Encoding) -> t -> StrictMaybe Encoding
encodeMapElement Word
ix t -> Encoding
encoder t
x = Encoding -> StrictMaybe Encoding
forall a. a -> StrictMaybe a
SJust (Word -> Encoding
encodeWord Word
ix Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> t -> Encoding
encoder t
x)

emptyPParamsUpdate :: PParamsUpdate era
emptyPParamsUpdate :: PParamsUpdate era
emptyPParamsUpdate =
  PParams :: forall (f :: * -> *) era.
HKD f Natural
-> HKD f Natural
-> HKD f Natural
-> HKD f Natural
-> HKD f Natural
-> HKD f Coin
-> HKD f Coin
-> HKD f EpochNo
-> HKD f Natural
-> HKD f Rational
-> HKD f UnitInterval
-> HKD f UnitInterval
-> HKD f UnitInterval
-> HKD f Nonce
-> HKD f ProtVer
-> HKD f Coin
-> HKD f Coin
-> PParams' f era
PParams
    { _minfeeA :: HKD StrictMaybe Natural
_minfeeA = HKD StrictMaybe Natural
forall a. StrictMaybe a
SNothing,
      _minfeeB :: HKD StrictMaybe Natural
_minfeeB = HKD StrictMaybe Natural
forall a. StrictMaybe a
SNothing,
      _maxBBSize :: HKD StrictMaybe Natural
_maxBBSize = HKD StrictMaybe Natural
forall a. StrictMaybe a
SNothing,
      _maxTxSize :: HKD StrictMaybe Natural
_maxTxSize = HKD StrictMaybe Natural
forall a. StrictMaybe a
SNothing,
      _maxBHSize :: HKD StrictMaybe Natural
_maxBHSize = HKD StrictMaybe Natural
forall a. StrictMaybe a
SNothing,
      _keyDeposit :: HKD StrictMaybe Coin
_keyDeposit = HKD StrictMaybe Coin
forall a. StrictMaybe a
SNothing,
      _poolDeposit :: HKD StrictMaybe Coin
_poolDeposit = HKD StrictMaybe Coin
forall a. StrictMaybe a
SNothing,
      _eMax :: HKD StrictMaybe EpochNo
_eMax = HKD StrictMaybe EpochNo
forall a. StrictMaybe a
SNothing,
      _nOpt :: HKD StrictMaybe Natural
_nOpt = HKD StrictMaybe Natural
forall a. StrictMaybe a
SNothing,
      _a0 :: HKD StrictMaybe Rational
_a0 = HKD StrictMaybe Rational
forall a. StrictMaybe a
SNothing,
      _rho :: HKD StrictMaybe UnitInterval
_rho = HKD StrictMaybe UnitInterval
forall a. StrictMaybe a
SNothing,
      _tau :: HKD StrictMaybe UnitInterval
_tau = HKD StrictMaybe UnitInterval
forall a. StrictMaybe a
SNothing,
      _d :: HKD StrictMaybe UnitInterval
_d = HKD StrictMaybe UnitInterval
forall a. StrictMaybe a
SNothing,
      _extraEntropy :: HKD StrictMaybe Nonce
_extraEntropy = HKD StrictMaybe Nonce
forall a. StrictMaybe a
SNothing,
      _protocolVersion :: HKD StrictMaybe ProtVer
_protocolVersion = HKD StrictMaybe ProtVer
forall a. StrictMaybe a
SNothing,
      _minUTxOValue :: HKD StrictMaybe Coin
_minUTxOValue = HKD StrictMaybe Coin
forall a. StrictMaybe a
SNothing,
      _minPoolCost :: HKD StrictMaybe Coin
_minPoolCost = HKD StrictMaybe Coin
forall a. StrictMaybe a
SNothing
    }

instance (Era era) => FromCBOR (PParamsUpdate era) where
  fromCBOR :: Decoder s (PParamsUpdate era)
fromCBOR = do
    [(Int, PParamsUpdate era -> PParamsUpdate era)]
mapParts <-
      Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
-> Decoder s [(Int, PParamsUpdate era -> PParamsUpdate era)]
forall s a. Decoder s a -> Decoder s [a]
decodeMapContents (Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
 -> Decoder s [(Int, PParamsUpdate era -> PParamsUpdate era)])
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
-> Decoder s [(Int, PParamsUpdate era -> PParamsUpdate era)]
forall a b. (a -> b) -> a -> b
$
        Decoder s Word
forall s. Decoder s Word
decodeWord Decoder s Word
-> (Word
    -> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era))
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
          Word
0 -> Decoder s Natural
forall a s. FromCBOR a => Decoder s a
fromCBOR Decoder s Natural
-> (Natural
    -> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era))
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Natural
x -> (Int, PParamsUpdate era -> PParamsUpdate era)
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
0, \PParamsUpdate era
up -> PParamsUpdate era
up {_minfeeA :: HKD StrictMaybe Natural
_minfeeA = Natural -> StrictMaybe Natural
forall a. a -> StrictMaybe a
SJust Natural
x})
          Word
1 -> Decoder s Natural
forall a s. FromCBOR a => Decoder s a
fromCBOR Decoder s Natural
-> (Natural
    -> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era))
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Natural
x -> (Int, PParamsUpdate era -> PParamsUpdate era)
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
1, \PParamsUpdate era
up -> PParamsUpdate era
up {_minfeeB :: HKD StrictMaybe Natural
_minfeeB = Natural -> StrictMaybe Natural
forall a. a -> StrictMaybe a
SJust Natural
x})
          Word
2 -> Decoder s Natural
forall a s. FromCBOR a => Decoder s a
fromCBOR Decoder s Natural
-> (Natural
    -> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era))
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Natural
x -> (Int, PParamsUpdate era -> PParamsUpdate era)
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
2, \PParamsUpdate era
up -> PParamsUpdate era
up {_maxBBSize :: HKD StrictMaybe Natural
_maxBBSize = Natural -> StrictMaybe Natural
forall a. a -> StrictMaybe a
SJust Natural
x})
          Word
3 -> Decoder s Natural
forall a s. FromCBOR a => Decoder s a
fromCBOR Decoder s Natural
-> (Natural
    -> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era))
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Natural
x -> (Int, PParamsUpdate era -> PParamsUpdate era)
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
3, \PParamsUpdate era
up -> PParamsUpdate era
up {_maxTxSize :: HKD StrictMaybe Natural
_maxTxSize = Natural -> StrictMaybe Natural
forall a. a -> StrictMaybe a
SJust Natural
x})
          Word
4 -> Decoder s Natural
forall a s. FromCBOR a => Decoder s a
fromCBOR Decoder s Natural
-> (Natural
    -> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era))
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Natural
x -> (Int, PParamsUpdate era -> PParamsUpdate era)
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
4, \PParamsUpdate era
up -> PParamsUpdate era
up {_maxBHSize :: HKD StrictMaybe Natural
_maxBHSize = Natural -> StrictMaybe Natural
forall a. a -> StrictMaybe a
SJust Natural
x})
          Word
5 -> Decoder s Coin
forall a s. FromCBOR a => Decoder s a
fromCBOR Decoder s Coin
-> (Coin
    -> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era))
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Coin
x -> (Int, PParamsUpdate era -> PParamsUpdate era)
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
5, \PParamsUpdate era
up -> PParamsUpdate era
up {_keyDeposit :: HKD StrictMaybe Coin
_keyDeposit = Coin -> StrictMaybe Coin
forall a. a -> StrictMaybe a
SJust Coin
x})
          Word
6 -> Decoder s Coin
forall a s. FromCBOR a => Decoder s a
fromCBOR Decoder s Coin
-> (Coin
    -> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era))
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Coin
x -> (Int, PParamsUpdate era -> PParamsUpdate era)
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
6, \PParamsUpdate era
up -> PParamsUpdate era
up {_poolDeposit :: HKD StrictMaybe Coin
_poolDeposit = Coin -> StrictMaybe Coin
forall a. a -> StrictMaybe a
SJust Coin
x})
          Word
7 -> Decoder s EpochNo
forall a s. FromCBOR a => Decoder s a
fromCBOR Decoder s EpochNo
-> (EpochNo
    -> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era))
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \EpochNo
x -> (Int, PParamsUpdate era -> PParamsUpdate era)
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
7, \PParamsUpdate era
up -> PParamsUpdate era
up {_eMax :: HKD StrictMaybe EpochNo
_eMax = EpochNo -> StrictMaybe EpochNo
forall a. a -> StrictMaybe a
SJust EpochNo
x})
          Word
8 -> Decoder s Natural
forall a s. FromCBOR a => Decoder s a
fromCBOR Decoder s Natural
-> (Natural
    -> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era))
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Natural
x -> (Int, PParamsUpdate era -> PParamsUpdate era)
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
8, \PParamsUpdate era
up -> PParamsUpdate era
up {_nOpt :: HKD StrictMaybe Natural
_nOpt = Natural -> StrictMaybe Natural
forall a. a -> StrictMaybe a
SJust Natural
x})
          Word
9 -> Decoder s Rational
forall a s. (Integral a, FromCBOR a) => Decoder s (Ratio a)
ratioFromCBOR Decoder s Rational
-> (Rational
    -> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era))
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Rational
x -> (Int, PParamsUpdate era -> PParamsUpdate era)
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
9, \PParamsUpdate era
up -> PParamsUpdate era
up {_a0 :: HKD StrictMaybe Rational
_a0 = Rational -> StrictMaybe Rational
forall a. a -> StrictMaybe a
SJust Rational
x})
          Word
10 -> Decoder s UnitInterval
forall a s. FromCBOR a => Decoder s a
fromCBOR Decoder s UnitInterval
-> (UnitInterval
    -> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era))
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \UnitInterval
x -> (Int, PParamsUpdate era -> PParamsUpdate era)
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
10, \PParamsUpdate era
up -> PParamsUpdate era
up {_rho :: HKD StrictMaybe UnitInterval
_rho = UnitInterval -> StrictMaybe UnitInterval
forall a. a -> StrictMaybe a
SJust UnitInterval
x})
          Word
11 -> Decoder s UnitInterval
forall a s. FromCBOR a => Decoder s a
fromCBOR Decoder s UnitInterval
-> (UnitInterval
    -> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era))
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \UnitInterval
x -> (Int, PParamsUpdate era -> PParamsUpdate era)
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
11, \PParamsUpdate era
up -> PParamsUpdate era
up {_tau :: HKD StrictMaybe UnitInterval
_tau = UnitInterval -> StrictMaybe UnitInterval
forall a. a -> StrictMaybe a
SJust UnitInterval
x})
          Word
12 -> Decoder s UnitInterval
forall a s. FromCBOR a => Decoder s a
fromCBOR Decoder s UnitInterval
-> (UnitInterval
    -> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era))
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \UnitInterval
x -> (Int, PParamsUpdate era -> PParamsUpdate era)
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
12, \PParamsUpdate era
up -> PParamsUpdate era
up {_d :: HKD StrictMaybe UnitInterval
_d = UnitInterval -> StrictMaybe UnitInterval
forall a. a -> StrictMaybe a
SJust UnitInterval
x})
          Word
13 -> Decoder s Nonce
forall a s. FromCBOR a => Decoder s a
fromCBOR Decoder s Nonce
-> (Nonce
    -> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era))
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Nonce
x -> (Int, PParamsUpdate era -> PParamsUpdate era)
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
13, \PParamsUpdate era
up -> PParamsUpdate era
up {_extraEntropy :: HKD StrictMaybe Nonce
_extraEntropy = Nonce -> StrictMaybe Nonce
forall a. a -> StrictMaybe a
SJust Nonce
x})
          Word
14 -> Decoder s ProtVer
forall a s. FromCBOR a => Decoder s a
fromCBOR Decoder s ProtVer
-> (ProtVer
    -> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era))
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \ProtVer
x -> (Int, PParamsUpdate era -> PParamsUpdate era)
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
14, \PParamsUpdate era
up -> PParamsUpdate era
up {_protocolVersion :: HKD StrictMaybe ProtVer
_protocolVersion = ProtVer -> StrictMaybe ProtVer
forall a. a -> StrictMaybe a
SJust ProtVer
x})
          Word
15 -> Decoder s Coin
forall a s. FromCBOR a => Decoder s a
fromCBOR Decoder s Coin
-> (Coin
    -> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era))
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Coin
x -> (Int, PParamsUpdate era -> PParamsUpdate era)
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
15, \PParamsUpdate era
up -> PParamsUpdate era
up {_minUTxOValue :: HKD StrictMaybe Coin
_minUTxOValue = Coin -> StrictMaybe Coin
forall a. a -> StrictMaybe a
SJust Coin
x})
          Word
16 -> Decoder s Coin
forall a s. FromCBOR a => Decoder s a
fromCBOR Decoder s Coin
-> (Coin
    -> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era))
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Coin
x -> (Int, PParamsUpdate era -> PParamsUpdate era)
-> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
16, \PParamsUpdate era
up -> PParamsUpdate era
up {_minPoolCost :: HKD StrictMaybe Coin
_minPoolCost = Coin -> StrictMaybe Coin
forall a. a -> StrictMaybe a
SJust Coin
x})
          Word
k -> Word -> Decoder s (Int, PParamsUpdate era -> PParamsUpdate era)
forall s a. Word -> Decoder s a
invalidKey Word
k
    let fields :: [Int]
fields = (Int, PParamsUpdate era -> PParamsUpdate era) -> Int
forall a b. (a, b) -> a
fst ((Int, PParamsUpdate era -> PParamsUpdate era) -> Int)
-> [(Int, PParamsUpdate era -> PParamsUpdate era)] -> [Int]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(Int, PParamsUpdate era -> PParamsUpdate era)]
mapParts :: [Int]
    Bool -> Decoder s () -> Decoder s ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless
      ([Int] -> [Int]
forall a. Eq a => [a] -> [a]
nub [Int]
fields [Int] -> [Int] -> Bool
forall a. Eq a => a -> a -> Bool
== [Int]
fields)
      (String -> Decoder s ()
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Decoder s ()) -> String -> Decoder s ()
forall a b. (a -> b) -> a -> b
$ String
"duplicate keys: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> [Int] -> String
forall a. Show a => a -> String
show [Int]
fields)
    PParamsUpdate era -> Decoder s (PParamsUpdate era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PParamsUpdate era -> Decoder s (PParamsUpdate era))
-> PParamsUpdate era -> Decoder s (PParamsUpdate era)
forall a b. (a -> b) -> a -> b
$ ((PParamsUpdate era -> PParamsUpdate era)
 -> PParamsUpdate era -> PParamsUpdate era)
-> PParamsUpdate era
-> [PParamsUpdate era -> PParamsUpdate era]
-> PParamsUpdate era
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (PParamsUpdate era -> PParamsUpdate era)
-> PParamsUpdate era -> PParamsUpdate era
forall a b. (a -> b) -> a -> b
($) PParamsUpdate era
forall era. PParamsUpdate era
emptyPParamsUpdate ((Int, PParamsUpdate era -> PParamsUpdate era)
-> PParamsUpdate era -> PParamsUpdate era
forall a b. (a, b) -> b
snd ((Int, PParamsUpdate era -> PParamsUpdate era)
 -> PParamsUpdate era -> PParamsUpdate era)
-> [(Int, PParamsUpdate era -> PParamsUpdate era)]
-> [PParamsUpdate era -> PParamsUpdate era]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(Int, PParamsUpdate era -> PParamsUpdate era)]
mapParts)

-- | Update operation for protocol parameters structure @PParams
newtype ProposedPPUpdates era
  = ProposedPPUpdates (Map (KeyHash 'Genesis (Crypto era)) (PParamsUpdate era))
  deriving (Int -> ProposedPPUpdates era -> ShowS
[ProposedPPUpdates era] -> ShowS
ProposedPPUpdates era -> String
(Int -> ProposedPPUpdates era -> ShowS)
-> (ProposedPPUpdates era -> String)
-> ([ProposedPPUpdates era] -> ShowS)
-> Show (ProposedPPUpdates era)
forall era. Int -> ProposedPPUpdates era -> ShowS
forall era. [ProposedPPUpdates era] -> ShowS
forall era. ProposedPPUpdates era -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ProposedPPUpdates era] -> ShowS
$cshowList :: forall era. [ProposedPPUpdates era] -> ShowS
show :: ProposedPPUpdates era -> String
$cshow :: forall era. ProposedPPUpdates era -> String
showsPrec :: Int -> ProposedPPUpdates era -> ShowS
$cshowsPrec :: forall era. Int -> ProposedPPUpdates era -> ShowS
Show, ProposedPPUpdates era -> ProposedPPUpdates era -> Bool
(ProposedPPUpdates era -> ProposedPPUpdates era -> Bool)
-> (ProposedPPUpdates era -> ProposedPPUpdates era -> Bool)
-> Eq (ProposedPPUpdates era)
forall era. ProposedPPUpdates era -> ProposedPPUpdates era -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ProposedPPUpdates era -> ProposedPPUpdates era -> Bool
$c/= :: forall era. ProposedPPUpdates era -> ProposedPPUpdates era -> Bool
== :: ProposedPPUpdates era -> ProposedPPUpdates era -> Bool
$c== :: forall era. ProposedPPUpdates era -> ProposedPPUpdates era -> Bool
Eq, (forall x. ProposedPPUpdates era -> Rep (ProposedPPUpdates era) x)
-> (forall x.
    Rep (ProposedPPUpdates era) x -> ProposedPPUpdates era)
-> Generic (ProposedPPUpdates era)
forall x. Rep (ProposedPPUpdates era) x -> ProposedPPUpdates era
forall x. ProposedPPUpdates era -> Rep (ProposedPPUpdates era) x
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, ProposedPPUpdates era -> ()
(ProposedPPUpdates era -> ()) -> NFData (ProposedPPUpdates era)
forall era. ProposedPPUpdates era -> ()
forall a. (a -> ()) -> NFData a
rnf :: ProposedPPUpdates era -> ()
$crnf :: forall era. ProposedPPUpdates era -> ()
NFData)

instance NoThunks (ProposedPPUpdates era)

instance Era era => ToCBOR (ProposedPPUpdates era) where
  toCBOR :: ProposedPPUpdates era -> Encoding
toCBOR (ProposedPPUpdates Map (KeyHash 'Genesis (Crypto era)) (PParamsUpdate era)
m) = Map (KeyHash 'Genesis (Crypto era)) (PParamsUpdate era) -> Encoding
forall a b. (ToCBOR a, ToCBOR b) => Map a b -> Encoding
mapToCBOR Map (KeyHash 'Genesis (Crypto era)) (PParamsUpdate era)
m

instance Era era => FromCBOR (ProposedPPUpdates era) where
  fromCBOR :: Decoder s (ProposedPPUpdates era)
fromCBOR = Map (KeyHash 'Genesis (Crypto era)) (PParamsUpdate era)
-> ProposedPPUpdates era
forall era.
Map (KeyHash 'Genesis (Crypto era)) (PParamsUpdate era)
-> ProposedPPUpdates era
ProposedPPUpdates (Map (KeyHash 'Genesis (Crypto era)) (PParamsUpdate era)
 -> ProposedPPUpdates era)
-> Decoder
     s (Map (KeyHash 'Genesis (Crypto era)) (PParamsUpdate era))
-> Decoder s (ProposedPPUpdates era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s (Map (KeyHash 'Genesis (Crypto era)) (PParamsUpdate era))
forall a b s.
(Ord a, FromCBOR a, FromCBOR b) =>
Decoder s (Map a b)
mapFromCBOR

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

updatePParams :: PParams era -> PParamsUpdate era -> PParams era
updatePParams :: PParams era -> PParamsUpdate era -> PParams era
updatePParams PParams era
pp PParamsUpdate era
ppup =
  PParams :: forall (f :: * -> *) era.
HKD f Natural
-> HKD f Natural
-> HKD f Natural
-> HKD f Natural
-> HKD f Natural
-> HKD f Coin
-> HKD f Coin
-> HKD f EpochNo
-> HKD f Natural
-> HKD f Rational
-> HKD f UnitInterval
-> HKD f UnitInterval
-> HKD f UnitInterval
-> HKD f Nonce
-> HKD f ProtVer
-> HKD f Coin
-> HKD f Coin
-> PParams' f era
PParams
    { _minfeeA :: HKD Identity Natural
_minfeeA = Natural -> StrictMaybe Natural -> Natural
forall a. a -> StrictMaybe a -> a
fromMaybe' (PParams era -> HKD Identity Natural
forall (f :: * -> *) era. PParams' f era -> HKD f Natural
_minfeeA PParams era
pp) (PParamsUpdate era -> HKD StrictMaybe Natural
forall (f :: * -> *) era. PParams' f era -> HKD f Natural
_minfeeA PParamsUpdate era
ppup),
      _minfeeB :: HKD Identity Natural
_minfeeB = Natural -> StrictMaybe Natural -> Natural
forall a. a -> StrictMaybe a -> a
fromMaybe' (PParams era -> HKD Identity Natural
forall (f :: * -> *) era. PParams' f era -> HKD f Natural
_minfeeB PParams era
pp) (PParamsUpdate era -> HKD StrictMaybe Natural
forall (f :: * -> *) era. PParams' f era -> HKD f Natural
_minfeeB PParamsUpdate era
ppup),
      _maxBBSize :: HKD Identity Natural
_maxBBSize = Natural -> StrictMaybe Natural -> Natural
forall a. a -> StrictMaybe a -> a
fromMaybe' (PParams era -> HKD Identity Natural
forall (f :: * -> *) era. PParams' f era -> HKD f Natural
_maxBBSize PParams era
pp) (PParamsUpdate era -> HKD StrictMaybe Natural
forall (f :: * -> *) era. PParams' f era -> HKD f Natural
_maxBBSize PParamsUpdate era
ppup),
      _maxTxSize :: HKD Identity Natural
_maxTxSize = Natural -> StrictMaybe Natural -> Natural
forall a. a -> StrictMaybe a -> a
fromMaybe' (PParams era -> HKD Identity Natural
forall (f :: * -> *) era. PParams' f era -> HKD f Natural
_maxTxSize PParams era
pp) (PParamsUpdate era -> HKD StrictMaybe Natural
forall (f :: * -> *) era. PParams' f era -> HKD f Natural
_maxTxSize PParamsUpdate era
ppup),
      _maxBHSize :: HKD Identity Natural
_maxBHSize = Natural -> StrictMaybe Natural -> Natural
forall a. a -> StrictMaybe a -> a
fromMaybe' (PParams era -> HKD Identity Natural
forall (f :: * -> *) era. PParams' f era -> HKD f Natural
_maxBHSize PParams era
pp) (PParamsUpdate era -> HKD StrictMaybe Natural
forall (f :: * -> *) era. PParams' f era -> HKD f Natural
_maxBHSize PParamsUpdate era
ppup),
      _keyDeposit :: HKD Identity Coin
_keyDeposit = Coin -> StrictMaybe Coin -> Coin
forall a. a -> StrictMaybe a -> a
fromMaybe' (PParams era -> HKD Identity Coin
forall (f :: * -> *) era. PParams' f era -> HKD f Coin
_keyDeposit PParams era
pp) (PParamsUpdate era -> HKD StrictMaybe Coin
forall (f :: * -> *) era. PParams' f era -> HKD f Coin
_keyDeposit PParamsUpdate era
ppup),
      _poolDeposit :: HKD Identity Coin
_poolDeposit = Coin -> StrictMaybe Coin -> Coin
forall a. a -> StrictMaybe a -> a
fromMaybe' (PParams era -> HKD Identity Coin
forall (f :: * -> *) era. PParams' f era -> HKD f Coin
_poolDeposit PParams era
pp) (PParamsUpdate era -> HKD StrictMaybe Coin
forall (f :: * -> *) era. PParams' f era -> HKD f Coin
_poolDeposit PParamsUpdate era
ppup),
      _eMax :: HKD Identity EpochNo
_eMax = EpochNo -> StrictMaybe EpochNo -> EpochNo
forall a. a -> StrictMaybe a -> a
fromMaybe' (PParams era -> HKD Identity EpochNo
forall (f :: * -> *) era. PParams' f era -> HKD f EpochNo
_eMax PParams era
pp) (PParamsUpdate era -> HKD StrictMaybe EpochNo
forall (f :: * -> *) era. PParams' f era -> HKD f EpochNo
_eMax PParamsUpdate era
ppup),
      _nOpt :: HKD Identity Natural
_nOpt = Natural -> StrictMaybe Natural -> Natural
forall a. a -> StrictMaybe a -> a
fromMaybe' (PParams era -> HKD Identity Natural
forall (f :: * -> *) era. PParams' f era -> HKD f Natural
_nOpt PParams era
pp) (PParamsUpdate era -> HKD StrictMaybe Natural
forall (f :: * -> *) era. PParams' f era -> HKD f Natural
_nOpt PParamsUpdate era
ppup),
      _a0 :: HKD Identity Rational
_a0 = Rational -> StrictMaybe Rational -> Rational
forall a. a -> StrictMaybe a -> a
fromMaybe' (PParams era -> HKD Identity Rational
forall (f :: * -> *) era. PParams' f era -> HKD f Rational
_a0 PParams era
pp) (PParamsUpdate era -> HKD StrictMaybe Rational
forall (f :: * -> *) era. PParams' f era -> HKD f Rational
_a0 PParamsUpdate era
ppup),
      _rho :: HKD Identity UnitInterval
_rho = UnitInterval -> StrictMaybe UnitInterval -> UnitInterval
forall a. a -> StrictMaybe a -> a
fromMaybe' (PParams era -> HKD Identity UnitInterval
forall (f :: * -> *) era. PParams' f era -> HKD f UnitInterval
_rho PParams era
pp) (PParamsUpdate era -> HKD StrictMaybe UnitInterval
forall (f :: * -> *) era. PParams' f era -> HKD f UnitInterval
_rho PParamsUpdate era
ppup),
      _tau :: HKD Identity UnitInterval
_tau = UnitInterval -> StrictMaybe UnitInterval -> UnitInterval
forall a. a -> StrictMaybe a -> a
fromMaybe' (PParams era -> HKD Identity UnitInterval
forall (f :: * -> *) era. PParams' f era -> HKD f UnitInterval
_tau PParams era
pp) (PParamsUpdate era -> HKD StrictMaybe UnitInterval
forall (f :: * -> *) era. PParams' f era -> HKD f UnitInterval
_tau PParamsUpdate era
ppup),
      _d :: HKD Identity UnitInterval
_d = UnitInterval -> StrictMaybe UnitInterval -> UnitInterval
forall a. a -> StrictMaybe a -> a
fromMaybe' (PParams era -> HKD Identity UnitInterval
forall (f :: * -> *) era. PParams' f era -> HKD f UnitInterval
_d PParams era
pp) (PParamsUpdate era -> HKD StrictMaybe UnitInterval
forall (f :: * -> *) era. PParams' f era -> HKD f UnitInterval
_d PParamsUpdate era
ppup),
      _extraEntropy :: HKD Identity Nonce
_extraEntropy = Nonce -> StrictMaybe Nonce -> Nonce
forall a. a -> StrictMaybe a -> a
fromMaybe' (PParams era -> HKD Identity Nonce
forall (f :: * -> *) era. PParams' f era -> HKD f Nonce
_extraEntropy PParams era
pp) (PParamsUpdate era -> HKD StrictMaybe Nonce
forall (f :: * -> *) era. PParams' f era -> HKD f Nonce
_extraEntropy PParamsUpdate era
ppup),
      _protocolVersion :: HKD Identity ProtVer
_protocolVersion = ProtVer -> StrictMaybe ProtVer -> ProtVer
forall a. a -> StrictMaybe a -> a
fromMaybe' (PParams era -> HKD Identity ProtVer
forall (f :: * -> *) era. PParams' f era -> HKD f ProtVer
_protocolVersion PParams era
pp) (PParamsUpdate era -> HKD StrictMaybe ProtVer
forall (f :: * -> *) era. PParams' f era -> HKD f ProtVer
_protocolVersion PParamsUpdate era
ppup),
      _minUTxOValue :: HKD Identity Coin
_minUTxOValue = Coin -> StrictMaybe Coin -> Coin
forall a. a -> StrictMaybe a -> a
fromMaybe' (PParams era -> HKD Identity Coin
forall (f :: * -> *) era. PParams' f era -> HKD f Coin
_minUTxOValue PParams era
pp) (PParamsUpdate era -> HKD StrictMaybe Coin
forall (f :: * -> *) era. PParams' f era -> HKD f Coin
_minUTxOValue PParamsUpdate era
ppup),
      _minPoolCost :: HKD Identity Coin
_minPoolCost = Coin -> StrictMaybe Coin -> Coin
forall a. a -> StrictMaybe a -> a
fromMaybe' (PParams era -> HKD Identity Coin
forall (f :: * -> *) era. PParams' f era -> HKD f Coin
_minPoolCost PParams era
pp) (PParamsUpdate era -> HKD StrictMaybe Coin
forall (f :: * -> *) era. PParams' f era -> HKD f Coin
_minPoolCost PParamsUpdate era
ppup)
    }
  where
    fromMaybe' :: a -> StrictMaybe a -> a
    fromMaybe' :: a -> StrictMaybe a -> a
fromMaybe' a
x = a -> Maybe a -> a
forall a. a -> Maybe a -> a
fromMaybe a
x (Maybe a -> a) -> (StrictMaybe a -> Maybe a) -> StrictMaybe a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StrictMaybe a -> Maybe a
forall a. StrictMaybe a -> Maybe a
strictMaybeToMaybe