plutus-ledger-api-1.0.0.0.0.0.0.0.1: Interface to the Plutus ledger for the Cardano ledger.
Safe HaskellSafe-Inferred
LanguageHaskell2010

PlutusLedgerApi.Common

Description

Common types and functions used across all the ledger API modules.

Synopsis

Documentation

evaluateScriptCounting Source #

Arguments

:: 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 #

Arguments

:: 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

Instances details
Generic EvaluationContext Source # 
Instance details

Defined in PlutusLedgerApi.Common.Eval

Associated Types

type Rep EvaluationContext :: Type -> Type Source #

NFData EvaluationContext Source # 
Instance details

Defined in PlutusLedgerApi.Common.Eval

Methods

rnf :: EvaluationContext -> () Source #

NoThunks EvaluationContext Source # 
Instance details

Defined in PlutusLedgerApi.Common.Eval

type Rep EvaluationContext Source # 
Instance details

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)))

mkDynEvaluationContext :: MonadError CostModelApplyError m => BuiltinVersion DefaultFun -> CostModelParams -> m EvaluationContext Source #

Build the EvaluationContext.

The input is a Map of Texts 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.

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.

Constructors

Verbose 
Quiet 

Instances

Instances details
Eq VerboseMode Source # 
Instance details

Defined in PlutusLedgerApi.Common.Eval

type LogOutput = [Text] Source #

The type of log output: just a list of Text.

data EvaluationError Source #

Errors that can be thrown when evaluating a Plutus script.

Constructors

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

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.

Constructors

ProtocolVersion 

Fields

Instances

Instances details
Generic ProtocolVersion Source # 
Instance details

Defined in PlutusLedgerApi.Common.ProtocolVersions

Associated Types

type Rep ProtocolVersion :: Type -> Type Source #

Show ProtocolVersion Source # 
Instance details

Defined in PlutusLedgerApi.Common.ProtocolVersions

Eq ProtocolVersion Source # 
Instance details

Defined in PlutusLedgerApi.Common.ProtocolVersions

Ord ProtocolVersion Source # 
Instance details

Defined in PlutusLedgerApi.Common.ProtocolVersions

Pretty ProtocolVersion Source # 
Instance details

Defined in PlutusLedgerApi.Common.ProtocolVersions

Serialise ProtocolVersion Source # 
Instance details

Defined in PlutusLedgerApi.Common.ProtocolVersions

type Rep ProtocolVersion Source # 
Instance details

Defined in PlutusLedgerApi.Common.ProtocolVersions

type Rep ProtocolVersion = D1 ('MetaData "ProtocolVersion" "PlutusLedgerApi.Common.ProtocolVersions" "plutus-ledger-api-1.0.0.0.0.0.0.0.1-62zX2BmwjkDFan4zfGhQ4n" 'False) (C1 ('MetaCons "ProtocolVersion" 'PrefixI 'True) (S1 ('MetaSel ('Just "pvMajor") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int) :*: S1 ('MetaSel ('Just "pvMinor") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))

data LedgerPlutusVersion Source #

The plutus language version as seen from the ledger's side. Note: the ordering of constructors matters for deriving Ord

Constructors

PlutusV1 
PlutusV2 
PlutusV3 

Instances

Instances details
Bounded LedgerPlutusVersion Source # 
Instance details

Defined in PlutusLedgerApi.Common.Versions

Enum LedgerPlutusVersion Source # 
Instance details

Defined in PlutusLedgerApi.Common.Versions

Generic LedgerPlutusVersion Source # 
Instance details

Defined in PlutusLedgerApi.Common.Versions

Associated Types

type Rep LedgerPlutusVersion :: Type -> Type Source #

Show LedgerPlutusVersion Source # 
Instance details

Defined in PlutusLedgerApi.Common.Versions

Eq LedgerPlutusVersion Source # 
Instance details

Defined in PlutusLedgerApi.Common.Versions

Ord LedgerPlutusVersion Source # 
Instance details

Defined in PlutusLedgerApi.Common.Versions

Pretty LedgerPlutusVersion Source # 
Instance details

Defined in PlutusLedgerApi.Common.Versions

type Rep LedgerPlutusVersion Source # 
Instance details

Defined in PlutusLedgerApi.Common.Versions

type Rep LedgerPlutusVersion = D1 ('MetaData "LedgerPlutusVersion" "PlutusLedgerApi.Common.Versions" "plutus-ledger-api-1.0.0.0.0.0.0.0.1-62zX2BmwjkDFan4zfGhQ4n" 'False) (C1 ('MetaCons "PlutusV1" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "PlutusV2" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "PlutusV3" 'PrefixI 'False) (U1 :: Type -> Type)))

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.

Minimal complete definition

showParamName

Instances

Instances details
IsParamName ParamName Source # 
Instance details

Defined in PlutusLedgerApi.V1.ParamName

IsParamName ParamName Source # 
Instance details

Defined in PlutusLedgerApi.V2.ParamName

IsParamName ParamName Source # 
Instance details

Defined in PlutusLedgerApi.V3.ParamName

(Generic a, GIsParamName (Rep a)) => IsParamName (GenericParamName a) Source # 
Instance details

Defined in PlutusLedgerApi.Common.ParamName

data GenericParamName a Source #

A Generic wrapper for use with deriving via

Instances

Instances details
(Generic a, GIsParamName (Rep a)) => IsParamName (GenericParamName a) Source # 
Instance details

Defined in PlutusLedgerApi.Common.ParamName

toCostModelParams :: IsParamName k => [(k, Integer)] -> CostModelParams Source #

Essentially untag the association of param names to values so that CostModelInterface can make use of it.