-- Copyright 2026 Biglup Labs
-- SPDX-License-Identifier: Apache-2.0
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
--     https://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
{-# LANGUAGE OverloadedStrings #-}

-- | Sparse typed changes to protocol parameters. 'Nothing' leaves a field
-- unchanged. For nullable leverage and bootstrap round, @Just Nothing@ explicitly
-- removes the bound or round. The original imported encoding is available
-- separately from fresh serialization, which may normalize representation.
--
-- @
-- import qualified Cometa.Protocol.Parameters.Update as Update
--
-- change :: Update.Update
-- change = Update.empty { Update.updateMinFeeB = Just 155381 }
-- @
module Cometa.Protocol.Parameters.Update
  ( Update (..),
    empty,
    apply,
    fromParameters,
    EncodedUpdate,
    encodeCbor,
    decodeCbor,
    toCbor,
    toUpdate,
    toPlutusData,
  )
where

-- IMPORTS --------------------------------------------------------------------

import qualified Codec.CBOR.Decoding as Decode
import qualified Codec.CBOR.Encoding as Encode
import qualified Codec.CBOR.Read as Read
import qualified Codec.CBOR.Write as Write
import Cometa.Error (Error (..))
import Cometa.Internal.CostModels (CostModels)
import qualified Cometa.Internal.CostModels as Models
import qualified Cometa.Internal.ParameterUpdate as Native
import Cometa.Internal.ProtocolValues (DRepVotingThresholds, ExUnitPrices, ExUnits, NonNegativeRational, PoolVotingThresholds, ProtocolVersion, UnitInterval)
import qualified Cometa.Internal.ProtocolValues as Values
import qualified Cometa.PlutusData as Data
import Cometa.Protocol.Parameters (Nonce, Parameters (..), ReferenceScriptCostStride)
import qualified Cometa.Protocol.Parameters as Parameters
import Control.Applicative ((<|>))
import Control.Monad (unless)
import Data.ByteString (ByteString)
import qualified Data.ByteString.Lazy as Lazy
import Data.Maybe (fromMaybe)
import qualified Data.Set as Set
import qualified Data.Text as Text
import Data.Word (Word16, Word32, Word64)

-- TYPES ----------------------------------------------------------------------

-- | Independent optional changes. All constituent values are validated once;
-- constructing or applying a change is pure and cannot fail. Construction
-- does not validate activation or governance rules of a particular ledger era.
data Update = Update
  { -- | Linear transaction fee coefficient in lovelace per byte.
    Update -> Maybe Word64
updateMinFeeA :: !(Maybe Word64),
    -- | Constant transaction fee in lovelace.
    Update -> Maybe Word64
updateMinFeeB :: !(Maybe Word64),
    -- | Maximum block body size in bytes.
    Update -> Maybe Word64
updateMaxBlockBodySize :: !(Maybe Word64),
    -- | Maximum transaction size in bytes.
    Update -> Maybe Word64
updateMaxTxSize :: !(Maybe Word64),
    -- | Maximum block header size in bytes.
    Update -> Maybe Word64
updateMaxBlockHeaderSize :: !(Maybe Word64),
    -- | Stake credential registration deposit in lovelace.
    Update -> Maybe Word64
updateKeyDeposit :: !(Maybe Word64),
    -- | Pool registration deposit in lovelace.
    Update -> Maybe Word64
updatePoolDeposit :: !(Maybe Word64),
    -- | Maximum pool retirement interval in epochs.
    Update -> Maybe Word64
updateMaxEpoch :: !(Maybe Word64),
    -- | Desired number of stake pools.
    Update -> Maybe Word64
updateDesiredPoolCount :: !(Maybe Word64),
    -- | Nonnegative pool pledge influence factor.
    Update -> Maybe NonNegativeRational
updatePoolPledgeInfluence :: !(Maybe NonNegativeRational),
    -- | Monetary expansion fraction per epoch.
    Update -> Maybe UnitInterval
updateExpansionRate :: !(Maybe UnitInterval),
    -- | Treasury growth fraction per epoch.
    Update -> Maybe UnitInterval
updateTreasuryGrowthRate :: !(Maybe UnitInterval),
    -- | Decentralization fraction; deprecated after Alonzo.
    Update -> Maybe UnitInterval
updateDecentralization :: !(Maybe UnitInterval),
    -- | Extra entropy nonce; deprecated after Alonzo.
    Update -> Maybe Nonce
updateExtraEntropy :: !(Maybe Nonce),
    -- | Major and minor protocol version; updates deprecated after Babbage.
    Update -> Maybe ProtocolVersion
updateProtocolVersion :: !(Maybe ProtocolVersion),
    -- | Minimum pool cost in lovelace per epoch.
    Update -> Maybe Word64
updateMinPoolCost :: !(Maybe Word64),
    -- | Minimum UTxO charge in lovelace per byte.
    Update -> Maybe Word64
updateAdaPerUtxoByte :: !(Maybe Word64),
    -- | Language-indexed execution cost models.
    Update -> Maybe CostModels
updateCostModels :: !(Maybe CostModels),
    -- | Execution memory and step prices in lovelace per unit.
    Update -> Maybe ExUnitPrices
updateExecutionCosts :: !(Maybe ExUnitPrices),
    -- | Maximum execution units per transaction.
    Update -> Maybe ExUnits
updateMaxTxExUnits :: !(Maybe ExUnits),
    -- | Maximum execution units per block.
    Update -> Maybe ExUnits
updateMaxBlockExUnits :: !(Maybe ExUnits),
    -- | Maximum serialized value size in bytes.
    Update -> Maybe Word64
updateMaxValueSize :: !(Maybe Word64),
    -- | Collateral as an integer percentage of script fees.
    Update -> Maybe Word64
updateCollateralPercentage :: !(Maybe Word64),
    -- | Maximum number of collateral inputs.
    Update -> Maybe Word64
updateMaxCollateralInputs :: !(Maybe Word64),
    -- | Stake pool governance voting thresholds.
    Update -> Maybe PoolVotingThresholds
updatePoolVotingThresholds :: !(Maybe PoolVotingThresholds),
    -- | DRep governance voting thresholds.
    Update -> Maybe DRepVotingThresholds
updateDrepVotingThresholds :: !(Maybe DRepVotingThresholds),
    -- | Minimum constitutional committee membership count.
    Update -> Maybe Word64
updateMinCommitteeSize :: !(Maybe Word64),
    -- | Maximum committee term in epochs.
    Update -> Maybe Word64
updateCommitteeTermLimit :: !(Maybe Word64),
    -- | Governance action lifetime in epochs.
    Update -> Maybe Word64
updateGovernanceActionValidityPeriod :: !(Maybe Word64),
    -- | Governance action deposit in lovelace.
    Update -> Maybe Word64
updateGovernanceActionDeposit :: !(Maybe Word64),
    -- | DRep registration deposit in lovelace.
    Update -> Maybe Word64
updateDrepDeposit :: !(Maybe Word64),
    -- | DRep inactivity interval in epochs.
    Update -> Maybe Word64
updateDrepInactivityPeriod :: !(Maybe Word64),
    -- | Base reference script charge in lovelace per byte.
    Update -> Maybe NonNegativeRational
updateRefScriptCostPerByte :: !(Maybe NonNegativeRational),
    -- | Maximum reference script size per block in bytes; Dijkstra.
    Update -> Maybe Word32
updateMaxRefScriptSizePerBlock :: !(Maybe Word32),
    -- | Maximum reference script size per transaction in bytes; Dijkstra.
    Update -> Maybe Word32
updateMaxRefScriptSizePerTx :: !(Maybe Word32),
    -- | Positive reference script tier stride in bytes; Dijkstra.
    Update -> Maybe ReferenceScriptCostStride
updateRefScriptCostStride :: !(Maybe ReferenceScriptCostStride),
    -- | Reference script tier multiplier; Dijkstra.
    Update -> Maybe NonNegativeRational
updateRefScriptCostMultiplier :: !(Maybe NonNegativeRational),
    -- | Maximum pledge leverage; @Just Nothing@ selects an unbounded value.
    Update -> Maybe (Maybe NonNegativeRational)
updateMaxPledgeLeverage :: !(Maybe (Maybe NonNegativeRational)),
    -- | Minimum stake pool profit margin fraction; Dijkstra.
    Update -> Maybe UnitInterval
updateMinPoolMargin :: !(Maybe UnitInterval),
    -- | Leios announcement period in milliseconds.
    Update -> Maybe Word32
updateLeiosAnnouncementPeriodLength :: !(Maybe Word32),
    -- | Leios voting period in milliseconds.
    Update -> Maybe Word32
updateLeiosVotePeriodLength :: !(Maybe Word32),
    -- | Leios diffusion period in milliseconds.
    Update -> Maybe Word32
updateLeiosDiffusionPeriodLength :: !(Maybe Word32),
    -- | Leios committee member count.
    Update -> Maybe Word16
updateLeiosCommitteeSize :: !(Maybe Word16),
    -- | Leios quorum fraction of stake.
    Update -> Maybe UnitInterval
updateLeiosQuorumStakeThreshold :: !(Maybe UnitInterval),
    -- | Maximum endorser block references size in bytes.
    Update -> Maybe Word32
updateMaxEndorserBlockReferencesSize :: !(Maybe Word32),
    -- | Maximum endorser block transactions size in bytes.
    Update -> Maybe Word32
updateMaxEndorserBlockTxsSize :: !(Maybe Word32),
    -- | Maximum execution units per endorser block.
    Update -> Maybe ExUnits
updateMaxEndorserBlockExecutionUnits :: !(Maybe ExUnits),
    -- | Maximum reference script size per endorser block in bytes.
    Update -> Maybe Word32
updateMaxRefScriptSizePerEndorserBlock :: !(Maybe Word32),
    -- | Minimum Peras candidate block age in slots.
    Update -> Maybe Word32
updatePerasMinCandidateBlockAge :: !(Maybe Word32),
    -- | Peras healing factor.
    Update -> Maybe NonNegativeRational
updatePerasHealingFactor :: !(Maybe NonNegativeRational),
    -- | Peras certificate boost.
    Update -> Maybe Word16
updatePerasCertBoost :: !(Maybe Word16),
    -- | Target Peras committee member count.
    Update -> Maybe Word16
updatePerasTargetCommitteeSize :: !(Maybe Word16),
    -- | Manual Peras bootstrap round; @Just Nothing@ selects no round.
    Update -> Maybe (Maybe Word32)
updatePerasBootstrapRound :: !(Maybe (Maybe Word32)),
    -- | Peras quorum safety margin fraction.
    Update -> Maybe UnitInterval
updatePerasQuorumThresholdSafetyMargin :: !(Maybe UnitInterval),
    -- | Reference input charge in lovelace per multi-asset policy.
    Update -> Maybe Word64
updateRefInputsCostPerMultiAssetPolicy :: !(Maybe Word64),
    -- | Reference input charge in lovelace per datum byte.
    Update -> Maybe Word64
updateRefInputsCostPerDatumByte :: !(Maybe Word64)
  }
  deriving (Update -> Update -> Bool
(Update -> Update -> Bool)
-> (Update -> Update -> Bool) -> Eq Update
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Update -> Update -> Bool
== :: Update -> Update -> Bool
$c/= :: Update -> Update -> Bool
/= :: Update -> Update -> Bool
Eq, Int -> Update -> ShowS
[Update] -> ShowS
Update -> String
(Int -> Update -> ShowS)
-> (Update -> String) -> ([Update] -> ShowS) -> Show Update
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Update -> ShowS
showsPrec :: Int -> Update -> ShowS
$cshow :: Update -> String
show :: Update -> String
$cshowList :: [Update] -> ShowS
showList :: [Update] -> ShowS
Show)

-- | A validated update with its exact original CBOR bytes. Equality and ordering
-- compare those bytes, so alternative encodings of the same change can differ.
data EncodedUpdate = EncodedUpdate !ByteString !Update deriving (Int -> EncodedUpdate -> ShowS
[EncodedUpdate] -> ShowS
EncodedUpdate -> String
(Int -> EncodedUpdate -> ShowS)
-> (EncodedUpdate -> String)
-> ([EncodedUpdate] -> ShowS)
-> Show EncodedUpdate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> EncodedUpdate -> ShowS
showsPrec :: Int -> EncodedUpdate -> ShowS
$cshow :: EncodedUpdate -> String
show :: EncodedUpdate -> String
$cshowList :: [EncodedUpdate] -> ShowS
showList :: [EncodedUpdate] -> ShowS
Show)

instance Eq EncodedUpdate where
  EncodedUpdate ByteString
a Update
_ == :: EncodedUpdate -> EncodedUpdate -> Bool
== EncodedUpdate ByteString
b Update
_ = ByteString
a ByteString -> ByteString -> Bool
forall a. Eq a => a -> a -> Bool
== ByteString
b

instance Ord EncodedUpdate where
  compare :: EncodedUpdate -> EncodedUpdate -> Ordering
compare (EncodedUpdate ByteString
a Update
_) (EncodedUpdate ByteString
b Update
_) = ByteString -> ByteString -> Ordering
forall a. Ord a => a -> a -> Ordering
compare ByteString
a ByteString
b

-- CONSTRUCTION ---------------------------------------------------------------

-- | The empty change. Applying it preserves every parameter field.
empty :: Update
empty :: Update
empty =
  Update
    { updateMinFeeA :: Maybe Word64
updateMinFeeA = Maybe Word64
forall a. Maybe a
Nothing,
      updateMinFeeB :: Maybe Word64
updateMinFeeB = Maybe Word64
forall a. Maybe a
Nothing,
      updateMaxBlockBodySize :: Maybe Word64
updateMaxBlockBodySize = Maybe Word64
forall a. Maybe a
Nothing,
      updateMaxTxSize :: Maybe Word64
updateMaxTxSize = Maybe Word64
forall a. Maybe a
Nothing,
      updateMaxBlockHeaderSize :: Maybe Word64
updateMaxBlockHeaderSize = Maybe Word64
forall a. Maybe a
Nothing,
      updateKeyDeposit :: Maybe Word64
updateKeyDeposit = Maybe Word64
forall a. Maybe a
Nothing,
      updatePoolDeposit :: Maybe Word64
updatePoolDeposit = Maybe Word64
forall a. Maybe a
Nothing,
      updateMaxEpoch :: Maybe Word64
updateMaxEpoch = Maybe Word64
forall a. Maybe a
Nothing,
      updateDesiredPoolCount :: Maybe Word64
updateDesiredPoolCount = Maybe Word64
forall a. Maybe a
Nothing,
      updatePoolPledgeInfluence :: Maybe NonNegativeRational
updatePoolPledgeInfluence = Maybe NonNegativeRational
forall a. Maybe a
Nothing,
      updateExpansionRate :: Maybe UnitInterval
updateExpansionRate = Maybe UnitInterval
forall a. Maybe a
Nothing,
      updateTreasuryGrowthRate :: Maybe UnitInterval
updateTreasuryGrowthRate = Maybe UnitInterval
forall a. Maybe a
Nothing,
      updateDecentralization :: Maybe UnitInterval
updateDecentralization = Maybe UnitInterval
forall a. Maybe a
Nothing,
      updateExtraEntropy :: Maybe Nonce
updateExtraEntropy = Maybe Nonce
forall a. Maybe a
Nothing,
      updateProtocolVersion :: Maybe ProtocolVersion
updateProtocolVersion = Maybe ProtocolVersion
forall a. Maybe a
Nothing,
      updateMinPoolCost :: Maybe Word64
updateMinPoolCost = Maybe Word64
forall a. Maybe a
Nothing,
      updateAdaPerUtxoByte :: Maybe Word64
updateAdaPerUtxoByte = Maybe Word64
forall a. Maybe a
Nothing,
      updateCostModels :: Maybe CostModels
updateCostModels = Maybe CostModels
forall a. Maybe a
Nothing,
      updateExecutionCosts :: Maybe ExUnitPrices
updateExecutionCosts = Maybe ExUnitPrices
forall a. Maybe a
Nothing,
      updateMaxTxExUnits :: Maybe ExUnits
updateMaxTxExUnits = Maybe ExUnits
forall a. Maybe a
Nothing,
      updateMaxBlockExUnits :: Maybe ExUnits
updateMaxBlockExUnits = Maybe ExUnits
forall a. Maybe a
Nothing,
      updateMaxValueSize :: Maybe Word64
updateMaxValueSize = Maybe Word64
forall a. Maybe a
Nothing,
      updateCollateralPercentage :: Maybe Word64
updateCollateralPercentage = Maybe Word64
forall a. Maybe a
Nothing,
      updateMaxCollateralInputs :: Maybe Word64
updateMaxCollateralInputs = Maybe Word64
forall a. Maybe a
Nothing,
      updatePoolVotingThresholds :: Maybe PoolVotingThresholds
updatePoolVotingThresholds = Maybe PoolVotingThresholds
forall a. Maybe a
Nothing,
      updateDrepVotingThresholds :: Maybe DRepVotingThresholds
updateDrepVotingThresholds = Maybe DRepVotingThresholds
forall a. Maybe a
Nothing,
      updateMinCommitteeSize :: Maybe Word64
updateMinCommitteeSize = Maybe Word64
forall a. Maybe a
Nothing,
      updateCommitteeTermLimit :: Maybe Word64
updateCommitteeTermLimit = Maybe Word64
forall a. Maybe a
Nothing,
      updateGovernanceActionValidityPeriod :: Maybe Word64
updateGovernanceActionValidityPeriod = Maybe Word64
forall a. Maybe a
Nothing,
      updateGovernanceActionDeposit :: Maybe Word64
updateGovernanceActionDeposit = Maybe Word64
forall a. Maybe a
Nothing,
      updateDrepDeposit :: Maybe Word64
updateDrepDeposit = Maybe Word64
forall a. Maybe a
Nothing,
      updateDrepInactivityPeriod :: Maybe Word64
updateDrepInactivityPeriod = Maybe Word64
forall a. Maybe a
Nothing,
      updateRefScriptCostPerByte :: Maybe NonNegativeRational
updateRefScriptCostPerByte = Maybe NonNegativeRational
forall a. Maybe a
Nothing,
      updateMaxRefScriptSizePerBlock :: Maybe Word32
updateMaxRefScriptSizePerBlock = Maybe Word32
forall a. Maybe a
Nothing,
      updateMaxRefScriptSizePerTx :: Maybe Word32
updateMaxRefScriptSizePerTx = Maybe Word32
forall a. Maybe a
Nothing,
      updateRefScriptCostStride :: Maybe ReferenceScriptCostStride
updateRefScriptCostStride = Maybe ReferenceScriptCostStride
forall a. Maybe a
Nothing,
      updateRefScriptCostMultiplier :: Maybe NonNegativeRational
updateRefScriptCostMultiplier = Maybe NonNegativeRational
forall a. Maybe a
Nothing,
      updateMaxPledgeLeverage :: Maybe (Maybe NonNegativeRational)
updateMaxPledgeLeverage = Maybe (Maybe NonNegativeRational)
forall a. Maybe a
Nothing,
      updateMinPoolMargin :: Maybe UnitInterval
updateMinPoolMargin = Maybe UnitInterval
forall a. Maybe a
Nothing,
      updateLeiosAnnouncementPeriodLength :: Maybe Word32
updateLeiosAnnouncementPeriodLength = Maybe Word32
forall a. Maybe a
Nothing,
      updateLeiosVotePeriodLength :: Maybe Word32
updateLeiosVotePeriodLength = Maybe Word32
forall a. Maybe a
Nothing,
      updateLeiosDiffusionPeriodLength :: Maybe Word32
updateLeiosDiffusionPeriodLength = Maybe Word32
forall a. Maybe a
Nothing,
      updateLeiosCommitteeSize :: Maybe Word16
updateLeiosCommitteeSize = Maybe Word16
forall a. Maybe a
Nothing,
      updateLeiosQuorumStakeThreshold :: Maybe UnitInterval
updateLeiosQuorumStakeThreshold = Maybe UnitInterval
forall a. Maybe a
Nothing,
      updateMaxEndorserBlockReferencesSize :: Maybe Word32
updateMaxEndorserBlockReferencesSize = Maybe Word32
forall a. Maybe a
Nothing,
      updateMaxEndorserBlockTxsSize :: Maybe Word32
updateMaxEndorserBlockTxsSize = Maybe Word32
forall a. Maybe a
Nothing,
      updateMaxEndorserBlockExecutionUnits :: Maybe ExUnits
updateMaxEndorserBlockExecutionUnits = Maybe ExUnits
forall a. Maybe a
Nothing,
      updateMaxRefScriptSizePerEndorserBlock :: Maybe Word32
updateMaxRefScriptSizePerEndorserBlock = Maybe Word32
forall a. Maybe a
Nothing,
      updatePerasMinCandidateBlockAge :: Maybe Word32
updatePerasMinCandidateBlockAge = Maybe Word32
forall a. Maybe a
Nothing,
      updatePerasHealingFactor :: Maybe NonNegativeRational
updatePerasHealingFactor = Maybe NonNegativeRational
forall a. Maybe a
Nothing,
      updatePerasCertBoost :: Maybe Word16
updatePerasCertBoost = Maybe Word16
forall a. Maybe a
Nothing,
      updatePerasTargetCommitteeSize :: Maybe Word16
updatePerasTargetCommitteeSize = Maybe Word16
forall a. Maybe a
Nothing,
      updatePerasBootstrapRound :: Maybe (Maybe Word32)
updatePerasBootstrapRound = Maybe (Maybe Word32)
forall a. Maybe a
Nothing,
      updatePerasQuorumThresholdSafetyMargin :: Maybe UnitInterval
updatePerasQuorumThresholdSafetyMargin = Maybe UnitInterval
forall a. Maybe a
Nothing,
      updateRefInputsCostPerMultiAssetPolicy :: Maybe Word64
updateRefInputsCostPerMultiAssetPolicy = Maybe Word64
forall a. Maybe a
Nothing,
      updateRefInputsCostPerDatumByte :: Maybe Word64
updateRefInputsCostPerDatumByte = Maybe Word64
forall a. Maybe a
Nothing
    }

-- | Apply all present fields to a complete snapshot, preserving absent fields.
apply :: Update -> Parameters -> Parameters
apply :: Update -> Parameters -> Parameters
apply Update
change Parameters
current =
  Parameters
    { parameterMinFeeA :: Word64
parameterMinFeeA = Word64 -> Maybe Word64 -> Word64
forall a. a -> Maybe a -> a
fromMaybe (Parameters -> Word64
parameterMinFeeA Parameters
current) (Update -> Maybe Word64
updateMinFeeA Update
change),
      parameterMinFeeB :: Word64
parameterMinFeeB = Word64 -> Maybe Word64 -> Word64
forall a. a -> Maybe a -> a
fromMaybe (Parameters -> Word64
parameterMinFeeB Parameters
current) (Update -> Maybe Word64
updateMinFeeB Update
change),
      parameterMaxBlockBodySize :: Word64
parameterMaxBlockBodySize = Word64 -> Maybe Word64 -> Word64
forall a. a -> Maybe a -> a
fromMaybe (Parameters -> Word64
parameterMaxBlockBodySize Parameters
current) (Update -> Maybe Word64
updateMaxBlockBodySize Update
change),
      parameterMaxTxSize :: Word64
parameterMaxTxSize = Word64 -> Maybe Word64 -> Word64
forall a. a -> Maybe a -> a
fromMaybe (Parameters -> Word64
parameterMaxTxSize Parameters
current) (Update -> Maybe Word64
updateMaxTxSize Update
change),
      parameterMaxBlockHeaderSize :: Word64
parameterMaxBlockHeaderSize = Word64 -> Maybe Word64 -> Word64
forall a. a -> Maybe a -> a
fromMaybe (Parameters -> Word64
parameterMaxBlockHeaderSize Parameters
current) (Update -> Maybe Word64
updateMaxBlockHeaderSize Update
change),
      parameterKeyDeposit :: Word64
parameterKeyDeposit = Word64 -> Maybe Word64 -> Word64
forall a. a -> Maybe a -> a
fromMaybe (Parameters -> Word64
parameterKeyDeposit Parameters
current) (Update -> Maybe Word64
updateKeyDeposit Update
change),
      parameterPoolDeposit :: Word64
parameterPoolDeposit = Word64 -> Maybe Word64 -> Word64
forall a. a -> Maybe a -> a
fromMaybe (Parameters -> Word64
parameterPoolDeposit Parameters
current) (Update -> Maybe Word64
updatePoolDeposit Update
change),
      parameterMaxEpoch :: Word64
parameterMaxEpoch = Word64 -> Maybe Word64 -> Word64
forall a. a -> Maybe a -> a
fromMaybe (Parameters -> Word64
parameterMaxEpoch Parameters
current) (Update -> Maybe Word64
updateMaxEpoch Update
change),
      parameterDesiredPoolCount :: Word64
parameterDesiredPoolCount = Word64 -> Maybe Word64 -> Word64
forall a. a -> Maybe a -> a
fromMaybe (Parameters -> Word64
parameterDesiredPoolCount Parameters
current) (Update -> Maybe Word64
updateDesiredPoolCount Update
change),
      parameterPoolPledgeInfluence :: NonNegativeRational
parameterPoolPledgeInfluence = NonNegativeRational
-> Maybe NonNegativeRational -> NonNegativeRational
forall a. a -> Maybe a -> a
fromMaybe (Parameters -> NonNegativeRational
parameterPoolPledgeInfluence Parameters
current) (Update -> Maybe NonNegativeRational
updatePoolPledgeInfluence Update
change),
      parameterExpansionRate :: UnitInterval
parameterExpansionRate = UnitInterval -> Maybe UnitInterval -> UnitInterval
forall a. a -> Maybe a -> a
fromMaybe (Parameters -> UnitInterval
parameterExpansionRate Parameters
current) (Update -> Maybe UnitInterval
updateExpansionRate Update
change),
      parameterTreasuryGrowthRate :: UnitInterval
parameterTreasuryGrowthRate = UnitInterval -> Maybe UnitInterval -> UnitInterval
forall a. a -> Maybe a -> a
fromMaybe (Parameters -> UnitInterval
parameterTreasuryGrowthRate Parameters
current) (Update -> Maybe UnitInterval
updateTreasuryGrowthRate Update
change),
      parameterDecentralization :: Maybe UnitInterval
parameterDecentralization = Update -> Maybe UnitInterval
updateDecentralization Update
change Maybe UnitInterval -> Maybe UnitInterval -> Maybe UnitInterval
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe UnitInterval
parameterDecentralization Parameters
current,
      parameterExtraEntropy :: Maybe Nonce
parameterExtraEntropy = Update -> Maybe Nonce
updateExtraEntropy Update
change Maybe Nonce -> Maybe Nonce -> Maybe Nonce
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe Nonce
parameterExtraEntropy Parameters
current,
      parameterProtocolVersion :: ProtocolVersion
parameterProtocolVersion = ProtocolVersion -> Maybe ProtocolVersion -> ProtocolVersion
forall a. a -> Maybe a -> a
fromMaybe (Parameters -> ProtocolVersion
parameterProtocolVersion Parameters
current) (Update -> Maybe ProtocolVersion
updateProtocolVersion Update
change),
      parameterMinPoolCost :: Word64
parameterMinPoolCost = Word64 -> Maybe Word64 -> Word64
forall a. a -> Maybe a -> a
fromMaybe (Parameters -> Word64
parameterMinPoolCost Parameters
current) (Update -> Maybe Word64
updateMinPoolCost Update
change),
      parameterAdaPerUtxoByte :: Maybe Word64
parameterAdaPerUtxoByte = Update -> Maybe Word64
updateAdaPerUtxoByte Update
change Maybe Word64 -> Maybe Word64 -> Maybe Word64
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe Word64
parameterAdaPerUtxoByte Parameters
current,
      parameterCostModels :: Maybe CostModels
parameterCostModels = Update -> Maybe CostModels
updateCostModels Update
change Maybe CostModels -> Maybe CostModels -> Maybe CostModels
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe CostModels
parameterCostModels Parameters
current,
      parameterExecutionCosts :: Maybe ExUnitPrices
parameterExecutionCosts = Update -> Maybe ExUnitPrices
updateExecutionCosts Update
change Maybe ExUnitPrices -> Maybe ExUnitPrices -> Maybe ExUnitPrices
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe ExUnitPrices
parameterExecutionCosts Parameters
current,
      parameterMaxTxExUnits :: Maybe ExUnits
parameterMaxTxExUnits = Update -> Maybe ExUnits
updateMaxTxExUnits Update
change Maybe ExUnits -> Maybe ExUnits -> Maybe ExUnits
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe ExUnits
parameterMaxTxExUnits Parameters
current,
      parameterMaxBlockExUnits :: Maybe ExUnits
parameterMaxBlockExUnits = Update -> Maybe ExUnits
updateMaxBlockExUnits Update
change Maybe ExUnits -> Maybe ExUnits -> Maybe ExUnits
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe ExUnits
parameterMaxBlockExUnits Parameters
current,
      parameterMaxValueSize :: Maybe Word64
parameterMaxValueSize = Update -> Maybe Word64
updateMaxValueSize Update
change Maybe Word64 -> Maybe Word64 -> Maybe Word64
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe Word64
parameterMaxValueSize Parameters
current,
      parameterCollateralPercentage :: Maybe Word64
parameterCollateralPercentage = Update -> Maybe Word64
updateCollateralPercentage Update
change Maybe Word64 -> Maybe Word64 -> Maybe Word64
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe Word64
parameterCollateralPercentage Parameters
current,
      parameterMaxCollateralInputs :: Maybe Word64
parameterMaxCollateralInputs = Update -> Maybe Word64
updateMaxCollateralInputs Update
change Maybe Word64 -> Maybe Word64 -> Maybe Word64
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe Word64
parameterMaxCollateralInputs Parameters
current,
      parameterPoolVotingThresholds :: Maybe PoolVotingThresholds
parameterPoolVotingThresholds = Update -> Maybe PoolVotingThresholds
updatePoolVotingThresholds Update
change Maybe PoolVotingThresholds
-> Maybe PoolVotingThresholds -> Maybe PoolVotingThresholds
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe PoolVotingThresholds
parameterPoolVotingThresholds Parameters
current,
      parameterDrepVotingThresholds :: Maybe DRepVotingThresholds
parameterDrepVotingThresholds = Update -> Maybe DRepVotingThresholds
updateDrepVotingThresholds Update
change Maybe DRepVotingThresholds
-> Maybe DRepVotingThresholds -> Maybe DRepVotingThresholds
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe DRepVotingThresholds
parameterDrepVotingThresholds Parameters
current,
      parameterMinCommitteeSize :: Maybe Word64
parameterMinCommitteeSize = Update -> Maybe Word64
updateMinCommitteeSize Update
change Maybe Word64 -> Maybe Word64 -> Maybe Word64
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe Word64
parameterMinCommitteeSize Parameters
current,
      parameterCommitteeTermLimit :: Maybe Word64
parameterCommitteeTermLimit = Update -> Maybe Word64
updateCommitteeTermLimit Update
change Maybe Word64 -> Maybe Word64 -> Maybe Word64
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe Word64
parameterCommitteeTermLimit Parameters
current,
      parameterGovernanceActionValidityPeriod :: Maybe Word64
parameterGovernanceActionValidityPeriod = Update -> Maybe Word64
updateGovernanceActionValidityPeriod Update
change Maybe Word64 -> Maybe Word64 -> Maybe Word64
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe Word64
parameterGovernanceActionValidityPeriod Parameters
current,
      parameterGovernanceActionDeposit :: Maybe Word64
parameterGovernanceActionDeposit = Update -> Maybe Word64
updateGovernanceActionDeposit Update
change Maybe Word64 -> Maybe Word64 -> Maybe Word64
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe Word64
parameterGovernanceActionDeposit Parameters
current,
      parameterDrepDeposit :: Maybe Word64
parameterDrepDeposit = Update -> Maybe Word64
updateDrepDeposit Update
change Maybe Word64 -> Maybe Word64 -> Maybe Word64
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe Word64
parameterDrepDeposit Parameters
current,
      parameterDrepInactivityPeriod :: Maybe Word64
parameterDrepInactivityPeriod = Update -> Maybe Word64
updateDrepInactivityPeriod Update
change Maybe Word64 -> Maybe Word64 -> Maybe Word64
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe Word64
parameterDrepInactivityPeriod Parameters
current,
      parameterRefScriptCostPerByte :: Maybe NonNegativeRational
parameterRefScriptCostPerByte = Update -> Maybe NonNegativeRational
updateRefScriptCostPerByte Update
change Maybe NonNegativeRational
-> Maybe NonNegativeRational -> Maybe NonNegativeRational
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe NonNegativeRational
parameterRefScriptCostPerByte Parameters
current,
      parameterMaxRefScriptSizePerBlock :: Maybe Word32
parameterMaxRefScriptSizePerBlock = Update -> Maybe Word32
updateMaxRefScriptSizePerBlock Update
change Maybe Word32 -> Maybe Word32 -> Maybe Word32
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe Word32
parameterMaxRefScriptSizePerBlock Parameters
current,
      parameterMaxRefScriptSizePerTx :: Maybe Word32
parameterMaxRefScriptSizePerTx = Update -> Maybe Word32
updateMaxRefScriptSizePerTx Update
change Maybe Word32 -> Maybe Word32 -> Maybe Word32
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe Word32
parameterMaxRefScriptSizePerTx Parameters
current,
      parameterRefScriptCostStride :: Maybe ReferenceScriptCostStride
parameterRefScriptCostStride = Update -> Maybe ReferenceScriptCostStride
updateRefScriptCostStride Update
change Maybe ReferenceScriptCostStride
-> Maybe ReferenceScriptCostStride
-> Maybe ReferenceScriptCostStride
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe ReferenceScriptCostStride
parameterRefScriptCostStride Parameters
current,
      parameterRefScriptCostMultiplier :: Maybe NonNegativeRational
parameterRefScriptCostMultiplier = Update -> Maybe NonNegativeRational
updateRefScriptCostMultiplier Update
change Maybe NonNegativeRational
-> Maybe NonNegativeRational -> Maybe NonNegativeRational
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe NonNegativeRational
parameterRefScriptCostMultiplier Parameters
current,
      parameterMaxPledgeLeverage :: Maybe (Maybe NonNegativeRational)
parameterMaxPledgeLeverage = Update -> Maybe (Maybe NonNegativeRational)
updateMaxPledgeLeverage Update
change Maybe (Maybe NonNegativeRational)
-> Maybe (Maybe NonNegativeRational)
-> Maybe (Maybe NonNegativeRational)
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe (Maybe NonNegativeRational)
parameterMaxPledgeLeverage Parameters
current,
      parameterMinPoolMargin :: Maybe UnitInterval
parameterMinPoolMargin = Update -> Maybe UnitInterval
updateMinPoolMargin Update
change Maybe UnitInterval -> Maybe UnitInterval -> Maybe UnitInterval
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe UnitInterval
parameterMinPoolMargin Parameters
current,
      parameterLeiosAnnouncementPeriodLength :: Maybe Word32
parameterLeiosAnnouncementPeriodLength = Update -> Maybe Word32
updateLeiosAnnouncementPeriodLength Update
change Maybe Word32 -> Maybe Word32 -> Maybe Word32
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe Word32
parameterLeiosAnnouncementPeriodLength Parameters
current,
      parameterLeiosVotePeriodLength :: Maybe Word32
parameterLeiosVotePeriodLength = Update -> Maybe Word32
updateLeiosVotePeriodLength Update
change Maybe Word32 -> Maybe Word32 -> Maybe Word32
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe Word32
parameterLeiosVotePeriodLength Parameters
current,
      parameterLeiosDiffusionPeriodLength :: Maybe Word32
parameterLeiosDiffusionPeriodLength = Update -> Maybe Word32
updateLeiosDiffusionPeriodLength Update
change Maybe Word32 -> Maybe Word32 -> Maybe Word32
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe Word32
parameterLeiosDiffusionPeriodLength Parameters
current,
      parameterLeiosCommitteeSize :: Maybe Word16
parameterLeiosCommitteeSize = Update -> Maybe Word16
updateLeiosCommitteeSize Update
change Maybe Word16 -> Maybe Word16 -> Maybe Word16
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe Word16
parameterLeiosCommitteeSize Parameters
current,
      parameterLeiosQuorumStakeThreshold :: Maybe UnitInterval
parameterLeiosQuorumStakeThreshold = Update -> Maybe UnitInterval
updateLeiosQuorumStakeThreshold Update
change Maybe UnitInterval -> Maybe UnitInterval -> Maybe UnitInterval
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe UnitInterval
parameterLeiosQuorumStakeThreshold Parameters
current,
      parameterMaxEndorserBlockReferencesSize :: Maybe Word32
parameterMaxEndorserBlockReferencesSize = Update -> Maybe Word32
updateMaxEndorserBlockReferencesSize Update
change Maybe Word32 -> Maybe Word32 -> Maybe Word32
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe Word32
parameterMaxEndorserBlockReferencesSize Parameters
current,
      parameterMaxEndorserBlockTxsSize :: Maybe Word32
parameterMaxEndorserBlockTxsSize = Update -> Maybe Word32
updateMaxEndorserBlockTxsSize Update
change Maybe Word32 -> Maybe Word32 -> Maybe Word32
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe Word32
parameterMaxEndorserBlockTxsSize Parameters
current,
      parameterMaxEndorserBlockExecutionUnits :: Maybe ExUnits
parameterMaxEndorserBlockExecutionUnits = Update -> Maybe ExUnits
updateMaxEndorserBlockExecutionUnits Update
change Maybe ExUnits -> Maybe ExUnits -> Maybe ExUnits
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe ExUnits
parameterMaxEndorserBlockExecutionUnits Parameters
current,
      parameterMaxRefScriptSizePerEndorserBlock :: Maybe Word32
parameterMaxRefScriptSizePerEndorserBlock = Update -> Maybe Word32
updateMaxRefScriptSizePerEndorserBlock Update
change Maybe Word32 -> Maybe Word32 -> Maybe Word32
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe Word32
parameterMaxRefScriptSizePerEndorserBlock Parameters
current,
      parameterPerasMinCandidateBlockAge :: Maybe Word32
parameterPerasMinCandidateBlockAge = Update -> Maybe Word32
updatePerasMinCandidateBlockAge Update
change Maybe Word32 -> Maybe Word32 -> Maybe Word32
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe Word32
parameterPerasMinCandidateBlockAge Parameters
current,
      parameterPerasHealingFactor :: Maybe NonNegativeRational
parameterPerasHealingFactor = Update -> Maybe NonNegativeRational
updatePerasHealingFactor Update
change Maybe NonNegativeRational
-> Maybe NonNegativeRational -> Maybe NonNegativeRational
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe NonNegativeRational
parameterPerasHealingFactor Parameters
current,
      parameterPerasCertBoost :: Maybe Word16
parameterPerasCertBoost = Update -> Maybe Word16
updatePerasCertBoost Update
change Maybe Word16 -> Maybe Word16 -> Maybe Word16
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe Word16
parameterPerasCertBoost Parameters
current,
      parameterPerasTargetCommitteeSize :: Maybe Word16
parameterPerasTargetCommitteeSize = Update -> Maybe Word16
updatePerasTargetCommitteeSize Update
change Maybe Word16 -> Maybe Word16 -> Maybe Word16
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe Word16
parameterPerasTargetCommitteeSize Parameters
current,
      parameterPerasBootstrapRound :: Maybe (Maybe Word32)
parameterPerasBootstrapRound = Update -> Maybe (Maybe Word32)
updatePerasBootstrapRound Update
change Maybe (Maybe Word32)
-> Maybe (Maybe Word32) -> Maybe (Maybe Word32)
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe (Maybe Word32)
parameterPerasBootstrapRound Parameters
current,
      parameterPerasQuorumThresholdSafetyMargin :: Maybe UnitInterval
parameterPerasQuorumThresholdSafetyMargin = Update -> Maybe UnitInterval
updatePerasQuorumThresholdSafetyMargin Update
change Maybe UnitInterval -> Maybe UnitInterval -> Maybe UnitInterval
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe UnitInterval
parameterPerasQuorumThresholdSafetyMargin Parameters
current,
      parameterRefInputsCostPerMultiAssetPolicy :: Maybe Word64
parameterRefInputsCostPerMultiAssetPolicy = Update -> Maybe Word64
updateRefInputsCostPerMultiAssetPolicy Update
change Maybe Word64 -> Maybe Word64 -> Maybe Word64
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe Word64
parameterRefInputsCostPerMultiAssetPolicy Parameters
current,
      parameterRefInputsCostPerDatumByte :: Maybe Word64
parameterRefInputsCostPerDatumByte = Update -> Maybe Word64
updateRefInputsCostPerDatumByte Update
change Maybe Word64 -> Maybe Word64 -> Maybe Word64
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parameters -> Maybe Word64
parameterRefInputsCostPerDatumByte Parameters
current
    }

-- | Produce a change setting each available field, including explicit nulls.
-- Unavailable fields are omitted.
fromParameters :: Parameters -> Update
fromParameters :: Parameters -> Update
fromParameters Parameters
current =
  Update
    { updateMinFeeA :: Maybe Word64
updateMinFeeA = Word64 -> Maybe Word64
forall a. a -> Maybe a
Just (Parameters -> Word64
parameterMinFeeA Parameters
current),
      updateMinFeeB :: Maybe Word64
updateMinFeeB = Word64 -> Maybe Word64
forall a. a -> Maybe a
Just (Parameters -> Word64
parameterMinFeeB Parameters
current),
      updateMaxBlockBodySize :: Maybe Word64
updateMaxBlockBodySize = Word64 -> Maybe Word64
forall a. a -> Maybe a
Just (Parameters -> Word64
parameterMaxBlockBodySize Parameters
current),
      updateMaxTxSize :: Maybe Word64
updateMaxTxSize = Word64 -> Maybe Word64
forall a. a -> Maybe a
Just (Parameters -> Word64
parameterMaxTxSize Parameters
current),
      updateMaxBlockHeaderSize :: Maybe Word64
updateMaxBlockHeaderSize = Word64 -> Maybe Word64
forall a. a -> Maybe a
Just (Parameters -> Word64
parameterMaxBlockHeaderSize Parameters
current),
      updateKeyDeposit :: Maybe Word64
updateKeyDeposit = Word64 -> Maybe Word64
forall a. a -> Maybe a
Just (Parameters -> Word64
parameterKeyDeposit Parameters
current),
      updatePoolDeposit :: Maybe Word64
updatePoolDeposit = Word64 -> Maybe Word64
forall a. a -> Maybe a
Just (Parameters -> Word64
parameterPoolDeposit Parameters
current),
      updateMaxEpoch :: Maybe Word64
updateMaxEpoch = Word64 -> Maybe Word64
forall a. a -> Maybe a
Just (Parameters -> Word64
parameterMaxEpoch Parameters
current),
      updateDesiredPoolCount :: Maybe Word64
updateDesiredPoolCount = Word64 -> Maybe Word64
forall a. a -> Maybe a
Just (Parameters -> Word64
parameterDesiredPoolCount Parameters
current),
      updatePoolPledgeInfluence :: Maybe NonNegativeRational
updatePoolPledgeInfluence = NonNegativeRational -> Maybe NonNegativeRational
forall a. a -> Maybe a
Just (Parameters -> NonNegativeRational
parameterPoolPledgeInfluence Parameters
current),
      updateExpansionRate :: Maybe UnitInterval
updateExpansionRate = UnitInterval -> Maybe UnitInterval
forall a. a -> Maybe a
Just (Parameters -> UnitInterval
parameterExpansionRate Parameters
current),
      updateTreasuryGrowthRate :: Maybe UnitInterval
updateTreasuryGrowthRate = UnitInterval -> Maybe UnitInterval
forall a. a -> Maybe a
Just (Parameters -> UnitInterval
parameterTreasuryGrowthRate Parameters
current),
      updateDecentralization :: Maybe UnitInterval
updateDecentralization = Parameters -> Maybe UnitInterval
parameterDecentralization Parameters
current,
      updateExtraEntropy :: Maybe Nonce
updateExtraEntropy = Parameters -> Maybe Nonce
parameterExtraEntropy Parameters
current,
      updateProtocolVersion :: Maybe ProtocolVersion
updateProtocolVersion = ProtocolVersion -> Maybe ProtocolVersion
forall a. a -> Maybe a
Just (Parameters -> ProtocolVersion
parameterProtocolVersion Parameters
current),
      updateMinPoolCost :: Maybe Word64
updateMinPoolCost = Word64 -> Maybe Word64
forall a. a -> Maybe a
Just (Parameters -> Word64
parameterMinPoolCost Parameters
current),
      updateAdaPerUtxoByte :: Maybe Word64
updateAdaPerUtxoByte = Parameters -> Maybe Word64
parameterAdaPerUtxoByte Parameters
current,
      updateCostModels :: Maybe CostModels
updateCostModels = Parameters -> Maybe CostModels
parameterCostModels Parameters
current,
      updateExecutionCosts :: Maybe ExUnitPrices
updateExecutionCosts = Parameters -> Maybe ExUnitPrices
parameterExecutionCosts Parameters
current,
      updateMaxTxExUnits :: Maybe ExUnits
updateMaxTxExUnits = Parameters -> Maybe ExUnits
parameterMaxTxExUnits Parameters
current,
      updateMaxBlockExUnits :: Maybe ExUnits
updateMaxBlockExUnits = Parameters -> Maybe ExUnits
parameterMaxBlockExUnits Parameters
current,
      updateMaxValueSize :: Maybe Word64
updateMaxValueSize = Parameters -> Maybe Word64
parameterMaxValueSize Parameters
current,
      updateCollateralPercentage :: Maybe Word64
updateCollateralPercentage = Parameters -> Maybe Word64
parameterCollateralPercentage Parameters
current,
      updateMaxCollateralInputs :: Maybe Word64
updateMaxCollateralInputs = Parameters -> Maybe Word64
parameterMaxCollateralInputs Parameters
current,
      updatePoolVotingThresholds :: Maybe PoolVotingThresholds
updatePoolVotingThresholds = Parameters -> Maybe PoolVotingThresholds
parameterPoolVotingThresholds Parameters
current,
      updateDrepVotingThresholds :: Maybe DRepVotingThresholds
updateDrepVotingThresholds = Parameters -> Maybe DRepVotingThresholds
parameterDrepVotingThresholds Parameters
current,
      updateMinCommitteeSize :: Maybe Word64
updateMinCommitteeSize = Parameters -> Maybe Word64
parameterMinCommitteeSize Parameters
current,
      updateCommitteeTermLimit :: Maybe Word64
updateCommitteeTermLimit = Parameters -> Maybe Word64
parameterCommitteeTermLimit Parameters
current,
      updateGovernanceActionValidityPeriod :: Maybe Word64
updateGovernanceActionValidityPeriod = Parameters -> Maybe Word64
parameterGovernanceActionValidityPeriod Parameters
current,
      updateGovernanceActionDeposit :: Maybe Word64
updateGovernanceActionDeposit = Parameters -> Maybe Word64
parameterGovernanceActionDeposit Parameters
current,
      updateDrepDeposit :: Maybe Word64
updateDrepDeposit = Parameters -> Maybe Word64
parameterDrepDeposit Parameters
current,
      updateDrepInactivityPeriod :: Maybe Word64
updateDrepInactivityPeriod = Parameters -> Maybe Word64
parameterDrepInactivityPeriod Parameters
current,
      updateRefScriptCostPerByte :: Maybe NonNegativeRational
updateRefScriptCostPerByte = Parameters -> Maybe NonNegativeRational
parameterRefScriptCostPerByte Parameters
current,
      updateMaxRefScriptSizePerBlock :: Maybe Word32
updateMaxRefScriptSizePerBlock = Parameters -> Maybe Word32
parameterMaxRefScriptSizePerBlock Parameters
current,
      updateMaxRefScriptSizePerTx :: Maybe Word32
updateMaxRefScriptSizePerTx = Parameters -> Maybe Word32
parameterMaxRefScriptSizePerTx Parameters
current,
      updateRefScriptCostStride :: Maybe ReferenceScriptCostStride
updateRefScriptCostStride = Parameters -> Maybe ReferenceScriptCostStride
parameterRefScriptCostStride Parameters
current,
      updateRefScriptCostMultiplier :: Maybe NonNegativeRational
updateRefScriptCostMultiplier = Parameters -> Maybe NonNegativeRational
parameterRefScriptCostMultiplier Parameters
current,
      updateMaxPledgeLeverage :: Maybe (Maybe NonNegativeRational)
updateMaxPledgeLeverage = Parameters -> Maybe (Maybe NonNegativeRational)
parameterMaxPledgeLeverage Parameters
current,
      updateMinPoolMargin :: Maybe UnitInterval
updateMinPoolMargin = Parameters -> Maybe UnitInterval
parameterMinPoolMargin Parameters
current,
      updateLeiosAnnouncementPeriodLength :: Maybe Word32
updateLeiosAnnouncementPeriodLength = Parameters -> Maybe Word32
parameterLeiosAnnouncementPeriodLength Parameters
current,
      updateLeiosVotePeriodLength :: Maybe Word32
updateLeiosVotePeriodLength = Parameters -> Maybe Word32
parameterLeiosVotePeriodLength Parameters
current,
      updateLeiosDiffusionPeriodLength :: Maybe Word32
updateLeiosDiffusionPeriodLength = Parameters -> Maybe Word32
parameterLeiosDiffusionPeriodLength Parameters
current,
      updateLeiosCommitteeSize :: Maybe Word16
updateLeiosCommitteeSize = Parameters -> Maybe Word16
parameterLeiosCommitteeSize Parameters
current,
      updateLeiosQuorumStakeThreshold :: Maybe UnitInterval
updateLeiosQuorumStakeThreshold = Parameters -> Maybe UnitInterval
parameterLeiosQuorumStakeThreshold Parameters
current,
      updateMaxEndorserBlockReferencesSize :: Maybe Word32
updateMaxEndorserBlockReferencesSize = Parameters -> Maybe Word32
parameterMaxEndorserBlockReferencesSize Parameters
current,
      updateMaxEndorserBlockTxsSize :: Maybe Word32
updateMaxEndorserBlockTxsSize = Parameters -> Maybe Word32
parameterMaxEndorserBlockTxsSize Parameters
current,
      updateMaxEndorserBlockExecutionUnits :: Maybe ExUnits
updateMaxEndorserBlockExecutionUnits = Parameters -> Maybe ExUnits
parameterMaxEndorserBlockExecutionUnits Parameters
current,
      updateMaxRefScriptSizePerEndorserBlock :: Maybe Word32
updateMaxRefScriptSizePerEndorserBlock = Parameters -> Maybe Word32
parameterMaxRefScriptSizePerEndorserBlock Parameters
current,
      updatePerasMinCandidateBlockAge :: Maybe Word32
updatePerasMinCandidateBlockAge = Parameters -> Maybe Word32
parameterPerasMinCandidateBlockAge Parameters
current,
      updatePerasHealingFactor :: Maybe NonNegativeRational
updatePerasHealingFactor = Parameters -> Maybe NonNegativeRational
parameterPerasHealingFactor Parameters
current,
      updatePerasCertBoost :: Maybe Word16
updatePerasCertBoost = Parameters -> Maybe Word16
parameterPerasCertBoost Parameters
current,
      updatePerasTargetCommitteeSize :: Maybe Word16
updatePerasTargetCommitteeSize = Parameters -> Maybe Word16
parameterPerasTargetCommitteeSize Parameters
current,
      updatePerasBootstrapRound :: Maybe (Maybe Word32)
updatePerasBootstrapRound = Parameters -> Maybe (Maybe Word32)
parameterPerasBootstrapRound Parameters
current,
      updatePerasQuorumThresholdSafetyMargin :: Maybe UnitInterval
updatePerasQuorumThresholdSafetyMargin = Parameters -> Maybe UnitInterval
parameterPerasQuorumThresholdSafetyMargin Parameters
current,
      updateRefInputsCostPerMultiAssetPolicy :: Maybe Word64
updateRefInputsCostPerMultiAssetPolicy = Parameters -> Maybe Word64
parameterRefInputsCostPerMultiAssetPolicy Parameters
current,
      updateRefInputsCostPerDatumByte :: Maybe Word64
updateRefInputsCostPerDatumByte = Parameters -> Maybe Word64
parameterRefInputsCostPerDatumByte Parameters
current
    }

-- CBOR -----------------------------------------------------------------------

-- | Serialize present fields in ascending parameter-key order, using definite
-- collections and minimal integer encodings. Rational pairs remain exact;
-- imported representation is preserved only by 'toCbor'.
encodeCbor :: Update -> ByteString
encodeCbor :: Update -> ByteString
encodeCbor Update
change = Encoding -> ByteString
Write.toStrictByteString (Word -> Encoding
Encode.encodeMapLen (Int -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral ([Encoding] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Encoding]
entries)) Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> [Encoding] -> Encoding
forall a. Monoid a => [a] -> a
mconcat [Encoding]
entries)
  where
    entries :: [Encoding]
entries =
      [[Encoding]] -> [Encoding]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
        [ Word64 -> (Word64 -> Encoding) -> Maybe Word64 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
0 Word64 -> Encoding
Encode.encodeWord64 (Update -> Maybe Word64
updateMinFeeA Update
change),
          Word64 -> (Word64 -> Encoding) -> Maybe Word64 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
1 Word64 -> Encoding
Encode.encodeWord64 (Update -> Maybe Word64
updateMinFeeB Update
change),
          Word64 -> (Word64 -> Encoding) -> Maybe Word64 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
2 Word64 -> Encoding
Encode.encodeWord64 (Update -> Maybe Word64
updateMaxBlockBodySize Update
change),
          Word64 -> (Word64 -> Encoding) -> Maybe Word64 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
3 Word64 -> Encoding
Encode.encodeWord64 (Update -> Maybe Word64
updateMaxTxSize Update
change),
          Word64 -> (Word64 -> Encoding) -> Maybe Word64 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
4 Word64 -> Encoding
Encode.encodeWord64 (Update -> Maybe Word64
updateMaxBlockHeaderSize Update
change),
          Word64 -> (Word64 -> Encoding) -> Maybe Word64 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
5 Word64 -> Encoding
Encode.encodeWord64 (Update -> Maybe Word64
updateKeyDeposit Update
change),
          Word64 -> (Word64 -> Encoding) -> Maybe Word64 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
6 Word64 -> Encoding
Encode.encodeWord64 (Update -> Maybe Word64
updatePoolDeposit Update
change),
          Word64 -> (Word64 -> Encoding) -> Maybe Word64 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
7 Word64 -> Encoding
Encode.encodeWord64 (Update -> Maybe Word64
updateMaxEpoch Update
change),
          Word64 -> (Word64 -> Encoding) -> Maybe Word64 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
8 Word64 -> Encoding
Encode.encodeWord64 (Update -> Maybe Word64
updateDesiredPoolCount Update
change),
          Word64
-> (NonNegativeRational -> Encoding)
-> Maybe NonNegativeRational
-> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
9 NonNegativeRational -> Encoding
Values.encodeRational (Update -> Maybe NonNegativeRational
updatePoolPledgeInfluence Update
change),
          Word64
-> (UnitInterval -> Encoding) -> Maybe UnitInterval -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
10 UnitInterval -> Encoding
Values.encodeUnitInterval (Update -> Maybe UnitInterval
updateExpansionRate Update
change),
          Word64
-> (UnitInterval -> Encoding) -> Maybe UnitInterval -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
11 UnitInterval -> Encoding
Values.encodeUnitInterval (Update -> Maybe UnitInterval
updateTreasuryGrowthRate Update
change),
          Word64
-> (UnitInterval -> Encoding) -> Maybe UnitInterval -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
12 UnitInterval -> Encoding
Values.encodeUnitInterval (Update -> Maybe UnitInterval
updateDecentralization Update
change),
          Word64 -> (Nonce -> Encoding) -> Maybe Nonce -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
13 Nonce -> Encoding
encodeNonce (Update -> Maybe Nonce
updateExtraEntropy Update
change),
          Word64
-> (ProtocolVersion -> Encoding)
-> Maybe ProtocolVersion
-> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
14 ProtocolVersion -> Encoding
Values.encodeProtocolVersion (Update -> Maybe ProtocolVersion
updateProtocolVersion Update
change),
          Word64 -> (Word64 -> Encoding) -> Maybe Word64 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
16 Word64 -> Encoding
Encode.encodeWord64 (Update -> Maybe Word64
updateMinPoolCost Update
change),
          Word64 -> (Word64 -> Encoding) -> Maybe Word64 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
17 Word64 -> Encoding
Encode.encodeWord64 (Update -> Maybe Word64
updateAdaPerUtxoByte Update
change),
          Word64
-> (CostModels -> Encoding) -> Maybe CostModels -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
18 CostModels -> Encoding
Models.encodeCostModels (Update -> Maybe CostModels
updateCostModels Update
change),
          Word64
-> (ExUnitPrices -> Encoding) -> Maybe ExUnitPrices -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
19 ExUnitPrices -> Encoding
Values.encodeExUnitPrices (Update -> Maybe ExUnitPrices
updateExecutionCosts Update
change),
          Word64 -> (ExUnits -> Encoding) -> Maybe ExUnits -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
20 ExUnits -> Encoding
Values.encodeExUnits (Update -> Maybe ExUnits
updateMaxTxExUnits Update
change),
          Word64 -> (ExUnits -> Encoding) -> Maybe ExUnits -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
21 ExUnits -> Encoding
Values.encodeExUnits (Update -> Maybe ExUnits
updateMaxBlockExUnits Update
change),
          Word64 -> (Word64 -> Encoding) -> Maybe Word64 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
22 Word64 -> Encoding
Encode.encodeWord64 (Update -> Maybe Word64
updateMaxValueSize Update
change),
          Word64 -> (Word64 -> Encoding) -> Maybe Word64 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
23 Word64 -> Encoding
Encode.encodeWord64 (Update -> Maybe Word64
updateCollateralPercentage Update
change),
          Word64 -> (Word64 -> Encoding) -> Maybe Word64 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
24 Word64 -> Encoding
Encode.encodeWord64 (Update -> Maybe Word64
updateMaxCollateralInputs Update
change),
          Word64
-> (PoolVotingThresholds -> Encoding)
-> Maybe PoolVotingThresholds
-> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
25 PoolVotingThresholds -> Encoding
Values.encodePoolVotingThresholds (Update -> Maybe PoolVotingThresholds
updatePoolVotingThresholds Update
change),
          Word64
-> (DRepVotingThresholds -> Encoding)
-> Maybe DRepVotingThresholds
-> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
26 DRepVotingThresholds -> Encoding
Values.encodeDRepVotingThresholds (Update -> Maybe DRepVotingThresholds
updateDrepVotingThresholds Update
change),
          Word64 -> (Word64 -> Encoding) -> Maybe Word64 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
27 Word64 -> Encoding
Encode.encodeWord64 (Update -> Maybe Word64
updateMinCommitteeSize Update
change),
          Word64 -> (Word64 -> Encoding) -> Maybe Word64 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
28 Word64 -> Encoding
Encode.encodeWord64 (Update -> Maybe Word64
updateCommitteeTermLimit Update
change),
          Word64 -> (Word64 -> Encoding) -> Maybe Word64 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
29 Word64 -> Encoding
Encode.encodeWord64 (Update -> Maybe Word64
updateGovernanceActionValidityPeriod Update
change),
          Word64 -> (Word64 -> Encoding) -> Maybe Word64 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
30 Word64 -> Encoding
Encode.encodeWord64 (Update -> Maybe Word64
updateGovernanceActionDeposit Update
change),
          Word64 -> (Word64 -> Encoding) -> Maybe Word64 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
31 Word64 -> Encoding
Encode.encodeWord64 (Update -> Maybe Word64
updateDrepDeposit Update
change),
          Word64 -> (Word64 -> Encoding) -> Maybe Word64 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
32 Word64 -> Encoding
Encode.encodeWord64 (Update -> Maybe Word64
updateDrepInactivityPeriod Update
change),
          Word64
-> (NonNegativeRational -> Encoding)
-> Maybe NonNegativeRational
-> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
33 NonNegativeRational -> Encoding
Values.encodeRational (Update -> Maybe NonNegativeRational
updateRefScriptCostPerByte Update
change),
          Word64 -> (Word32 -> Encoding) -> Maybe Word32 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
34 Word32 -> Encoding
Encode.encodeWord32 (Update -> Maybe Word32
updateMaxRefScriptSizePerBlock Update
change),
          Word64 -> (Word32 -> Encoding) -> Maybe Word32 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
35 Word32 -> Encoding
Encode.encodeWord32 (Update -> Maybe Word32
updateMaxRefScriptSizePerTx Update
change),
          Word64
-> (ReferenceScriptCostStride -> Encoding)
-> Maybe ReferenceScriptCostStride
-> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
36 (Word32 -> Encoding
Encode.encodeWord32 (Word32 -> Encoding)
-> (ReferenceScriptCostStride -> Word32)
-> ReferenceScriptCostStride
-> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ReferenceScriptCostStride -> Word32
Parameters.referenceScriptCostStride) (Update -> Maybe ReferenceScriptCostStride
updateRefScriptCostStride Update
change),
          Word64
-> (NonNegativeRational -> Encoding)
-> Maybe NonNegativeRational
-> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
37 NonNegativeRational -> Encoding
Values.encodeRational (Update -> Maybe NonNegativeRational
updateRefScriptCostMultiplier Update
change),
          Word64
-> (Maybe NonNegativeRational -> Encoding)
-> Maybe (Maybe NonNegativeRational)
-> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
38 ((NonNegativeRational -> Encoding)
-> Maybe NonNegativeRational -> Encoding
forall a. (a -> Encoding) -> Maybe a -> Encoding
encodeNullable NonNegativeRational -> Encoding
Values.encodeRational) (Update -> Maybe (Maybe NonNegativeRational)
updateMaxPledgeLeverage Update
change),
          Word64
-> (UnitInterval -> Encoding) -> Maybe UnitInterval -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
39 UnitInterval -> Encoding
Values.encodeUnitInterval (Update -> Maybe UnitInterval
updateMinPoolMargin Update
change),
          Word64 -> (Word32 -> Encoding) -> Maybe Word32 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
40 Word32 -> Encoding
Encode.encodeWord32 (Update -> Maybe Word32
updateLeiosAnnouncementPeriodLength Update
change),
          Word64 -> (Word32 -> Encoding) -> Maybe Word32 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
41 Word32 -> Encoding
Encode.encodeWord32 (Update -> Maybe Word32
updateLeiosVotePeriodLength Update
change),
          Word64 -> (Word32 -> Encoding) -> Maybe Word32 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
42 Word32 -> Encoding
Encode.encodeWord32 (Update -> Maybe Word32
updateLeiosDiffusionPeriodLength Update
change),
          Word64 -> (Word16 -> Encoding) -> Maybe Word16 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
43 Word16 -> Encoding
Encode.encodeWord16 (Update -> Maybe Word16
updateLeiosCommitteeSize Update
change),
          Word64
-> (UnitInterval -> Encoding) -> Maybe UnitInterval -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
44 UnitInterval -> Encoding
Values.encodeUnitInterval (Update -> Maybe UnitInterval
updateLeiosQuorumStakeThreshold Update
change),
          Word64 -> (Word32 -> Encoding) -> Maybe Word32 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
45 Word32 -> Encoding
Encode.encodeWord32 (Update -> Maybe Word32
updateMaxEndorserBlockReferencesSize Update
change),
          Word64 -> (Word32 -> Encoding) -> Maybe Word32 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
46 Word32 -> Encoding
Encode.encodeWord32 (Update -> Maybe Word32
updateMaxEndorserBlockTxsSize Update
change),
          Word64 -> (ExUnits -> Encoding) -> Maybe ExUnits -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
47 ExUnits -> Encoding
Values.encodeExUnits (Update -> Maybe ExUnits
updateMaxEndorserBlockExecutionUnits Update
change),
          Word64 -> (Word32 -> Encoding) -> Maybe Word32 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
48 Word32 -> Encoding
Encode.encodeWord32 (Update -> Maybe Word32
updateMaxRefScriptSizePerEndorserBlock Update
change),
          Word64 -> (Word32 -> Encoding) -> Maybe Word32 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
49 Word32 -> Encoding
Encode.encodeWord32 (Update -> Maybe Word32
updatePerasMinCandidateBlockAge Update
change),
          Word64
-> (NonNegativeRational -> Encoding)
-> Maybe NonNegativeRational
-> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
50 NonNegativeRational -> Encoding
Values.encodeRational (Update -> Maybe NonNegativeRational
updatePerasHealingFactor Update
change),
          Word64 -> (Word16 -> Encoding) -> Maybe Word16 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
51 Word16 -> Encoding
Encode.encodeWord16 (Update -> Maybe Word16
updatePerasCertBoost Update
change),
          Word64 -> (Word16 -> Encoding) -> Maybe Word16 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
52 Word16 -> Encoding
Encode.encodeWord16 (Update -> Maybe Word16
updatePerasTargetCommitteeSize Update
change),
          Word64
-> (Maybe Word32 -> Encoding) -> Maybe (Maybe Word32) -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
53 ((Word32 -> Encoding) -> Maybe Word32 -> Encoding
forall a. (a -> Encoding) -> Maybe a -> Encoding
encodeNullable Word32 -> Encoding
Encode.encodeWord32) (Update -> Maybe (Maybe Word32)
updatePerasBootstrapRound Update
change),
          Word64
-> (UnitInterval -> Encoding) -> Maybe UnitInterval -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
54 UnitInterval -> Encoding
Values.encodeUnitInterval (Update -> Maybe UnitInterval
updatePerasQuorumThresholdSafetyMargin Update
change),
          Word64 -> (Word64 -> Encoding) -> Maybe Word64 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
55 Word64 -> Encoding
Encode.encodeWord64 (Update -> Maybe Word64
updateRefInputsCostPerMultiAssetPolicy Update
change),
          Word64 -> (Word64 -> Encoding) -> Maybe Word64 -> [Encoding]
forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
56 Word64 -> Encoding
Encode.encodeWord64 (Update -> Maybe Word64
updateRefInputsCostPerDatumByte Update
change)
        ]

-- | Decode one complete update, retaining exact bytes. Unknown or duplicate
-- parameter keys, invalid field bounds/arity, malformed CBOR and trailing input
-- return 'InvalidProtocolParametersCbor'. Historical fields are accepted without
-- applying era-specific governance validity rules.
decodeCbor :: ByteString -> Either Error EncodedUpdate
decodeCbor :: ByteString -> Either Error EncodedUpdate
decodeCbor ByteString
bytes = case (forall s. Decoder s Update)
-> ByteString -> Either DeserialiseFailure (ByteString, Update)
forall a.
(forall s. Decoder s a)
-> ByteString -> Either DeserialiseFailure (ByteString, a)
Read.deserialiseFromBytes Decoder s Update
forall s. Decoder s Update
decodeUpdate (ByteString -> ByteString
Lazy.fromStrict ByteString
bytes) of
  Left DeserialiseFailure
failure -> Error -> Either Error EncodedUpdate
forall a b. a -> Either a b
Left (Text -> Error
InvalidProtocolParametersCbor (String -> Text
Text.pack (DeserialiseFailure -> String
forall a. Show a => a -> String
show DeserialiseFailure
failure)))
  Right (ByteString
trailing, Update
change)
    | ByteString -> Bool
Lazy.null ByteString
trailing -> EncodedUpdate -> Either Error EncodedUpdate
forall a b. b -> Either a b
Right (ByteString -> Update -> EncodedUpdate
EncodedUpdate ByteString
bytes Update
change)
    | Bool
otherwise -> Error -> Either Error EncodedUpdate
forall a b. a -> Either a b
Left (Text -> Error
InvalidProtocolParametersCbor Text
"Trailing bytes after protocol update")

-- | Return the exact validated input encoding.
toCbor :: EncodedUpdate -> ByteString
toCbor :: EncodedUpdate -> ByteString
toCbor (EncodedUpdate ByteString
bytes Update
_) = ByteString
bytes

-- | Inspect the Haskell-owned change without altering its original encoding.
toUpdate :: EncodedUpdate -> Update
toUpdate :: EncodedUpdate -> Update
toUpdate (EncodedUpdate ByteString
_ Update
change) = Update
change

field :: Word64 -> (a -> Encode.Encoding) -> Maybe a -> [Encode.Encoding]
field :: forall a. Word64 -> (a -> Encoding) -> Maybe a -> [Encoding]
field Word64
key a -> Encoding
encode = [Encoding] -> (a -> [Encoding]) -> Maybe a -> [Encoding]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\a
value -> [Word64 -> Encoding
Encode.encodeWord64 Word64
key Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> a -> Encoding
encode a
value])

encodeNullable :: (a -> Encode.Encoding) -> Maybe a -> Encode.Encoding
encodeNullable :: forall a. (a -> Encoding) -> Maybe a -> Encoding
encodeNullable = Encoding -> (a -> Encoding) -> Maybe a -> Encoding
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Encoding
Encode.encodeNull

encodeNonce :: Nonce -> Encode.Encoding
encodeNonce :: Nonce -> Encoding
encodeNonce Nonce
nonce = case Nonce -> Maybe ByteString
Parameters.nonceBytes Nonce
nonce of
  Maybe ByteString
Nothing -> Word -> Encoding
Encode.encodeListLen Word
1 Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word -> Encoding
Encode.encodeWord Word
0
  Just ByteString
bytes -> Word -> Encoding
Encode.encodeListLen Word
2 Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word -> Encoding
Encode.encodeWord Word
1 Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> ByteString -> Encoding
Encode.encodeBytes ByteString
bytes

decodeNullable :: Decode.Decoder s a -> Decode.Decoder s (Maybe a)
decodeNullable :: forall s a. Decoder s a -> Decoder s (Maybe a)
decodeNullable Decoder s a
decode = do
  TokenType
token <- Decoder s TokenType
forall s. Decoder s TokenType
Decode.peekTokenType
  if TokenType
token TokenType -> TokenType -> Bool
forall a. Eq a => a -> a -> Bool
== TokenType
Decode.TypeNull then Decoder s ()
forall s. Decoder s ()
Decode.decodeNull Decoder s () -> Decoder s (Maybe a) -> Decoder s (Maybe a)
forall a b. Decoder s a -> Decoder s b -> Decoder s b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Maybe a -> Decoder s (Maybe a)
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe a
forall a. Maybe a
Nothing else a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> Decoder s a -> Decoder s (Maybe a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s a
decode

decodeNonce :: Decode.Decoder s Nonce
decodeNonce :: forall s. Decoder s Nonce
decodeNonce = do
  Int
size <- Decoder s Int
forall s. Decoder s Int
Decode.decodeListLen
  Word
tag <- Decoder s Word
forall s. Decoder s Word
Decode.decodeWord
  case (Int
size, Word
tag) of
    (Int
1, Word
0) -> Nonce -> Decoder s Nonce
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Nonce
Parameters.neutralNonce
    (Int
2, Word
1) -> do
      ByteString
bytes <- Decoder s ByteString
forall s. Decoder s ByteString
Decode.decodeBytes
      (Error -> Decoder s Nonce)
-> (Nonce -> Decoder s Nonce)
-> Either Error Nonce
-> Decoder s Nonce
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Decoder s Nonce -> Error -> Decoder s Nonce
forall a b. a -> b -> a
const (String -> Decoder s Nonce
forall a. String -> Decoder s a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Nonce digest must contain 32 bytes")) Nonce -> Decoder s Nonce
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ByteString -> Either Error Nonce
Parameters.mkNonce ByteString
bytes)
    (Int, Word)
_ -> String -> Decoder s Nonce
forall a. String -> Decoder s a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Invalid entropy nonce variant or arity"

decodeStride :: Decode.Decoder s ReferenceScriptCostStride
decodeStride :: forall s. Decoder s ReferenceScriptCostStride
decodeStride = do
  Word32
value <- Decoder s Word32
forall s. Decoder s Word32
Decode.decodeWord32
  (Error -> Decoder s ReferenceScriptCostStride)
-> (ReferenceScriptCostStride
    -> Decoder s ReferenceScriptCostStride)
-> Either Error ReferenceScriptCostStride
-> Decoder s ReferenceScriptCostStride
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Decoder s ReferenceScriptCostStride
-> Error -> Decoder s ReferenceScriptCostStride
forall a b. a -> b -> a
const (String -> Decoder s ReferenceScriptCostStride
forall a. String -> Decoder s a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Reference script cost stride must be positive")) ReferenceScriptCostStride -> Decoder s ReferenceScriptCostStride
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Integer -> Either Error ReferenceScriptCostStride
Parameters.mkReferenceScriptCostStride (Word32 -> Integer
forall a. Integral a => a -> Integer
toInteger Word32
value))

decodeUpdate :: Decode.Decoder s Update
decodeUpdate :: forall s. Decoder s Update
decodeUpdate = do
  Maybe Int
count <- Decoder s (Maybe Int)
forall s. Decoder s (Maybe Int)
Decode.decodeMapLenOrIndef
  Maybe Int -> Set Word64 -> Update -> Decoder s Update
forall {b} {s}.
(Eq b, Num b) =>
Maybe b -> Set Word64 -> Update -> Decoder s Update
go Maybe Int
count Set Word64
forall a. Set a
Set.empty Update
empty
  where
    go :: Maybe b -> Set Word64 -> Update -> Decoder s Update
go (Just b
0) Set Word64
_ Update
change = Update -> Decoder s Update
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Update
change
    go Maybe b
count Set Word64
seen Update
change = do
      Bool
ended <- case Maybe b
count of
        Maybe b
Nothing -> Decoder s Bool
forall s. Decoder s Bool
Decode.decodeBreakOr
        Just b
_ -> Bool -> Decoder s Bool
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
False
      if Bool
ended
        then Update -> Decoder s Update
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Update
change
        else do
          Word64
key <- Decoder s Word64
forall s. Decoder s Word64
Decode.decodeWord64
          Bool -> Decoder s () -> Decoder s ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Word64 -> Set Word64 -> Bool
forall a. Ord a => a -> Set a -> Bool
Set.notMember Word64
key Set Word64
seen) (String -> Decoder s ()
forall a. String -> Decoder s a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Duplicate protocol parameter key")
          Update
next <- case Word64
key of
            Word64
0 -> (\Word64
value -> Update
change {updateMinFeeA = Just value}) (Word64 -> Update) -> Decoder s Word64 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word64
forall s. Decoder s Word64
Decode.decodeWord64
            Word64
1 -> (\Word64
value -> Update
change {updateMinFeeB = Just value}) (Word64 -> Update) -> Decoder s Word64 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word64
forall s. Decoder s Word64
Decode.decodeWord64
            Word64
2 -> (\Word64
value -> Update
change {updateMaxBlockBodySize = Just value}) (Word64 -> Update) -> Decoder s Word64 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word64
forall s. Decoder s Word64
Decode.decodeWord64
            Word64
3 -> (\Word64
value -> Update
change {updateMaxTxSize = Just value}) (Word64 -> Update) -> Decoder s Word64 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word64
forall s. Decoder s Word64
Decode.decodeWord64
            Word64
4 -> (\Word64
value -> Update
change {updateMaxBlockHeaderSize = Just value}) (Word64 -> Update) -> Decoder s Word64 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word64
forall s. Decoder s Word64
Decode.decodeWord64
            Word64
5 -> (\Word64
value -> Update
change {updateKeyDeposit = Just value}) (Word64 -> Update) -> Decoder s Word64 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word64
forall s. Decoder s Word64
Decode.decodeWord64
            Word64
6 -> (\Word64
value -> Update
change {updatePoolDeposit = Just value}) (Word64 -> Update) -> Decoder s Word64 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word64
forall s. Decoder s Word64
Decode.decodeWord64
            Word64
7 -> (\Word64
value -> Update
change {updateMaxEpoch = Just value}) (Word64 -> Update) -> Decoder s Word64 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word64
forall s. Decoder s Word64
Decode.decodeWord64
            Word64
8 -> (\Word64
value -> Update
change {updateDesiredPoolCount = Just value}) (Word64 -> Update) -> Decoder s Word64 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word64
forall s. Decoder s Word64
Decode.decodeWord64
            Word64
9 -> (\NonNegativeRational
value -> Update
change {updatePoolPledgeInfluence = Just value}) (NonNegativeRational -> Update)
-> Decoder s NonNegativeRational -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s NonNegativeRational
forall s. Decoder s NonNegativeRational
Values.decodeRational
            Word64
10 -> (\UnitInterval
value -> Update
change {updateExpansionRate = Just value}) (UnitInterval -> Update)
-> Decoder s UnitInterval -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s UnitInterval
forall s. Decoder s UnitInterval
Values.decodeUnitInterval
            Word64
11 -> (\UnitInterval
value -> Update
change {updateTreasuryGrowthRate = Just value}) (UnitInterval -> Update)
-> Decoder s UnitInterval -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s UnitInterval
forall s. Decoder s UnitInterval
Values.decodeUnitInterval
            Word64
12 -> (\UnitInterval
value -> Update
change {updateDecentralization = Just value}) (UnitInterval -> Update)
-> Decoder s UnitInterval -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s UnitInterval
forall s. Decoder s UnitInterval
Values.decodeUnitInterval
            Word64
13 -> (\Nonce
value -> Update
change {updateExtraEntropy = Just value}) (Nonce -> Update) -> Decoder s Nonce -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Nonce
forall s. Decoder s Nonce
decodeNonce
            Word64
14 -> (\ProtocolVersion
value -> Update
change {updateProtocolVersion = Just value}) (ProtocolVersion -> Update)
-> Decoder s ProtocolVersion -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s ProtocolVersion
forall s. Decoder s ProtocolVersion
Values.decodeProtocolVersion
            Word64
16 -> (\Word64
value -> Update
change {updateMinPoolCost = Just value}) (Word64 -> Update) -> Decoder s Word64 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word64
forall s. Decoder s Word64
Decode.decodeWord64
            Word64
17 -> (\Word64
value -> Update
change {updateAdaPerUtxoByte = Just value}) (Word64 -> Update) -> Decoder s Word64 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word64
forall s. Decoder s Word64
Decode.decodeWord64
            Word64
18 -> (\CostModels
value -> Update
change {updateCostModels = Just value}) (CostModels -> Update) -> Decoder s CostModels -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s CostModels
forall s. Decoder s CostModels
Models.decodeCostModels
            Word64
19 -> (\ExUnitPrices
value -> Update
change {updateExecutionCosts = Just value}) (ExUnitPrices -> Update)
-> Decoder s ExUnitPrices -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s ExUnitPrices
forall s. Decoder s ExUnitPrices
Values.decodeExUnitPrices
            Word64
20 -> (\ExUnits
value -> Update
change {updateMaxTxExUnits = Just value}) (ExUnits -> Update) -> Decoder s ExUnits -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s ExUnits
forall s. Decoder s ExUnits
Values.decodeExUnits
            Word64
21 -> (\ExUnits
value -> Update
change {updateMaxBlockExUnits = Just value}) (ExUnits -> Update) -> Decoder s ExUnits -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s ExUnits
forall s. Decoder s ExUnits
Values.decodeExUnits
            Word64
22 -> (\Word64
value -> Update
change {updateMaxValueSize = Just value}) (Word64 -> Update) -> Decoder s Word64 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word64
forall s. Decoder s Word64
Decode.decodeWord64
            Word64
23 -> (\Word64
value -> Update
change {updateCollateralPercentage = Just value}) (Word64 -> Update) -> Decoder s Word64 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word64
forall s. Decoder s Word64
Decode.decodeWord64
            Word64
24 -> (\Word64
value -> Update
change {updateMaxCollateralInputs = Just value}) (Word64 -> Update) -> Decoder s Word64 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word64
forall s. Decoder s Word64
Decode.decodeWord64
            Word64
25 -> (\PoolVotingThresholds
value -> Update
change {updatePoolVotingThresholds = Just value}) (PoolVotingThresholds -> Update)
-> Decoder s PoolVotingThresholds -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s PoolVotingThresholds
forall s. Decoder s PoolVotingThresholds
Values.decodePoolVotingThresholds
            Word64
26 -> (\DRepVotingThresholds
value -> Update
change {updateDrepVotingThresholds = Just value}) (DRepVotingThresholds -> Update)
-> Decoder s DRepVotingThresholds -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s DRepVotingThresholds
forall s. Decoder s DRepVotingThresholds
Values.decodeDRepVotingThresholds
            Word64
27 -> (\Word64
value -> Update
change {updateMinCommitteeSize = Just value}) (Word64 -> Update) -> Decoder s Word64 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word64
forall s. Decoder s Word64
Decode.decodeWord64
            Word64
28 -> (\Word64
value -> Update
change {updateCommitteeTermLimit = Just value}) (Word64 -> Update) -> Decoder s Word64 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word64
forall s. Decoder s Word64
Decode.decodeWord64
            Word64
29 -> (\Word64
value -> Update
change {updateGovernanceActionValidityPeriod = Just value}) (Word64 -> Update) -> Decoder s Word64 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word64
forall s. Decoder s Word64
Decode.decodeWord64
            Word64
30 -> (\Word64
value -> Update
change {updateGovernanceActionDeposit = Just value}) (Word64 -> Update) -> Decoder s Word64 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word64
forall s. Decoder s Word64
Decode.decodeWord64
            Word64
31 -> (\Word64
value -> Update
change {updateDrepDeposit = Just value}) (Word64 -> Update) -> Decoder s Word64 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word64
forall s. Decoder s Word64
Decode.decodeWord64
            Word64
32 -> (\Word64
value -> Update
change {updateDrepInactivityPeriod = Just value}) (Word64 -> Update) -> Decoder s Word64 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word64
forall s. Decoder s Word64
Decode.decodeWord64
            Word64
33 -> (\NonNegativeRational
value -> Update
change {updateRefScriptCostPerByte = Just value}) (NonNegativeRational -> Update)
-> Decoder s NonNegativeRational -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s NonNegativeRational
forall s. Decoder s NonNegativeRational
Values.decodeRational
            Word64
34 -> (\Word32
value -> Update
change {updateMaxRefScriptSizePerBlock = Just value}) (Word32 -> Update) -> Decoder s Word32 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word32
forall s. Decoder s Word32
Decode.decodeWord32
            Word64
35 -> (\Word32
value -> Update
change {updateMaxRefScriptSizePerTx = Just value}) (Word32 -> Update) -> Decoder s Word32 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word32
forall s. Decoder s Word32
Decode.decodeWord32
            Word64
36 -> (\ReferenceScriptCostStride
value -> Update
change {updateRefScriptCostStride = Just value}) (ReferenceScriptCostStride -> Update)
-> Decoder s ReferenceScriptCostStride -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s ReferenceScriptCostStride
forall s. Decoder s ReferenceScriptCostStride
decodeStride
            Word64
37 -> (\NonNegativeRational
value -> Update
change {updateRefScriptCostMultiplier = Just value}) (NonNegativeRational -> Update)
-> Decoder s NonNegativeRational -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s NonNegativeRational
forall s. Decoder s NonNegativeRational
Values.decodeRational
            Word64
38 -> (\Maybe NonNegativeRational
value -> Update
change {updateMaxPledgeLeverage = Just value}) (Maybe NonNegativeRational -> Update)
-> Decoder s (Maybe NonNegativeRational) -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s NonNegativeRational
-> Decoder s (Maybe NonNegativeRational)
forall s a. Decoder s a -> Decoder s (Maybe a)
decodeNullable Decoder s NonNegativeRational
forall s. Decoder s NonNegativeRational
Values.decodeRational
            Word64
39 -> (\UnitInterval
value -> Update
change {updateMinPoolMargin = Just value}) (UnitInterval -> Update)
-> Decoder s UnitInterval -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s UnitInterval
forall s. Decoder s UnitInterval
Values.decodeUnitInterval
            Word64
40 -> (\Word32
value -> Update
change {updateLeiosAnnouncementPeriodLength = Just value}) (Word32 -> Update) -> Decoder s Word32 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word32
forall s. Decoder s Word32
Decode.decodeWord32
            Word64
41 -> (\Word32
value -> Update
change {updateLeiosVotePeriodLength = Just value}) (Word32 -> Update) -> Decoder s Word32 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word32
forall s. Decoder s Word32
Decode.decodeWord32
            Word64
42 -> (\Word32
value -> Update
change {updateLeiosDiffusionPeriodLength = Just value}) (Word32 -> Update) -> Decoder s Word32 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word32
forall s. Decoder s Word32
Decode.decodeWord32
            Word64
43 -> (\Word16
value -> Update
change {updateLeiosCommitteeSize = Just value}) (Word16 -> Update) -> Decoder s Word16 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word16
forall s. Decoder s Word16
Decode.decodeWord16
            Word64
44 -> (\UnitInterval
value -> Update
change {updateLeiosQuorumStakeThreshold = Just value}) (UnitInterval -> Update)
-> Decoder s UnitInterval -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s UnitInterval
forall s. Decoder s UnitInterval
Values.decodeUnitInterval
            Word64
45 -> (\Word32
value -> Update
change {updateMaxEndorserBlockReferencesSize = Just value}) (Word32 -> Update) -> Decoder s Word32 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word32
forall s. Decoder s Word32
Decode.decodeWord32
            Word64
46 -> (\Word32
value -> Update
change {updateMaxEndorserBlockTxsSize = Just value}) (Word32 -> Update) -> Decoder s Word32 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word32
forall s. Decoder s Word32
Decode.decodeWord32
            Word64
47 -> (\ExUnits
value -> Update
change {updateMaxEndorserBlockExecutionUnits = Just value}) (ExUnits -> Update) -> Decoder s ExUnits -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s ExUnits
forall s. Decoder s ExUnits
Values.decodeExUnits
            Word64
48 -> (\Word32
value -> Update
change {updateMaxRefScriptSizePerEndorserBlock = Just value}) (Word32 -> Update) -> Decoder s Word32 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word32
forall s. Decoder s Word32
Decode.decodeWord32
            Word64
49 -> (\Word32
value -> Update
change {updatePerasMinCandidateBlockAge = Just value}) (Word32 -> Update) -> Decoder s Word32 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word32
forall s. Decoder s Word32
Decode.decodeWord32
            Word64
50 -> (\NonNegativeRational
value -> Update
change {updatePerasHealingFactor = Just value}) (NonNegativeRational -> Update)
-> Decoder s NonNegativeRational -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s NonNegativeRational
forall s. Decoder s NonNegativeRational
Values.decodeRational
            Word64
51 -> (\Word16
value -> Update
change {updatePerasCertBoost = Just value}) (Word16 -> Update) -> Decoder s Word16 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word16
forall s. Decoder s Word16
Decode.decodeWord16
            Word64
52 -> (\Word16
value -> Update
change {updatePerasTargetCommitteeSize = Just value}) (Word16 -> Update) -> Decoder s Word16 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word16
forall s. Decoder s Word16
Decode.decodeWord16
            Word64
53 -> (\Maybe Word32
value -> Update
change {updatePerasBootstrapRound = Just value}) (Maybe Word32 -> Update)
-> Decoder s (Maybe Word32) -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word32 -> Decoder s (Maybe Word32)
forall s a. Decoder s a -> Decoder s (Maybe a)
decodeNullable Decoder s Word32
forall s. Decoder s Word32
Decode.decodeWord32
            Word64
54 -> (\UnitInterval
value -> Update
change {updatePerasQuorumThresholdSafetyMargin = Just value}) (UnitInterval -> Update)
-> Decoder s UnitInterval -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s UnitInterval
forall s. Decoder s UnitInterval
Values.decodeUnitInterval
            Word64
55 -> (\Word64
value -> Update
change {updateRefInputsCostPerMultiAssetPolicy = Just value}) (Word64 -> Update) -> Decoder s Word64 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word64
forall s. Decoder s Word64
Decode.decodeWord64
            Word64
56 -> (\Word64
value -> Update
change {updateRefInputsCostPerDatumByte = Just value}) (Word64 -> Update) -> Decoder s Word64 -> Decoder s Update
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word64
forall s. Decoder s Word64
Decode.decodeWord64
            Word64
_ -> String -> Decoder s Update
forall a. String -> Decoder s a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Unknown protocol parameter key"
          Maybe b -> Set Word64 -> Update -> Decoder s Update
go (b -> b -> b
forall a. Num a => a -> a -> a
subtract b
1 (b -> b) -> Maybe b -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe b
count) (Word64 -> Set Word64 -> Set Word64
forall a. Ord a => a -> Set a -> Set a
Set.insert Word64
key Set Word64
seen) Update
next

-- | Encode changed parameters for a Plutus governance script. The result is a
-- map keyed by parameter identifiers; absent fields are omitted. Rational values
-- are reduced fractions represented as numerator/denominator lists. Historical
-- decentralization, entropy and protocol-version changes are excluded. This is
-- script data, distinct from protocol-update CBOR, and does not validate whether
-- the changes are permitted in a particular ledger era. Conversion failures
-- return 'NativeError'.
toPlutusData :: Update -> IO (Either Error Data.PlutusData)
toPlutusData :: Update -> IO (Either Error PlutusData)
toPlutusData = ByteString -> IO (Either Error PlutusData)
Native.toPlutusData (ByteString -> IO (Either Error PlutusData))
-> (Update -> ByteString) -> Update -> IO (Either Error PlutusData)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Update -> ByteString
encodeCbor