Skip to content

Commit

Permalink
feat(blockfrost#60): store cost models as list
Browse files Browse the repository at this point in the history
  • Loading branch information
sourabhxyz committed Sep 6, 2024
1 parent 08eea3c commit dadffe1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
13 changes: 5 additions & 8 deletions blockfrost-api/src/Blockfrost/Types/Cardano/Epochs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ instance ToSample ProtocolParams where
, _protocolParamsMinFeeRefScriptCostPerByte = Just 15
}

newtype CostModels = CostModels { unCostModels :: Map ScriptType (Map Text Integer) }
newtype CostModels = CostModels { unCostModels :: Map ScriptType [(Text, Integer)] }
deriving (Eq, Show, Generic)

instance ToJSON CostModels where
Expand All @@ -186,8 +186,7 @@ instance ToJSON CostModels where
$ map (\(key, param) ->
( Data.Aeson.Key.fromText key
, toJSON param)
)
$ Data.Map.toList params
) params
))
. Data.Map.toList
. unCostModels
Expand All @@ -207,7 +206,7 @@ instance FromJSON CostModels where
)
$ Data.Aeson.Key.toString kLang
ps <- parseParams vParams
pure (l, Data.Map.fromList ps)
pure (l, ps)
)
$ Data.Aeson.KeyMap.toList o

Expand All @@ -217,14 +216,12 @@ costModelsSample :: CostModels
costModelsSample = CostModels
$ Data.Map.fromList
[ ( PlutusV1
, Data.Map.fromList
[ ("addInteger-cpu-arguments-intercept", 197209)
, [ ("addInteger-cpu-arguments-intercept", 197209)
, ("addInteger-cpu-arguments-slope", 0)
]
)
, (PlutusV2
, Data.Map.fromList
[ ("addInteger-cpu-arguments-intercept", 197209)
, [ ("addInteger-cpu-arguments-intercept", 197209)
, ("addInteger-cpu-arguments-slope", 0)
]
)
Expand Down
6 changes: 2 additions & 4 deletions blockfrost-api/test/Cardano/Epochs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,12 @@ protocolParamsExpected =
CostModels
$ Data.Map.fromList
[ ( PlutusV1
, Data.Map.fromList
[ ("addInteger-cpu-arguments-intercept", 197209)
, [ ("addInteger-cpu-arguments-intercept", 197209)
, ("addInteger-cpu-arguments-slope", 0)
]
)
, (PlutusV2
, Data.Map.fromList
[ ("addInteger-cpu-arguments-intercept", 197209)
, [ ("addInteger-cpu-arguments-intercept", 197209)
, ("addInteger-cpu-arguments-slope", 0)
]
)
Expand Down

0 comments on commit dadffe1

Please sign in to comment.