Skip to content

Commit 5aa8e07

Browse files
committed
Enforce PlutusV3 cost model key order
1 parent 47e856e commit 5aa8e07

File tree

4 files changed

+513
-12
lines changed

4 files changed

+513
-12
lines changed

fixtures/test/blockfrost/getProtocolParameters/.gitkeep

Whitespace-only changes.

spago.dhall

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ You can edit this file as you like.
4444
, "foreign-object"
4545
, "formatters"
4646
, "functions"
47+
, "heterogeneous"
4748
, "http-methods"
4849
, "identity"
4950
, "integers"

src/Internal/Service/Blockfrost.purs

+18-11
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ import Cardano.Serialization.Lib (toBytes)
8787
import Cardano.Types
8888
( AssetClass(AssetClass)
8989
, AuxiliaryData
90-
, CostModel
9190
, DataHash
9291
, GeneralTransactionMetadata(GeneralTransactionMetadata)
9392
, Language(PlutusV3, PlutusV2, PlutusV1)
@@ -195,7 +194,13 @@ import Ctl.Internal.Types.EraSummaries
195194
, EraSummaryParameters
196195
)
197196
import Ctl.Internal.Types.ProtocolParameters
198-
( ProtocolParameters(ProtocolParameters)
197+
( CostModelV1
198+
, CostModelV2
199+
, ProtocolParameters(ProtocolParameters)
200+
, convertPlutusV1CostModel
201+
, convertPlutusV2CostModel
202+
, convertPlutusV3CostModel
203+
, convertUnnamedPlutusCostModel
199204
)
200205
import Ctl.Internal.Types.Rational (Rational, reduce)
201206
import Ctl.Internal.Types.Rational as Rational
@@ -235,7 +240,6 @@ import Effect.Aff.Class (liftAff)
235240
import Effect.Class (liftEffect)
236241
import Effect.Exception (error)
237242
import Foreign.Object (Object)
238-
import Foreign.Object (values) as Object
239243
import Foreign.Object as ForeignObject
240244
import JS.BigInt (fromString, toNumber) as BigInt
241245
import Prim.TypeError (class Warn, Text)
@@ -1517,8 +1521,8 @@ type BlockfrostProtocolParametersRaw =
15171521
, "protocol_minor_ver" :: UInt
15181522
, "min_pool_cost" :: Stringed BigNum
15191523
, "cost_models" ::
1520-
{ "PlutusV1" :: Object Cardano.Int
1521-
, "PlutusV2" :: Object Cardano.Int
1524+
{ "PlutusV1" :: { | CostModelV1 }
1525+
, "PlutusV2" :: { | CostModelV2 }
15221526
, "PlutusV3" :: Object Cardano.Int
15231527
}
15241528
, "price_mem" :: FiniteBigNumber
@@ -1594,6 +1598,12 @@ instance DecodeAeson BlockfrostProtocolParameters where
15941598
raw.min_fee_ref_script_cost_per_byte
15951599
)
15961600
one
1601+
let plutusV3CostModelRaw = raw.cost_models."PlutusV3"
1602+
plutusV3CostModel <-
1603+
note (AtKey "cost_models" $ AtKey "PlutusV3" $ TypeMismatch "CostModel")
1604+
( convertPlutusV3CostModel plutusV3CostModelRaw
1605+
<|> convertUnnamedPlutusCostModel plutusV3CostModelRaw
1606+
)
15971607
pure $ BlockfrostProtocolParameters $ ProtocolParameters
15981608
{ protocolVersion: raw.protocol_major_ver /\ raw.protocol_minor_ver
15991609
-- The following two parameters were removed from Babbage
@@ -1613,9 +1623,9 @@ instance DecodeAeson BlockfrostProtocolParameters where
16131623
, treasuryCut
16141624
, coinsPerUtxoByte: coinsPerUtxoByte
16151625
, costModels: Map.fromFoldable
1616-
[ PlutusV1 /\ convertPlutusCostModel raw.cost_models."PlutusV1"
1617-
, PlutusV2 /\ convertPlutusCostModel raw.cost_models."PlutusV2"
1618-
, PlutusV3 /\ convertPlutusCostModel raw.cost_models."PlutusV3"
1626+
[ PlutusV1 /\ convertPlutusV1CostModel raw.cost_models."PlutusV1"
1627+
, PlutusV2 /\ convertPlutusV2CostModel raw.cost_models."PlutusV2"
1628+
, PlutusV3 /\ plutusV3CostModel
16191629
]
16201630
, prices
16211631
, maxTxExUnits:
@@ -1635,9 +1645,6 @@ instance DecodeAeson BlockfrostProtocolParameters where
16351645
, drepDeposit: Coin $ unwrap raw.drep_deposit
16361646
, refScriptCoinsPerByte
16371647
}
1638-
where
1639-
convertPlutusCostModel :: Object Cardano.Int -> CostModel
1640-
convertPlutusCostModel = wrap <<< Object.values
16411648

16421649
--------------------------------------------------------------------------------
16431650
-- BlockfrostRewards

0 commit comments

Comments
 (0)