From dadffe1b4ed48b7330c6d0dc9d9a358ccef166e0 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Fri, 6 Sep 2024 20:53:55 +0530 Subject: [PATCH] feat(#60): store cost models as list --- .../src/Blockfrost/Types/Cardano/Epochs.hs | 13 +++++-------- blockfrost-api/test/Cardano/Epochs.hs | 6 ++---- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/blockfrost-api/src/Blockfrost/Types/Cardano/Epochs.hs b/blockfrost-api/src/Blockfrost/Types/Cardano/Epochs.hs index 4206c47..1c1e4a0 100644 --- a/blockfrost-api/src/Blockfrost/Types/Cardano/Epochs.hs +++ b/blockfrost-api/src/Blockfrost/Types/Cardano/Epochs.hs @@ -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 @@ -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 @@ -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 @@ -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) ] ) diff --git a/blockfrost-api/test/Cardano/Epochs.hs b/blockfrost-api/test/Cardano/Epochs.hs index 29b5045..b733976 100644 --- a/blockfrost-api/test/Cardano/Epochs.hs +++ b/blockfrost-api/test/Cardano/Epochs.hs @@ -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) ] )