{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}

module Cardano.Chain.Update.ProtocolParametersUpdate (
  ProtocolParametersUpdate (..),
  isEmpty,
  apply,
)
where

import Cardano.Chain.Common (LovelacePortion, TxFeePolicy)
import Cardano.Chain.Slotting (EpochNumber, SlotNumber (..))
import Cardano.Chain.Update.ProtocolParameters (ProtocolParameters (..))
import Cardano.Chain.Update.SoftforkRule (SoftforkRule)
import Cardano.Ledger.Binary (
  DecCBOR (..),
  EncCBOR (..),
  FromCBOR (..),
  ToCBOR (..),
  encodeListLen,
  enforceSize,
  fromByronCBOR,
  toByronCBOR,
 )
import Cardano.Prelude hiding (empty)
import Data.Aeson (ToJSON)
import Data.Text.Lazy.Builder (Builder)
import Formatting (Format, bprint, build, bytes, later, shortest)
import qualified Formatting.Buildable as B

-- | Data which represents modifications of block (aka protocol) version
data ProtocolParametersUpdate = ProtocolParametersUpdate
  { ProtocolParametersUpdate -> Maybe Word16
ppuScriptVersion :: !(Maybe Word16)
  , ProtocolParametersUpdate -> Maybe Natural
ppuSlotDuration :: !(Maybe Natural)
  , ProtocolParametersUpdate -> Maybe Natural
ppuMaxBlockSize :: !(Maybe Natural)
  , ProtocolParametersUpdate -> Maybe Natural
ppuMaxHeaderSize :: !(Maybe Natural)
  , ProtocolParametersUpdate -> Maybe Natural
ppuMaxTxSize :: !(Maybe Natural)
  , ProtocolParametersUpdate -> Maybe Natural
ppuMaxProposalSize :: !(Maybe Natural)
  , ProtocolParametersUpdate -> Maybe LovelacePortion
ppuMpcThd :: !(Maybe LovelacePortion)
  , ProtocolParametersUpdate -> Maybe LovelacePortion
ppuHeavyDelThd :: !(Maybe LovelacePortion)
  , ProtocolParametersUpdate -> Maybe LovelacePortion
ppuUpdateVoteThd :: !(Maybe LovelacePortion)
  , ProtocolParametersUpdate -> Maybe LovelacePortion
ppuUpdateProposalThd :: !(Maybe LovelacePortion)
  , ProtocolParametersUpdate -> Maybe SlotNumber
ppuUpdateProposalTTL :: !(Maybe SlotNumber)
  , ProtocolParametersUpdate -> Maybe SoftforkRule
ppuSoftforkRule :: !(Maybe SoftforkRule)
  , ProtocolParametersUpdate -> Maybe TxFeePolicy
ppuTxFeePolicy :: !(Maybe TxFeePolicy)
  , ProtocolParametersUpdate -> Maybe EpochNumber
ppuUnlockStakeEpoch :: !(Maybe EpochNumber)
  }
  deriving (Int -> ProtocolParametersUpdate -> ShowS
[ProtocolParametersUpdate] -> ShowS
ProtocolParametersUpdate -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ProtocolParametersUpdate] -> ShowS
$cshowList :: [ProtocolParametersUpdate] -> ShowS
show :: ProtocolParametersUpdate -> String
$cshow :: ProtocolParametersUpdate -> String
showsPrec :: Int -> ProtocolParametersUpdate -> ShowS
$cshowsPrec :: Int -> ProtocolParametersUpdate -> ShowS
Show, ProtocolParametersUpdate -> ProtocolParametersUpdate -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ProtocolParametersUpdate -> ProtocolParametersUpdate -> Bool
$c/= :: ProtocolParametersUpdate -> ProtocolParametersUpdate -> Bool
== :: ProtocolParametersUpdate -> ProtocolParametersUpdate -> Bool
$c== :: ProtocolParametersUpdate -> ProtocolParametersUpdate -> Bool
Eq, Eq ProtocolParametersUpdate
ProtocolParametersUpdate -> ProtocolParametersUpdate -> Bool
ProtocolParametersUpdate -> ProtocolParametersUpdate -> Ordering
ProtocolParametersUpdate
-> ProtocolParametersUpdate -> ProtocolParametersUpdate
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 :: ProtocolParametersUpdate
-> ProtocolParametersUpdate -> ProtocolParametersUpdate
$cmin :: ProtocolParametersUpdate
-> ProtocolParametersUpdate -> ProtocolParametersUpdate
max :: ProtocolParametersUpdate
-> ProtocolParametersUpdate -> ProtocolParametersUpdate
$cmax :: ProtocolParametersUpdate
-> ProtocolParametersUpdate -> ProtocolParametersUpdate
>= :: ProtocolParametersUpdate -> ProtocolParametersUpdate -> Bool
$c>= :: ProtocolParametersUpdate -> ProtocolParametersUpdate -> Bool
> :: ProtocolParametersUpdate -> ProtocolParametersUpdate -> Bool
$c> :: ProtocolParametersUpdate -> ProtocolParametersUpdate -> Bool
<= :: ProtocolParametersUpdate -> ProtocolParametersUpdate -> Bool
$c<= :: ProtocolParametersUpdate -> ProtocolParametersUpdate -> Bool
< :: ProtocolParametersUpdate -> ProtocolParametersUpdate -> Bool
$c< :: ProtocolParametersUpdate -> ProtocolParametersUpdate -> Bool
compare :: ProtocolParametersUpdate -> ProtocolParametersUpdate -> Ordering
$ccompare :: ProtocolParametersUpdate -> ProtocolParametersUpdate -> Ordering
Ord, forall x.
Rep ProtocolParametersUpdate x -> ProtocolParametersUpdate
forall x.
ProtocolParametersUpdate -> Rep ProtocolParametersUpdate x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ProtocolParametersUpdate x -> ProtocolParametersUpdate
$cfrom :: forall x.
ProtocolParametersUpdate -> Rep ProtocolParametersUpdate x
Generic)
  deriving anyclass (ProtocolParametersUpdate -> ()
forall a. (a -> ()) -> NFData a
rnf :: ProtocolParametersUpdate -> ()
$crnf :: ProtocolParametersUpdate -> ()
NFData)

instance B.Buildable ProtocolParametersUpdate where
  build :: ProtocolParametersUpdate -> Builder
build ProtocolParametersUpdate
ppu =
    forall a. Format Builder a -> a
bprint
      ( Format
  (Maybe Word16
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> Builder)
  (Maybe Word16
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> Builder)
"{ script version: "
          forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a r.
Format Builder (a -> Builder) -> Format r (Maybe a -> r)
bmodifier forall a r. Buildable a => Format r (a -> r)
build
          forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Format
  (Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> Builder)
  (Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> Builder)
", slot duration: "
          forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a r.
Format Builder (a -> Builder) -> Format r (Maybe a -> r)
bmodifier forall r. Format r (Natural -> r)
bytes'
          forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Format
  (Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> Builder)
  (Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> Builder)
", block size limit: "
          forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a r.
Format Builder (a -> Builder) -> Format r (Maybe a -> r)
bmodifier forall r. Format r (Natural -> r)
bytes'
          forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Format
  (Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> Builder)
  (Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> Builder)
", header size limit: "
          forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a r.
Format Builder (a -> Builder) -> Format r (Maybe a -> r)
bmodifier forall r. Format r (Natural -> r)
bytes'
          forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Format
  (Maybe Natural
   -> Maybe Natural
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> Builder)
  (Maybe Natural
   -> Maybe Natural
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> Builder)
", tx size limit: "
          forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a r.
Format Builder (a -> Builder) -> Format r (Maybe a -> r)
bmodifier forall r. Format r (Natural -> r)
bytes'
          forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Format
  (Maybe Natural
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> Builder)
  (Maybe Natural
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> Builder)
", proposal size limit: "
          forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a r.
Format Builder (a -> Builder) -> Format r (Maybe a -> r)
bmodifier forall r. Format r (Natural -> r)
bytes'
          forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Format
  (Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> Builder)
  (Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> Builder)
", mpc threshold: "
          forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a r.
Format Builder (a -> Builder) -> Format r (Maybe a -> r)
bmodifier forall a r. Buildable a => Format r (a -> r)
build
          forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Format
  (Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> Builder)
  (Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> Builder)
", heavyweight delegation threshold: "
          forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a r.
Format Builder (a -> Builder) -> Format r (Maybe a -> r)
bmodifier forall a r. Buildable a => Format r (a -> r)
build
          forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Format
  (Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> Builder)
  (Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> Builder)
", update vote threshold: "
          forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a r.
Format Builder (a -> Builder) -> Format r (Maybe a -> r)
bmodifier forall a r. Buildable a => Format r (a -> r)
build
          forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Format
  (Maybe LovelacePortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> Builder)
  (Maybe LovelacePortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> Builder)
", update proposal threshold: "
          forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a r.
Format Builder (a -> Builder) -> Format r (Maybe a -> r)
bmodifier forall a r. Buildable a => Format r (a -> r)
build
          forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Format
  (Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> Builder)
  (Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> Builder)
", update implicit period (slots): "
          forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a r.
Format Builder (a -> Builder) -> Format r (Maybe a -> r)
bmodifier forall a r. Buildable a => Format r (a -> r)
build
          forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Format
  (Maybe SoftforkRule
   -> Maybe TxFeePolicy -> Maybe EpochNumber -> Builder)
  (Maybe SoftforkRule
   -> Maybe TxFeePolicy -> Maybe EpochNumber -> Builder)
", softfork rule: "
          forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a r.
Format Builder (a -> Builder) -> Format r (Maybe a -> r)
bmodifier forall a r. Buildable a => Format r (a -> r)
build
          forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Format
  (Maybe TxFeePolicy -> Maybe EpochNumber -> Builder)
  (Maybe TxFeePolicy -> Maybe EpochNumber -> Builder)
", tx fee policy: "
          forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a r.
Format Builder (a -> Builder) -> Format r (Maybe a -> r)
bmodifier forall a r. Buildable a => Format r (a -> r)
build
          forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Format
  (Maybe EpochNumber -> Builder) (Maybe EpochNumber -> Builder)
", unlock stake epoch: "
          forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a r.
Format Builder (a -> Builder) -> Format r (Maybe a -> r)
bmodifier forall a r. Buildable a => Format r (a -> r)
build
          forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Format Builder Builder
" }"
      )
      (ProtocolParametersUpdate -> Maybe Word16
ppuScriptVersion ProtocolParametersUpdate
ppu)
      (ProtocolParametersUpdate -> Maybe Natural
ppuSlotDuration ProtocolParametersUpdate
ppu)
      (ProtocolParametersUpdate -> Maybe Natural
ppuMaxBlockSize ProtocolParametersUpdate
ppu)
      (ProtocolParametersUpdate -> Maybe Natural
ppuMaxHeaderSize ProtocolParametersUpdate
ppu)
      (ProtocolParametersUpdate -> Maybe Natural
ppuMaxTxSize ProtocolParametersUpdate
ppu)
      (ProtocolParametersUpdate -> Maybe Natural
ppuMaxProposalSize ProtocolParametersUpdate
ppu)
      (ProtocolParametersUpdate -> Maybe LovelacePortion
ppuMpcThd ProtocolParametersUpdate
ppu)
      (ProtocolParametersUpdate -> Maybe LovelacePortion
ppuHeavyDelThd ProtocolParametersUpdate
ppu)
      (ProtocolParametersUpdate -> Maybe LovelacePortion
ppuUpdateVoteThd ProtocolParametersUpdate
ppu)
      (ProtocolParametersUpdate -> Maybe LovelacePortion
ppuUpdateProposalThd ProtocolParametersUpdate
ppu)
      (ProtocolParametersUpdate -> Maybe SlotNumber
ppuUpdateProposalTTL ProtocolParametersUpdate
ppu)
      (ProtocolParametersUpdate -> Maybe SoftforkRule
ppuSoftforkRule ProtocolParametersUpdate
ppu)
      (ProtocolParametersUpdate -> Maybe TxFeePolicy
ppuTxFeePolicy ProtocolParametersUpdate
ppu)
      (ProtocolParametersUpdate -> Maybe EpochNumber
ppuUnlockStakeEpoch ProtocolParametersUpdate
ppu)
    where
      bmodifier :: Format Builder (a -> Builder) -> Format r (Maybe a -> r)
      bmodifier :: forall a r.
Format Builder (a -> Builder) -> Format r (Maybe a -> r)
bmodifier Format Builder (a -> Builder)
b = forall a r. (a -> Builder) -> Format r (a -> r)
later forall a b. (a -> b) -> a -> b
$ forall b a. b -> (a -> b) -> Maybe a -> b
maybe Builder
"no change" (forall a. Format Builder a -> a
bprint Format Builder (a -> Builder)
b)

      bytes' :: Format r (Natural -> r)
      bytes' :: forall r. Format r (Natural -> r)
bytes' = forall f a r.
(Ord f, Integral a, Fractional f) =>
Format Builder (f -> Builder) -> Format r (a -> r)
bytes (forall a r. Real a => Format r (a -> r)
shortest @Double)

-- Used for debugging purposes only
instance ToJSON ProtocolParametersUpdate

instance ToCBOR ProtocolParametersUpdate where
  toCBOR :: ProtocolParametersUpdate -> Encoding
toCBOR = forall a. EncCBOR a => a -> Encoding
toByronCBOR

instance FromCBOR ProtocolParametersUpdate where
  fromCBOR :: forall s. Decoder s ProtocolParametersUpdate
fromCBOR = forall a s. DecCBOR a => Decoder s a
fromByronCBOR

instance EncCBOR ProtocolParametersUpdate where
  encCBOR :: ProtocolParametersUpdate -> Encoding
encCBOR ProtocolParametersUpdate
ppu =
    Word -> Encoding
encodeListLen Word
14
      forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR (ProtocolParametersUpdate -> Maybe Word16
ppuScriptVersion ProtocolParametersUpdate
ppu)
      forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR (ProtocolParametersUpdate -> Maybe Natural
ppuSlotDuration ProtocolParametersUpdate
ppu)
      forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR (ProtocolParametersUpdate -> Maybe Natural
ppuMaxBlockSize ProtocolParametersUpdate
ppu)
      forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR (ProtocolParametersUpdate -> Maybe Natural
ppuMaxHeaderSize ProtocolParametersUpdate
ppu)
      forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR (ProtocolParametersUpdate -> Maybe Natural
ppuMaxTxSize ProtocolParametersUpdate
ppu)
      forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR (ProtocolParametersUpdate -> Maybe Natural
ppuMaxProposalSize ProtocolParametersUpdate
ppu)
      forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR (ProtocolParametersUpdate -> Maybe LovelacePortion
ppuMpcThd ProtocolParametersUpdate
ppu)
      forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR (ProtocolParametersUpdate -> Maybe LovelacePortion
ppuHeavyDelThd ProtocolParametersUpdate
ppu)
      forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR (ProtocolParametersUpdate -> Maybe LovelacePortion
ppuUpdateVoteThd ProtocolParametersUpdate
ppu)
      forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR (ProtocolParametersUpdate -> Maybe LovelacePortion
ppuUpdateProposalThd ProtocolParametersUpdate
ppu)
      forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR (ProtocolParametersUpdate -> Maybe SlotNumber
ppuUpdateProposalTTL ProtocolParametersUpdate
ppu)
      forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR (ProtocolParametersUpdate -> Maybe SoftforkRule
ppuSoftforkRule ProtocolParametersUpdate
ppu)
      forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR (ProtocolParametersUpdate -> Maybe TxFeePolicy
ppuTxFeePolicy ProtocolParametersUpdate
ppu)
      forall a. Semigroup a => a -> a -> a
<> forall a. EncCBOR a => a -> Encoding
encCBOR (ProtocolParametersUpdate -> Maybe EpochNumber
ppuUnlockStakeEpoch ProtocolParametersUpdate
ppu)

instance DecCBOR ProtocolParametersUpdate where
  decCBOR :: forall s. Decoder s ProtocolParametersUpdate
decCBOR = do
    forall s. Text -> Int -> Decoder s ()
enforceSize Text
"ProtocolParametersUpdate" Int
14
    Maybe Word16
-> Maybe Natural
-> Maybe Natural
-> Maybe Natural
-> Maybe Natural
-> Maybe Natural
-> Maybe LovelacePortion
-> Maybe LovelacePortion
-> Maybe LovelacePortion
-> Maybe LovelacePortion
-> Maybe SlotNumber
-> Maybe SoftforkRule
-> Maybe TxFeePolicy
-> Maybe EpochNumber
-> ProtocolParametersUpdate
ProtocolParametersUpdate
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a s. DecCBOR a => Decoder s a
decCBOR
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a s. DecCBOR a => Decoder s a
decCBOR
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a s. DecCBOR a => Decoder s a
decCBOR
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a s. DecCBOR a => Decoder s a
decCBOR
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a s. DecCBOR a => Decoder s a
decCBOR
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a s. DecCBOR a => Decoder s a
decCBOR
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a s. DecCBOR a => Decoder s a
decCBOR
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a s. DecCBOR a => Decoder s a
decCBOR
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a s. DecCBOR a => Decoder s a
decCBOR
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a s. DecCBOR a => Decoder s a
decCBOR
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a s. DecCBOR a => Decoder s a
decCBOR
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a s. DecCBOR a => Decoder s a
decCBOR
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a s. DecCBOR a => Decoder s a
decCBOR
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a s. DecCBOR a => Decoder s a
decCBOR

empty :: ProtocolParametersUpdate
empty :: ProtocolParametersUpdate
empty =
  ProtocolParametersUpdate
    { ppuScriptVersion :: Maybe Word16
ppuScriptVersion = forall a. Maybe a
Nothing
    , ppuSlotDuration :: Maybe Natural
ppuSlotDuration = forall a. Maybe a
Nothing
    , ppuMaxBlockSize :: Maybe Natural
ppuMaxBlockSize = forall a. Maybe a
Nothing
    , ppuMaxHeaderSize :: Maybe Natural
ppuMaxHeaderSize = forall a. Maybe a
Nothing
    , ppuMaxTxSize :: Maybe Natural
ppuMaxTxSize = forall a. Maybe a
Nothing
    , ppuMaxProposalSize :: Maybe Natural
ppuMaxProposalSize = forall a. Maybe a
Nothing
    , ppuMpcThd :: Maybe LovelacePortion
ppuMpcThd = forall a. Maybe a
Nothing
    , ppuHeavyDelThd :: Maybe LovelacePortion
ppuHeavyDelThd = forall a. Maybe a
Nothing
    , ppuUpdateVoteThd :: Maybe LovelacePortion
ppuUpdateVoteThd = forall a. Maybe a
Nothing
    , ppuUpdateProposalThd :: Maybe LovelacePortion
ppuUpdateProposalThd = forall a. Maybe a
Nothing
    , ppuUpdateProposalTTL :: Maybe SlotNumber
ppuUpdateProposalTTL = forall a. Maybe a
Nothing
    , ppuSoftforkRule :: Maybe SoftforkRule
ppuSoftforkRule = forall a. Maybe a
Nothing
    , ppuTxFeePolicy :: Maybe TxFeePolicy
ppuTxFeePolicy = forall a. Maybe a
Nothing
    , ppuUnlockStakeEpoch :: Maybe EpochNumber
ppuUnlockStakeEpoch = forall a. Maybe a
Nothing
    }

isEmpty :: ProtocolParametersUpdate -> Bool
isEmpty :: ProtocolParametersUpdate -> Bool
isEmpty = (forall a. Eq a => a -> a -> Bool
== ProtocolParametersUpdate
empty)

-- | Apply 'ProtocolParametersUpdate' to 'ProtocolParameters'
apply :: ProtocolParametersUpdate -> ProtocolParameters -> ProtocolParameters
apply :: ProtocolParametersUpdate
-> ProtocolParameters -> ProtocolParameters
apply ProtocolParametersUpdate
ppu ProtocolParameters
pp =
  ProtocolParameters
    { ppScriptVersion :: Word16
ppScriptVersion = forall a. a -> Maybe a -> a
fromMaybe (ProtocolParameters -> Word16
ppScriptVersion ProtocolParameters
pp) (ProtocolParametersUpdate -> Maybe Word16
ppuScriptVersion ProtocolParametersUpdate
ppu)
    , ppSlotDuration :: Natural
ppSlotDuration = forall a. a -> Maybe a -> a
fromMaybe (ProtocolParameters -> Natural
ppSlotDuration ProtocolParameters
pp) (ProtocolParametersUpdate -> Maybe Natural
ppuSlotDuration ProtocolParametersUpdate
ppu)
    , ppMaxBlockSize :: Natural
ppMaxBlockSize = forall a. a -> Maybe a -> a
fromMaybe (ProtocolParameters -> Natural
ppMaxBlockSize ProtocolParameters
pp) (ProtocolParametersUpdate -> Maybe Natural
ppuMaxBlockSize ProtocolParametersUpdate
ppu)
    , ppMaxHeaderSize :: Natural
ppMaxHeaderSize = forall a. a -> Maybe a -> a
fromMaybe (ProtocolParameters -> Natural
ppMaxHeaderSize ProtocolParameters
pp) (ProtocolParametersUpdate -> Maybe Natural
ppuMaxHeaderSize ProtocolParametersUpdate
ppu)
    , ppMaxTxSize :: Natural
ppMaxTxSize = forall a. a -> Maybe a -> a
fromMaybe (ProtocolParameters -> Natural
ppMaxTxSize ProtocolParameters
pp) (ProtocolParametersUpdate -> Maybe Natural
ppuMaxTxSize ProtocolParametersUpdate
ppu)
    , ppMaxProposalSize :: Natural
ppMaxProposalSize =
        forall a. a -> Maybe a -> a
fromMaybe
          (ProtocolParameters -> Natural
ppMaxProposalSize ProtocolParameters
pp)
          (ProtocolParametersUpdate -> Maybe Natural
ppuMaxProposalSize ProtocolParametersUpdate
ppu)
    , ppMpcThd :: LovelacePortion
ppMpcThd = forall a. a -> Maybe a -> a
fromMaybe (ProtocolParameters -> LovelacePortion
ppMpcThd ProtocolParameters
pp) (ProtocolParametersUpdate -> Maybe LovelacePortion
ppuMpcThd ProtocolParametersUpdate
ppu)
    , ppHeavyDelThd :: LovelacePortion
ppHeavyDelThd = forall a. a -> Maybe a -> a
fromMaybe (ProtocolParameters -> LovelacePortion
ppHeavyDelThd ProtocolParameters
pp) (ProtocolParametersUpdate -> Maybe LovelacePortion
ppuHeavyDelThd ProtocolParametersUpdate
ppu)
    , ppUpdateVoteThd :: LovelacePortion
ppUpdateVoteThd = forall a. a -> Maybe a -> a
fromMaybe (ProtocolParameters -> LovelacePortion
ppUpdateVoteThd ProtocolParameters
pp) (ProtocolParametersUpdate -> Maybe LovelacePortion
ppuUpdateVoteThd ProtocolParametersUpdate
ppu)
    , ppUpdateProposalThd :: LovelacePortion
ppUpdateProposalThd =
        forall a. a -> Maybe a -> a
fromMaybe
          (ProtocolParameters -> LovelacePortion
ppUpdateProposalThd ProtocolParameters
pp)
          (ProtocolParametersUpdate -> Maybe LovelacePortion
ppuUpdateProposalThd ProtocolParametersUpdate
ppu)
    , ppUpdateProposalTTL :: SlotNumber
ppUpdateProposalTTL = forall a. a -> Maybe a -> a
fromMaybe (ProtocolParameters -> SlotNumber
ppUpdateProposalTTL ProtocolParameters
pp) (ProtocolParametersUpdate -> Maybe SlotNumber
ppuUpdateProposalTTL ProtocolParametersUpdate
ppu)
    , ppSoftforkRule :: SoftforkRule
ppSoftforkRule = forall a. a -> Maybe a -> a
fromMaybe (ProtocolParameters -> SoftforkRule
ppSoftforkRule ProtocolParameters
pp) (ProtocolParametersUpdate -> Maybe SoftforkRule
ppuSoftforkRule ProtocolParametersUpdate
ppu)
    , ppTxFeePolicy :: TxFeePolicy
ppTxFeePolicy = forall a. a -> Maybe a -> a
fromMaybe (ProtocolParameters -> TxFeePolicy
ppTxFeePolicy ProtocolParameters
pp) (ProtocolParametersUpdate -> Maybe TxFeePolicy
ppuTxFeePolicy ProtocolParametersUpdate
ppu)
    , ppUnlockStakeEpoch :: EpochNumber
ppUnlockStakeEpoch =
        forall a. a -> Maybe a -> a
fromMaybe
          (ProtocolParameters -> EpochNumber
ppUnlockStakeEpoch ProtocolParameters
pp)
          (ProtocolParametersUpdate -> Maybe EpochNumber
ppuUnlockStakeEpoch ProtocolParametersUpdate
ppu)
    }