Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucsanszky committed May 9, 2024
1 parent 01b2b66 commit 62ad730
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cardano-api/internal/Cardano/Api/ProtocolParameters.hs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ import qualified Cardano.Ledger.Plutus.CostModels as Plutus
import qualified Cardano.Ledger.Plutus.Language as Plutus
import qualified Cardano.Ledger.Shelley.API as Ledger
import Cardano.Slotting.Slot (EpochNo (..))
import PlutusLedgerApi.Common (CostModelApplyError)

import Control.Monad
import Data.Aeson (FromJSON (..), ToJSON (..), object, withObject, (.!=), (.:), (.:?),
Expand Down Expand Up @@ -1128,8 +1129,8 @@ fromAlonzoScriptLanguage Plutus.PlutusV1 = AnyPlutusScriptVersion PlutusScriptV1
fromAlonzoScriptLanguage Plutus.PlutusV2 = AnyPlutusScriptVersion PlutusScriptV2
fromAlonzoScriptLanguage Plutus.PlutusV3 = AnyPlutusScriptVersion PlutusScriptV3

toAlonzoCostModel :: CostModel -> Plutus.Language -> Alonzo.CostModel
toAlonzoCostModel (CostModel m) l = Alonzo.mkCostModel l m
toAlonzoCostModel :: CostModel -> Plutus.Language -> Either ProtocolParametersConversionError Alonzo.CostModel
toAlonzoCostModel (CostModel m) l = first (PpceInvalidCostModel (CostModel m)) $ Alonzo.mkCostModel l m

fromAlonzoCostModel :: Alonzo.CostModel -> CostModel
fromAlonzoCostModel m = CostModel $ Alonzo.getCostModelParams m
Expand Down Expand Up @@ -1859,6 +1860,7 @@ instance Error ProtocolParametersError where
data ProtocolParametersConversionError
= PpceOutOfBounds !ProtocolParameterName !Rational
| PpceVersionInvalid !ProtocolParameterVersion
| PpceInvalidCostModel !CostModel !CostModelApplyError
| PpceMissingParameter !ProtocolParameterName
deriving (Eq, Show, Data)

Expand All @@ -1872,5 +1874,7 @@ instance Error ProtocolParametersConversionError where
"Value for '" <> pretty name <> "' is outside of bounds: " <> pretty (fromRational r :: Double)
PpceVersionInvalid majorProtVer ->
"Major protocol version is invalid: " <> pretty majorProtVer
PpceInvalidCostModel cm err ->
"Invalid cost model: " <> pretty @Text (display err) <> " Cost model: " <> pshow cm
PpceMissingParameter name ->
"Missing parameter: " <> pretty name
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ test_ProtocolParametersConversionError =
testAllErrorMessages @ProtocolParametersConversionError
[ PpceOutOfBounds "pparam" 0.1
, PpceVersionInvalid 99999
, PpceInvalidCostModel costModel (Plutus.CMInternalWriteError string)
, PpceMissingParameter "pparam"
]

Expand Down

0 comments on commit 62ad730

Please sign in to comment.