Skip to content

Commit

Permalink
Fix PlutusV3 cost model decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
errfrom committed Sep 4, 2024
1 parent c12bf2d commit 47e856e
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 571 deletions.
53 changes: 28 additions & 25 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,73 +7,76 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

- [[v9.3.0]](#v930)
- [Fixed](#fixed)
- [Changed](#changed)
- [[v9.2.0]](#v920)
- [Added](#added)
- [Changed](#changed)
- [Changed](#changed-1)
- [Removed](#removed)
- [Fixed](#fixed)
- [Fixed](#fixed-1)
- [[v9.1.0]](#v910)
- [Added](#added-1)
- [Changed](#changed-1)
- [Changed](#changed-2)
- [Removed](#removed-1)
- [Fixed](#fixed-1)
- [Fixed](#fixed-2)
- [[v9.0.0]](#v900)
- [Deprecated](#deprecated)
- [Added](#added-2)
- [Removed](#removed-2)
- [Changed](#changed-2)
- [Fixed](#fixed-2)
- [[v8.0.0]](#v800)
- [Added](#added-3)
- [Changed](#changed-3)
- [Fixed](#fixed-3)
- [[v8.0.0]](#v800)
- [Added](#added-3)
- [Changed](#changed-4)
- [Fixed](#fixed-4)
- [Removed](#removed-3)
- [[v7.0.0]](#v700)
- [Added](#added-4)
- [Changed](#changed-4)
- [Fixed](#fixed-4)
- [Changed](#changed-5)
- [Fixed](#fixed-5)
- [Removed](#removed-4)
- [[v6.0.0]](#v600)
- [Added](#added-5)
- [Changed](#changed-5)
- [Fixed](#fixed-5)
- [Changed](#changed-6)
- [Fixed](#fixed-6)
- [Removed](#removed-5)
- [[v5.0.0]](#v500)
- [Added](#added-6)
- [Changed](#changed-6)
- [Changed](#changed-7)
- [Removed](#removed-6)
- [Fixed](#fixed-6)
- [Fixed](#fixed-7)
- [Runtime Dependencies](#runtime-dependencies)
- [[v4.0.2] - 2023-01-17](#v402---2023-01-17)
- [Fixed](#fixed-7)
- [Fixed](#fixed-8)
- [[v4.0.1] - 2022-12-20](#v401---2022-12-20)
- [Added](#added-7)
- [[v4.0.0] - 2022-12-15](#v400---2022-12-15)
- [Added](#added-8)
- [Changed](#changed-7)
- [Changed](#changed-8)
- [Removed](#removed-7)
- [Fixed](#fixed-8)
- [Fixed](#fixed-9)
- [Runtime Dependencies](#runtime-dependencies-1)
- [[3.0.0] - 2022-11-21](#300---2022-11-21)
- [Added](#added-9)
- [Changed](#changed-8)
- [Changed](#changed-9)
- [Removed](#removed-8)
- [Fixed](#fixed-9)
- [Fixed](#fixed-10)
- [Runtime Dependencies](#runtime-dependencies-2)
- [[2.0.0] - 2022-09-12](#200---2022-09-12)
- [Added](#added-10)
- [Changed](#changed-9)
- [Changed](#changed-10)
- [Removed](#removed-9)
- [Fixed](#fixed-10)
- [Fixed](#fixed-11)
- [[2.0.0-alpha] - 2022-07-05](#200-alpha---2022-07-05)
- [Added](#added-11)
- [Removed](#removed-10)
- [Changed](#changed-10)
- [Fixed](#fixed-11)
- [[1.1.0] - 2022-06-30](#110---2022-06-30)
- [Changed](#changed-11)
- [Fixed](#fixed-12)
- [[1.0.1] - 2022-06-17](#101---2022-06-17)
- [[1.1.0] - 2022-06-30](#110---2022-06-30)
- [Fixed](#fixed-13)
- [[1.0.1] - 2022-06-17](#101---2022-06-17)
- [Fixed](#fixed-14)
- [[1.0.0] - 2022-06-10](#100---2022-06-10)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion spago.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ You can edit this file as you like.
, "foreign-object"
, "formatters"
, "functions"
, "heterogeneous"
, "http-methods"
, "identity"
, "integers"
Expand Down
26 changes: 13 additions & 13 deletions src/Internal/Service/Blockfrost.purs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ import Cardano.Serialization.Lib (toBytes)
import Cardano.Types
( AssetClass(AssetClass)
, AuxiliaryData
, CostModel
, DataHash
, GeneralTransactionMetadata(GeneralTransactionMetadata)
, Language(PlutusV3, PlutusV2, PlutusV1)
Expand Down Expand Up @@ -118,6 +119,7 @@ import Cardano.Types.Epoch (Epoch(Epoch))
import Cardano.Types.ExUnitPrices (ExUnitPrices(ExUnitPrices))
import Cardano.Types.ExUnits (ExUnits(ExUnits))
import Cardano.Types.GeneralTransactionMetadata as GeneralTransactionMetadata
import Cardano.Types.Int (Int) as Cardano
import Cardano.Types.NativeScript
( NativeScript
( ScriptAll
Expand Down Expand Up @@ -193,13 +195,7 @@ import Ctl.Internal.Types.EraSummaries
, EraSummaryParameters
)
import Ctl.Internal.Types.ProtocolParameters
( CostModelV1
, CostModelV2
, CostModelV3
, ProtocolParameters(ProtocolParameters)
, convertPlutusV1CostModel
, convertPlutusV2CostModel
, convertPlutusV3CostModel
( ProtocolParameters(ProtocolParameters)
)
import Ctl.Internal.Types.Rational (Rational, reduce)
import Ctl.Internal.Types.Rational as Rational
Expand Down Expand Up @@ -239,6 +235,7 @@ import Effect.Aff.Class (liftAff)
import Effect.Class (liftEffect)
import Effect.Exception (error)
import Foreign.Object (Object)
import Foreign.Object (values) as Object
import Foreign.Object as ForeignObject
import JS.BigInt (fromString, toNumber) as BigInt
import Prim.TypeError (class Warn, Text)
Expand Down Expand Up @@ -1520,9 +1517,9 @@ type BlockfrostProtocolParametersRaw =
, "protocol_minor_ver" :: UInt
, "min_pool_cost" :: Stringed BigNum
, "cost_models" ::
{ "PlutusV1" :: { | CostModelV1 }
, "PlutusV2" :: { | CostModelV2 }
, "PlutusV3" :: { | CostModelV3 }
{ "PlutusV1" :: Object Cardano.Int
, "PlutusV2" :: Object Cardano.Int
, "PlutusV3" :: Object Cardano.Int
}
, "price_mem" :: FiniteBigNumber
, "price_step" :: FiniteBigNumber
Expand Down Expand Up @@ -1616,9 +1613,9 @@ instance DecodeAeson BlockfrostProtocolParameters where
, treasuryCut
, coinsPerUtxoByte: coinsPerUtxoByte
, costModels: Map.fromFoldable
[ PlutusV1 /\ convertPlutusV1CostModel raw.cost_models."PlutusV1"
, PlutusV2 /\ convertPlutusV2CostModel raw.cost_models."PlutusV2"
, PlutusV3 /\ convertPlutusV3CostModel raw.cost_models."PlutusV3"
[ PlutusV1 /\ convertPlutusCostModel raw.cost_models."PlutusV1"
, PlutusV2 /\ convertPlutusCostModel raw.cost_models."PlutusV2"
, PlutusV3 /\ convertPlutusCostModel raw.cost_models."PlutusV3"
]
, prices
, maxTxExUnits:
Expand All @@ -1638,6 +1635,9 @@ instance DecodeAeson BlockfrostProtocolParameters where
, drepDeposit: Coin $ unwrap raw.drep_deposit
, refScriptCoinsPerByte
}
where
convertPlutusCostModel :: Object Cardano.Int -> CostModel
convertPlutusCostModel = wrap <<< Object.values

--------------------------------------------------------------------------------
-- BlockfrostRewards
Expand Down
Loading

0 comments on commit 47e856e

Please sign in to comment.