@@ -21,7 +21,7 @@ module Cardano.Ledger.Alonzo.Genesis (
2121 extraConfig ,
2222 AlonzoGenesis ,
2323 agCoinsPerUTxOWord ,
24- agCostModels ,
24+ agPlutusV1CostModel ,
2525 agPrices ,
2626 agMaxTxExUnits ,
2727 agMaxBlockExUnits ,
@@ -38,25 +38,28 @@ import Cardano.Ledger.Alonzo.PParams (
3838 CoinPerWord ,
3939 UpgradeAlonzoPParams (.. ),
4040 )
41- import Cardano.Ledger.Alonzo.Scripts (CostModels , ExUnits (.. ), Prices (.. ))
41+ import Cardano.Ledger.Alonzo.Scripts (
42+ CostModel ,
43+ CostModels ,
44+ ExUnits (.. ),
45+ Prices (.. ),
46+ decodeCostModel ,
47+ decodeCostModelsLenient ,
48+ encodeCostModel ,
49+ )
4250import Cardano.Ledger.BaseTypes (KeyValuePairs (.. ), ToKeyValuePairs (.. ))
4351import Cardano.Ledger.Binary (
44- DecCBOR ,
45- EncCBOR ,
52+ DecCBOR ( .. ) ,
53+ EncCBOR ( .. ) ,
4654 FromCBOR (.. ),
4755 ToCBOR (.. ),
56+ decodeNullMaybe ,
57+ encodeNullMaybe ,
4858 )
49- import Cardano.Ledger.Binary.Coders (
50- Decode (From , RecD ),
51- Encode (Rec , To ),
52- decode ,
53- encode ,
54- (!>) ,
55- (<!) ,
56- )
59+ import Cardano.Ledger.Binary.Coders
5760import Cardano.Ledger.Core
5861import Cardano.Ledger.Genesis (EraGenesis (.. ))
59- import Cardano.Ledger.Plutus.CostModels (parseCostModels )
62+ import Cardano.Ledger.Plutus.CostModels (parseCostModelAsArray , parseCostModels )
6063import Cardano.Ledger.Plutus.Language (Language (.. ))
6164import Control.DeepSeq (NFData )
6265import Data.Aeson (FromJSON (.. ), ToJSON (.. ), (.:) , (.:?) , (.=) )
@@ -82,7 +85,25 @@ newtype AlonzoExtraConfig = AlonzoExtraConfig
8285 { aecCostModels :: Maybe CostModels
8386 }
8487 deriving (Eq )
85- deriving newtype (EncCBOR , DecCBOR , NFData , NoThunks , Show )
88+ deriving newtype (NFData , NoThunks , Show )
89+
90+ instance DecCBOR AlonzoExtraConfig
91+
92+ instance EncCBOR AlonzoExtraConfig
93+
94+ instance FromCBOR AlonzoExtraConfig where
95+ fromCBOR =
96+ eraDecoder @ AlonzoEra $
97+ decode $
98+ RecD AlonzoExtraConfig
99+ <! D (decodeNullMaybe decodeCostModelsLenient)
100+
101+ instance ToCBOR AlonzoExtraConfig where
102+ toCBOR x@ (AlonzoExtraConfig _) =
103+ let AlonzoExtraConfig {.. } = x
104+ in toEraCBOR @ AlonzoEra . encode $
105+ Rec AlonzoExtraConfig
106+ !> E (encodeNullMaybe encCBOR) aecCostModels
86107
87108instance FromJSON AlonzoExtraConfig where
88109 parseJSON = Aeson. withObject " Extra Config" $ \ o ->
@@ -95,7 +116,7 @@ instance ToJSON AlonzoExtraConfig where
95116
96117pattern AlonzoGenesis ::
97118 CoinPerWord ->
98- CostModels ->
119+ CostModel ->
99120 Prices ->
100121 ExUnits ->
101122 ExUnits ->
@@ -106,7 +127,7 @@ pattern AlonzoGenesis ::
106127 AlonzoGenesis
107128pattern AlonzoGenesis
108129 { agCoinsPerUTxOWord
109- , agCostModels
130+ , agPlutusV1CostModel
110131 , agPrices
111132 , agMaxTxExUnits
112133 , agMaxBlockExUnits
@@ -119,7 +140,7 @@ pattern AlonzoGenesis
119140 { unAlonzoGenesisWrapper =
120141 UpgradeAlonzoPParams
121142 { uappCoinsPerUTxOWord = agCoinsPerUTxOWord
122- , uappCostModels = agCostModels
143+ , uappPlutusV1CostModel = agPlutusV1CostModel
123144 , uappPrices = agPrices
124145 , uappMaxTxExUnits = agMaxTxExUnits
125146 , uappMaxBlockExUnits = agMaxBlockExUnits
@@ -143,7 +164,7 @@ pattern AlonzoGenesis
143164 AlonzoGenesisWrapper
144165 ( UpgradeAlonzoPParams
145166 { uappCoinsPerUTxOWord = coinsPerUTxOWord_
146- , uappCostModels = costModels_
167+ , uappPlutusV1CostModel = costModels_
147168 , uappPrices = prices_
148169 , uappMaxTxExUnits = maxTxExUnits_
149170 , uappMaxBlockExUnits = maxBlockExUnits_
@@ -170,7 +191,7 @@ instance FromCBOR AlonzoGenesis where
170191 decode $
171192 RecD AlonzoGenesis
172193 <! From
173- <! From
194+ <! D (decodeCostModel PlutusV1 )
174195 <! From
175196 <! From
176197 <! From
@@ -180,33 +201,24 @@ instance FromCBOR AlonzoGenesis where
180201 <! From
181202
182203instance ToCBOR AlonzoGenesis where
183- toCBOR
184- AlonzoGenesis
185- { agCoinsPerUTxOWord
186- , agCostModels
187- , agPrices
188- , agMaxTxExUnits
189- , agMaxBlockExUnits
190- , agMaxValSize
191- , agCollateralPercentage
192- , agMaxCollateralInputs
193- } =
194- toEraCBOR @ AlonzoEra
195- . encode
196- $ Rec AlonzoGenesis
197- !> To agCoinsPerUTxOWord
198- !> To agCostModels
199- !> To agPrices
200- !> To agMaxTxExUnits
201- !> To agMaxBlockExUnits
202- !> To agMaxValSize
203- !> To agCollateralPercentage
204- !> To agMaxCollateralInputs
204+ toCBOR x@ (AlonzoGenesis _ _ _ _ _ _ _ _ _) =
205+ let AlonzoGenesis {.. } = x
206+ in toEraCBOR @ AlonzoEra . encode $
207+ Rec AlonzoGenesis
208+ !> To agCoinsPerUTxOWord
209+ !> E encodeCostModel agPlutusV1CostModel
210+ !> To agPrices
211+ !> To agMaxTxExUnits
212+ !> To agMaxBlockExUnits
213+ !> To agMaxValSize
214+ !> To agCollateralPercentage
215+ !> To agMaxCollateralInputs
216+ !> To agExtraConfig
205217
206218instance FromJSON AlonzoGenesis where
207219 parseJSON = Aeson. withObject " Alonzo Genesis" $ \ o -> do
208220 agCoinsPerUTxOWord <- o .: " lovelacePerUTxOWord"
209- agCostModels <- parseCostModels False [ PlutusV1 ] =<< o .: " costModels "
221+ agPlutusV1CostModel <- parseCostModelAsArray False PlutusV1 =<< o .: " plutusV1CostModel "
210222 agPrices <- o .: " executionPrices"
211223 agMaxTxExUnits <- o .: " maxTxExUnits"
212224 agMaxBlockExUnits <- o .: " maxBlockExUnits"
@@ -219,7 +231,7 @@ instance FromJSON AlonzoGenesis where
219231instance ToKeyValuePairs AlonzoGenesis where
220232 toKeyValuePairs ag =
221233 [ " lovelacePerUTxOWord" .= agCoinsPerUTxOWord ag
222- , " costModels " .= agCostModels ag
234+ , " plutusV1CostModel " .= agPlutusV1CostModel ag
223235 , " executionPrices" .= agPrices ag
224236 , " maxTxExUnits" .= agMaxTxExUnits ag
225237 , " maxBlockExUnits" .= agMaxBlockExUnits ag
0 commit comments