{-# LANGUAGE TypeApplications #-}
module PlutusLedgerApi.V2.EvaluationContext
( EvaluationContext
, mkEvaluationContext
, CostModelParams
, assertWellFormedCostModelParams
, toMachineParameters
, CostModelApplyError (..)
) where
import PlutusLedgerApi.Common
import PlutusLedgerApi.Common.Versions (changPV)
import PlutusLedgerApi.V2.ParamName as V2
import PlutusCore.Default (BuiltinSemanticsVariant (DefaultFunSemanticsVariantA, DefaultFunSemanticsVariantB))
import Control.Monad
import Control.Monad.Writer.Strict
import Data.Int (Int64)
mkEvaluationContext :: (MonadError CostModelApplyError m, MonadWriter [CostModelApplyWarn] m)
=> [Int64]
-> m EvaluationContext
mkEvaluationContext :: forall (m :: * -> *).
(MonadError CostModelApplyError m,
MonadWriter [CostModelApplyWarn] m) =>
[Int64] -> m EvaluationContext
mkEvaluationContext =
forall k (m :: * -> *).
(Enum k, Bounded k, MonadError CostModelApplyError m,
MonadWriter [CostModelApplyWarn] m) =>
[Int64] -> m [(k, Int64)]
tagWithParamNames @V2.ParamName
([Int64] -> m [(ParamName, Int64)])
-> ([(ParamName, Int64)] -> m EvaluationContext)
-> [Int64]
-> m EvaluationContext
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> CostModelParams -> m CostModelParams
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CostModelParams -> m CostModelParams)
-> ([(ParamName, Int64)] -> CostModelParams)
-> [(ParamName, Int64)]
-> m CostModelParams
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(ParamName, Int64)] -> CostModelParams
forall p. IsParamName p => [(p, Int64)] -> CostModelParams
toCostModelParams
([(ParamName, Int64)] -> m CostModelParams)
-> (CostModelParams -> m EvaluationContext)
-> [(ParamName, Int64)]
-> m EvaluationContext
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> PlutusLedgerLanguage
-> [BuiltinSemanticsVariant DefaultFun]
-> (MajorProtocolVersion -> BuiltinSemanticsVariant DefaultFun)
-> CostModelParams
-> m EvaluationContext
forall (m :: * -> *).
MonadError CostModelApplyError m =>
PlutusLedgerLanguage
-> [BuiltinSemanticsVariant DefaultFun]
-> (MajorProtocolVersion -> BuiltinSemanticsVariant DefaultFun)
-> CostModelParams
-> m EvaluationContext
mkDynEvaluationContext
PlutusLedgerLanguage
PlutusV2
[BuiltinSemanticsVariant DefaultFun
DefaultFunSemanticsVariantA, BuiltinSemanticsVariant DefaultFun
DefaultFunSemanticsVariantB]
(\MajorProtocolVersion
pv -> if MajorProtocolVersion
pv MajorProtocolVersion -> MajorProtocolVersion -> Bool
forall a. Ord a => a -> a -> Bool
< MajorProtocolVersion
changPV
then BuiltinSemanticsVariant DefaultFun
DefaultFunSemanticsVariantA
else BuiltinSemanticsVariant DefaultFun
DefaultFunSemanticsVariantB)