Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Common types and functions used across all the ledger API modules.
Synopsis
- evaluateScriptCounting :: LedgerPlutusVersion -> ProtocolVersion -> VerboseMode -> EvaluationContext -> SerialisedScript -> [Data] -> (LogOutput, Either EvaluationError ExBudget)
- evaluateScriptRestricting :: LedgerPlutusVersion -> ProtocolVersion -> VerboseMode -> EvaluationContext -> ExBudget -> SerialisedScript -> [Data] -> (LogOutput, Either EvaluationError ExBudget)
- data EvaluationContext = EvaluationContext {}
- data ScriptDecodeError
- mkDynEvaluationContext :: MonadError CostModelApplyError m => BuiltinVersion DefaultFun -> CostModelParams -> m EvaluationContext
- assertScriptWellFormed :: MonadError ScriptDecodeError m => LedgerPlutusVersion -> ProtocolVersion -> SerialisedScript -> m ()
- assertWellFormedCostModelParams :: MonadError CostModelApplyError m => CostModelParams -> m ()
- toMachineParameters :: ProtocolVersion -> EvaluationContext -> DefaultMachineParameters
- type SerialisedScript = ShortByteString
- serialiseCompiledCode :: forall a. CompiledCode a -> SerialisedScript
- serialiseUPLC :: Program DeBruijn DefaultUni DefaultFun () -> SerialisedScript
- deserialiseUPLC :: SerialisedScript -> Program DeBruijn DefaultUni DefaultFun ()
- data VerboseMode
- type LogOutput = [Text]
- data EvaluationError
- data ProtocolVersion = ProtocolVersion {}
- data LedgerPlutusVersion
- builtinsIntroducedIn :: Map (LedgerPlutusVersion, ProtocolVersion) (Set DefaultFun)
- builtinsAvailableIn :: LedgerPlutusVersion -> ProtocolVersion -> Set DefaultFun
- class IsParamName a
- data GenericParamName a
- toCostModelParams :: IsParamName k => [(k, Integer)] -> CostModelParams
- showParamName :: IsParamName a => a -> String
Documentation
evaluateScriptCounting Source #
:: LedgerPlutusVersion | |
-> ProtocolVersion | |
-> VerboseMode | Whether to produce log output |
-> EvaluationContext | The cost model that should already be synced to the most recent cost-model-params coming from the current protocol |
-> SerialisedScript | The script to evaluate |
-> [Data] | The arguments to the script |
-> (LogOutput, Either EvaluationError ExBudget) |
Evaluates a script, returning the minimum budget that the script would need
to evaluate successfully. This will take as long as the script takes, if you need to
limit the execution time of the script also, you can use evaluateScriptRestricting
, which
also returns the used budget.
Note: Parameterized over the ledger-plutus-version since the builtins allowed (during decoding) differs.
evaluateScriptRestricting Source #
:: LedgerPlutusVersion | |
-> ProtocolVersion | |
-> VerboseMode | Whether to produce log output |
-> EvaluationContext | The cost model that should already be synced to the most recent cost-model-params coming from the current protocol |
-> ExBudget | The resource budget which must not be exceeded during evaluation |
-> SerialisedScript | The script to evaluate |
-> [Data] | The arguments to the script |
-> (LogOutput, Either EvaluationError ExBudget) |
Evaluates a script, with a cost model and a budget that restricts how many resources it can use according to the cost model. Also returns the budget that was actually used.
Can be used to calculate budgets for scripts, but even in this case you must give a limit to guard against scripts that run for a long time or loop.
Note: Parameterized over the ledger-plutus-version since the builtins allowed (during decoding) differs.
data EvaluationContext Source #
An opaque type that contains all the static parameters that the evaluator needs to evaluate a script. This is so that they can be computed once and cached, rather than recomputed on every evaluation.
There are two sets of parameters: one is with immediate unlifting and the other one is with deferred unlifting. We have to keep both of them, because depending on the language version either one has to be used or the other. We also compile them separately due to all the inlining and optimization that need to happen for things to be efficient.
Instances
Generic EvaluationContext Source # | |
Defined in PlutusLedgerApi.Common.Eval from :: EvaluationContext -> Rep EvaluationContext x Source # to :: Rep EvaluationContext x -> EvaluationContext Source # | |
NFData EvaluationContext Source # | |
Defined in PlutusLedgerApi.Common.Eval rnf :: EvaluationContext -> () Source # | |
NoThunks EvaluationContext Source # | |
Defined in PlutusLedgerApi.Common.Eval | |
type Rep EvaluationContext Source # | |
Defined in PlutusLedgerApi.Common.Eval type Rep EvaluationContext = D1 ('MetaData "EvaluationContext" "PlutusLedgerApi.Common.Eval" "plutus-ledger-api-1.0.0.0.0.0.0.0.1-62zX2BmwjkDFan4zfGhQ4n" 'False) (C1 ('MetaCons "EvaluationContext" 'PrefixI 'True) (S1 ('MetaSel ('Just "machineParametersImmediate") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 DefaultMachineParameters) :*: S1 ('MetaSel ('Just "machineParametersDeferred") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 DefaultMachineParameters))) |
data ScriptDecodeError Source #
Instances
mkDynEvaluationContext :: MonadError CostModelApplyError m => BuiltinVersion DefaultFun -> CostModelParams -> m EvaluationContext Source #
Build the EvaluationContext
.
The input is a Map
of Text
s to cost integer values (aka CostModelParams
, CostModel
)
See Note [Inlining meanings of builtins].
assertScriptWellFormed :: MonadError ScriptDecodeError m => LedgerPlutusVersion -> ProtocolVersion -> SerialisedScript -> m () Source #
Check if a Script
is "valid" according to a protocol version. At the moment this means "deserialises correctly", which in particular
implies that it is (almost certainly) an encoded script and the script does not mention any builtins unavailable in the given protocol version.
Note: Parameterized over the ledger-plutus-version since the builtins allowed (during decoding) differs.
assertWellFormedCostModelParams :: MonadError CostModelApplyError m => CostModelParams -> m () Source #
Comparably expensive to mkEvaluationContext
, so it should only be used sparingly.
type SerialisedScript = ShortByteString Source #
Scripts to the ledger are serialised bytestrings.
serialiseCompiledCode :: forall a. CompiledCode a -> SerialisedScript Source #
serialiseUPLC :: Program DeBruijn DefaultUni DefaultFun () -> SerialisedScript Source #
Note [Using Flat for serialising/deserialising Script] `plutus-ledger` uses CBOR for data serialisation and `plutus-core` uses Flat. The choice to use Flat was made to have a more efficient (most wins are in uncompressed size) data serialisation format and use less space on-chain.
To make `plutus-ledger` work with scripts serialised with Flat, and keep the CBOR
format otherwise, we have defined the serialiseUPLC
and deserialiseUPLC
functions.
Because Flat is not self-describing and it gets used in the encoding of Programs, data structures that include scripts (for example, transactions) no-longer benefit for CBOR's ability to self-describe it's format.
data VerboseMode Source #
A simple toggle indicating whether or not we should produce logs.
Instances
Eq VerboseMode Source # | |
Defined in PlutusLedgerApi.Common.Eval (==) :: VerboseMode -> VerboseMode -> Bool Source # (/=) :: VerboseMode -> VerboseMode -> Bool Source # |
data EvaluationError Source #
Errors that can be thrown when evaluating a Plutus script.
CekError (CekEvaluationException NamedDeBruijn DefaultUni DefaultFun) | An error from the evaluator itself |
DeBruijnError FreeVariableError | An error in the pre-evaluation step of converting from de-Bruijn indices |
CodecError ScriptDecodeError | A deserialisation error |
IncompatibleVersionError (Version ()) | An error indicating a version tag that we don't support TODO: make this error more informative when we have more information about what went wrong |
CostModelParameterMismatch | An error indicating that the cost model parameters didn't match what we expected |
Instances
Show EvaluationError Source # | |
Defined in PlutusLedgerApi.Common.Eval | |
Eq EvaluationError Source # | |
Defined in PlutusLedgerApi.Common.Eval (==) :: EvaluationError -> EvaluationError -> Bool Source # (/=) :: EvaluationError -> EvaluationError -> Bool Source # | |
Pretty EvaluationError Source # | |
Defined in PlutusLedgerApi.Common.Eval pretty :: EvaluationError -> Doc ann Source # prettyList :: [EvaluationError] -> Doc ann Source # |
data ProtocolVersion Source #
This represents the Cardano protocol version, with its major and minor components. This relies on careful understanding between us and the ledger as to what this means.
Instances
data LedgerPlutusVersion Source #
The plutus language version as seen from the ledger's side. Note: the ordering of constructors matters for deriving Ord
Instances
builtinsIntroducedIn :: Map (LedgerPlutusVersion, ProtocolVersion) (Set DefaultFun) Source #
A map indicating which builtin functions were introduced in which ProtocolVersion
. Each builtin function should appear at most once.
This *must* be updated when new builtins are added. See Note [New builtins and protocol versions]
builtinsAvailableIn :: LedgerPlutusVersion -> ProtocolVersion -> Set DefaultFun Source #
Which builtin functions are available in the given ProtocolVersion
?
See Note [New builtins and protocol versions]
class IsParamName a Source #
A valid parameter name has to be enumeration, bounded, ordered, and prettyprintable in a "lowerKebab" way.
Each API version should expose such an enumeration as an ADT and create an instance of ParamName out of it.
Instances
IsParamName ParamName Source # | |
Defined in PlutusLedgerApi.V1.ParamName showParamName :: ParamName -> String Source # | |
IsParamName ParamName Source # | |
Defined in PlutusLedgerApi.V2.ParamName showParamName :: ParamName -> String Source # | |
IsParamName ParamName Source # | |
Defined in PlutusLedgerApi.V3.ParamName showParamName :: ParamName -> String Source # | |
(Generic a, GIsParamName (Rep a)) => IsParamName (GenericParamName a) Source # | |
Defined in PlutusLedgerApi.Common.ParamName showParamName :: GenericParamName a -> String Source # |
data GenericParamName a Source #
A Generic wrapper for use with deriving via
Instances
(Generic a, GIsParamName (Rep a)) => IsParamName (GenericParamName a) Source # | |
Defined in PlutusLedgerApi.Common.ParamName showParamName :: GenericParamName a -> String Source # |
toCostModelParams :: IsParamName k => [(k, Integer)] -> CostModelParams Source #
Essentially untag the association of param names to values so that CostModelInterface can make use of it.
showParamName :: IsParamName a => a -> String Source #