Skip to content

Commit

Permalink
Fix building of Alonzo transaction in Babbage era.
Browse files Browse the repository at this point in the history
This is achieved by auto-converting from Babbage field protocolParamUTxOCostPerByte to Alonzo field protocolParamUTxOCostPerWord.
  • Loading branch information
newhoggy committed Jul 11, 2022
1 parent 78a13b0 commit 9df6bd6
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions cardano-api/src/Cardano/Api/ProtocolParameters.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
Expand Down Expand Up @@ -106,8 +107,8 @@ import Text.PrettyBy.Default (display)
import Cardano.Api.Address
import Cardano.Api.Eras
import Cardano.Api.Error
import Cardano.Api.HasTypeProxy
import Cardano.Api.Hash
import Cardano.Api.HasTypeProxy
import Cardano.Api.KeysByron
import Cardano.Api.KeysShelley
import Cardano.Api.Script
Expand All @@ -119,6 +120,7 @@ import Cardano.Api.StakePoolMetadata
import Cardano.Api.TxMetadata
import Cardano.Api.Utils
import Cardano.Api.Value
import Control.Applicative ((<|>))


-- | The values of the set of /updatable/ protocol parameters. At any
Expand Down Expand Up @@ -1436,15 +1438,20 @@ toAlonzoPParams ProtocolParameters {
protocolParamPoolPledgeInfluence,
protocolParamMonetaryExpansion,
protocolParamTreasuryCut,
protocolParamUTxOCostPerWord = Just utxoCostPerWord,
protocolParamUTxOCostPerWord,
protocolParamCostModels,
protocolParamPrices = Just prices,
protocolParamMaxTxExUnits = Just maxTxExUnits,
protocolParamMaxBlockExUnits = Just maxBlockExUnits,
protocolParamMaxValueSize = Just maxValueSize,
protocolParamCollateralPercent = Just collateralPercentage,
protocolParamMaxCollateralInputs = Just maxCollateralInputs
protocolParamMaxCollateralInputs = Just maxCollateralInputs,
protocolParamUTxOCostPerByte
} =
let !coinsPerUTxOWord = fromMaybe
(error "toAlonzoPParams: must specify protocolParamUTxOCostPerWord or protocolParamUTxOCostPerByte") $
protocolParamUTxOCostPerWord <|> ((* 8) <$> protocolParamUTxOCostPerByte)
in
Alonzo.PParams {
Alonzo._protocolVersion
= let (maj, minor) = protocolParamProtocolVersion
Expand Down Expand Up @@ -1483,7 +1490,7 @@ toAlonzoPParams ProtocolParameters {
(Ledger.boundRational protocolParamTreasuryCut)

-- New params in Alonzo:
, Alonzo._coinsPerUTxOWord = toShelleyLovelace utxoCostPerWord
, Alonzo._coinsPerUTxOWord = toShelleyLovelace coinsPerUTxOWord
, Alonzo._costmdls = either
(\e -> error $ "toAlonzoPParams: invalid cost models, error: " <> e)
id
Expand Down

0 comments on commit 9df6bd6

Please sign in to comment.