@@ -79,7 +79,7 @@ import Data.Either.Combinators (maybeToRight)
79
79
import Data.Map.Strict (Map )
80
80
import qualified Data.Map.Strict as Map
81
81
import Data.Maybe (isJust )
82
- import Data.Maybe.Strict (StrictMaybe (.. ))
82
+ import Data.Maybe.Strict (StrictMaybe (.. ))
83
83
import Data.String (IsString )
84
84
import GHC.Generics
85
85
import Lens.Micro
@@ -323,7 +323,7 @@ instance FromJSON ProtocolParameters where
323
323
<*> o .: " monetaryExpansion"
324
324
<*> o .: " treasuryCut"
325
325
<*> o .:? " utxoCostPerWord"
326
- <*> o .:? " costModels" .!= Map. empty
326
+ <*> ( fmap unCostModels <$> o .:? " costModels" ) .!= Map. empty
327
327
<*> o .:? " executionUnitPrices"
328
328
<*> o .:? " maxTxExecutionUnits"
329
329
<*> o .:? " maxBlockExecutionUnits"
@@ -355,7 +355,7 @@ instance ToJSON ProtocolParameters where
355
355
, " txFeePerByte" .= protocolParamTxFeePerByte
356
356
-- Alonzo era:
357
357
, " utxoCostPerWord" .= protocolParamUTxOCostPerWord
358
- , " costModels" .= protocolParamCostModels
358
+ , " costModels" .= CostModels protocolParamCostModels
359
359
, " executionUnitPrices" .= protocolParamPrices
360
360
, " maxTxExecutionUnits" .= protocolParamMaxTxExUnits
361
361
, " maxBlockExecutionUnits" .= protocolParamMaxBlockExUnits
@@ -776,9 +776,20 @@ fromAlonzoPrices Alonzo.Prices{Alonzo.prSteps, Alonzo.prMem} =
776
776
777
777
newtype CostModel = CostModel [Integer ]
778
778
deriving (Eq , Show )
779
- deriving newtype (ToJSON , FromJSON )
780
779
deriving newtype (ToCBOR , FromCBOR )
781
780
781
+ newtype CostModels = CostModels { unCostModels :: Map AnyPlutusScriptVersion CostModel }
782
+ deriving (Eq , Show )
783
+
784
+ instance FromJSON CostModels where
785
+ parseJSON v = CostModels . fromAlonzoCostModels <$> parseJSON v
786
+
787
+ instance ToJSON CostModels where
788
+ toJSON (CostModels costModels) =
789
+ case toAlonzoCostModels costModels of
790
+ Left err -> error $ " Invalid cost model was constructed: " ++ err
791
+ Right ledgerCostModels -> toJSON ledgerCostModels
792
+
782
793
data InvalidCostModel = InvalidCostModel CostModel Alonzo. CostModelApplyError
783
794
deriving Show
784
795
0 commit comments