Skip to content

Commit f7d574e

Browse files
Merge #4166
4166: Fix building of Alonzo transaction in Babbage era. r=newhoggy a=newhoggy This is achieved by auto-converting from Babbage field `protocolParamUTxOCostPerByte` to Alonzo field `protocolParamUTxOCostPerWord`, which is a multiplication by `8`. Fixes #4164 Co-authored-by: John Ky <[email protected]>
2 parents d25f48a + 51b9a22 commit f7d574e

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

cardano-api/src/Cardano/Api/ProtocolParameters.hs

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE BangPatterns #-}
12
{-# LANGUAGE DeriveAnyClass #-}
23
{-# LANGUAGE DeriveGeneric #-}
34
{-# LANGUAGE DerivingVia #-}
@@ -64,6 +65,7 @@ module Cardano.Api.ProtocolParameters (
6465

6566
import Prelude
6667

68+
import Control.Applicative ((<|>))
6769
import Control.Monad
6870
import Data.Aeson (FromJSON (..), ToJSON (..), object, withObject, (.!=), (.:), (.:?),
6971
(.=))
@@ -106,8 +108,8 @@ import Text.PrettyBy.Default (display)
106108
import Cardano.Api.Address
107109
import Cardano.Api.Eras
108110
import Cardano.Api.Error
109-
import Cardano.Api.HasTypeProxy
110111
import Cardano.Api.Hash
112+
import Cardano.Api.HasTypeProxy
111113
import Cardano.Api.KeysByron
112114
import Cardano.Api.KeysShelley
113115
import Cardano.Api.Script
@@ -120,7 +122,6 @@ import Cardano.Api.TxMetadata
120122
import Cardano.Api.Utils
121123
import Cardano.Api.Value
122124

123-
124125
-- | The values of the set of /updatable/ protocol parameters. At any
125126
-- particular point on the chain there is a current set of parameters in use.
126127
--
@@ -1436,15 +1437,20 @@ toAlonzoPParams ProtocolParameters {
14361437
protocolParamPoolPledgeInfluence,
14371438
protocolParamMonetaryExpansion,
14381439
protocolParamTreasuryCut,
1439-
protocolParamUTxOCostPerWord = Just utxoCostPerWord,
1440+
protocolParamUTxOCostPerWord,
14401441
protocolParamCostModels,
14411442
protocolParamPrices = Just prices,
14421443
protocolParamMaxTxExUnits = Just maxTxExUnits,
14431444
protocolParamMaxBlockExUnits = Just maxBlockExUnits,
14441445
protocolParamMaxValueSize = Just maxValueSize,
14451446
protocolParamCollateralPercent = Just collateralPercentage,
1446-
protocolParamMaxCollateralInputs = Just maxCollateralInputs
1447+
protocolParamMaxCollateralInputs = Just maxCollateralInputs,
1448+
protocolParamUTxOCostPerByte
14471449
} =
1450+
let !coinsPerUTxOWord = fromMaybe
1451+
(error "toAlonzoPParams: must specify protocolParamUTxOCostPerWord or protocolParamUTxOCostPerByte") $
1452+
protocolParamUTxOCostPerWord <|> ((* 8) <$> protocolParamUTxOCostPerByte)
1453+
in
14481454
Alonzo.PParams {
14491455
Alonzo._protocolVersion
14501456
= let (maj, minor) = protocolParamProtocolVersion
@@ -1483,7 +1489,7 @@ toAlonzoPParams ProtocolParameters {
14831489
(Ledger.boundRational protocolParamTreasuryCut)
14841490

14851491
-- New params in Alonzo:
1486-
, Alonzo._coinsPerUTxOWord = toShelleyLovelace utxoCostPerWord
1492+
, Alonzo._coinsPerUTxOWord = toShelleyLovelace coinsPerUTxOWord
14871493
, Alonzo._costmdls = either
14881494
(\e -> error $ "toAlonzoPParams: invalid cost models, error: " <> e)
14891495
id

0 commit comments

Comments
 (0)