| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
PlutusLedgerApi.Data.V2
Description
The interface to Plutus V2 for the ledger.
Synopsis
- type SerialisedScript = CompiledCode a -> SerialisedScript #
Turns a program which was compiled using the 'PlutusTx' toolchain into a binary format that is understood by the network and can be stored on-chain.
serialiseUPLC :: DefaultFun () -> SerialisedScript #
Turns a program's AST (most likely manually constructed) into a binary format that is understood by the network and can be stored on-chain.
Arguments
| :: forall m. MonadError ScriptDecodeError m | |
| => MajorProtocolVersion | which major protocol version the script was submitted in. |
| -> SerialisedScript | the script to deserialise. |
| -> m ScriptForEvaluation |
The deserialization from a serialised script into a ScriptForEvaluation,
ready to be evaluated on-chain.
Called inside phase-1 validation (i.e., deserialisation error is a phase-1 error).
uncheckedDeserialiseUPLC :: SerialisedScript -> DefaultFun () #
Deserialises a SerialisedScript back into an AST. Does *not* do
ledger-language-version-specific checks like for allowable builtins.
Running scripts
Arguments
| :: MajorProtocolVersion | Which major protocol version to run the operation in |
| -> VerboseMode | Whether to produce log output |
| -> EvaluationContext | Includes the cost model to use for tallying up the execution costs |
| -> ExBudget | The resource budget which must not be exceeded during evaluation |
| -> ScriptForEvaluation | 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.
Arguments
| :: MajorProtocolVersion | Which major protocol version to run the operation in |
| -> VerboseMode | Whether to produce log output |
| -> EvaluationContext | Includes the cost model to use for tallying up the execution costs |
| -> ScriptForEvaluation | 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.
Protocol version
newtype MajorProtocolVersion #
This represents the major component of the Cardano protocol version. The ledger can only supply the major component of the protocol version, not the minor component, and Plutus should only need to care about the major component anyway. This relies on careful understanding between us and the ledger as to what this means.
Constructors
| MajorProtocolVersion | |
Fields
| |
Counts CPU units in picoseconds: maximum value for SatInt is 2^63 ps, or appproximately 106 days.
Constructors
| ExCPU Data.SatInt | |
| Num SatInt | In the |
Defined in Data.SatInt | |
fromSatInt :: Num a => SatInt -> a #
An optimized version of fromIntegral . unSatInt.
Cost model
data EvaluationContext #
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 being recomputed on every evaluation.
Different protocol versions may require different bundles of machine parameters, which allows us for
example to tweak the shape of the costing function of a builtin, so that the builtin costs less.
Currently this means that we have to create multiple DefaultMachineParameters per language
version, which we put into a cache (represented by an association list) in order to avoid costly
recomputation of machine parameters.
In order to get the appropriate DefaultMachineParameters at validation time we look it up in the
cache using a semantics variant as a key. We compute the semantics variant from the protocol
version using the stored function. Note that the semantics variant depends on the language version
too, but the latter is known statically (because each language version has its own evaluation
context), hence there's no reason to require it to be provided at runtime.
To say it differently, there's a matrix of semantics variants indexed by (LL, PV) pairs and we
cache its particular row corresponding to the statically given LL in an EvaluationContext.
The reason why we associate a DefaultMachineParameters with a semantics variant rather than a
protocol version are
- generally there are far more protocol versions than semantics variants supported by a specific language version, so we save on pointless duplication of bundles of machine parameters
- builtins don't know anything about protocol versions, only semantics variants. It is therefore more semantically precise to associate bundles of machine parameters with semantics variants than with protocol versions
Instances
Arguments
| :: (MonadError CostModelApplyError m, MonadWriter [CostModelApplyWarn] m) | |
| => [Int64] | the (updated) cost model parameters of the protocol |
| -> m EvaluationContext |
Build the EvaluationContext.
The input is a list of cost model parameters (which are integer values) passed from the ledger.
IMPORTANT: the cost model parameters MUST appear in the correct order,
matching the names in ParamName. If the parameters are
supplied in the wrong order then script cost calculations will be incorrect.
IMPORTANT: The evaluation context of every Plutus version must be recreated upon a protocol update with the updated cost model parameters.
The enumeration of all possible cost model parameter names for this language version.
IMPORTANT: The order of appearance of the data constructors here matters. DO NOT REORDER. See Note [Quotation marks in cost model parameter constructors] See Note [Cost model parameters from the ledger's point of view]
Constructors
Instances
HasFromOpaque arep a => arep -> a #Bytesnewtype LedgerBytes # Constructors
Instances
fromBytes :: ByteString -> LedgerBytes # Lift a Haskell bytestring to the Plutus abstraction CertificatesA representation of the ledger DCert. Some information is digested, and not included pattern DCertDelegRegKey :: StakingCredential -> DCert # pattern DCertDelegDeRegKey :: StakingCredential -> DCert # pattern DCertDelegDelegate :: StakingCredential -> PubKeyHash -> DCert # pattern DCertPoolRegister :: PubKeyHash -> PubKeyHash -> DCert # pattern DCertPoolRetire :: PubKeyHash -> Integer -> DCert # pattern DCertGenesis :: DCert # Credentialsdata StakingCredential # Staking credential used to assign rewards. The staking hash constructor is the The | ||||||||||||||
pattern StakingHash :: Credential -> StakingCredential #
pattern StakingPtr :: Integer -> Integer -> Integer -> StakingCredential #
data Credential #
Credentials required to unlock a transaction output.
The PubKeyCredential constructor represents the transaction that
spends this output and must be signed by the private key.
See PubKeyHash.
The ScriptCredential constructor represents the transaction that spends
this output must include the validator script and
be accepted by the validator. See ScriptHash.
Instances
| RepIsStuckError Credential :: Type -> Type) (Rep Credential))) |
pattern PubKeyCredential :: PubKeyHash -> Credential #
pattern ScriptCredential :: ScriptHash -> Credential #
Value
The Value type represents a collection of amounts of different currencies.
We can think of Value as a vector space whose dimensions are currencies.
Operations on currencies are usually implemented pointwise. That is,
we apply the operation to the quantities for each currency in turn. So
when we add two Values the resulting Value has, for each currency,
the sum of the quantities of that particular currency in the argument
Value. The effect of this is that the currencies in the Value are "independent",
and are operated on separately.
Whenever we need to get the quantity of a currency in a Value where there
is no explicit quantity of that currency in the Value, then the quantity is
taken to be zero.
There is no 'Ord Value' instance since Value is only a partial order, so compare can't
do the right thing in some cases.
newtype CurrencySymbol #
ByteString representing the currency, hashed with BLAKE2b-224.
It is empty for Ada, 28 bytes for MintingPolicyHash.
Forms an AssetClass along with TokenName.
A Value is a map from CurrencySymbol's to a map from TokenName to an Integer.
This is a simple type without any validation, use with caution. You may want to add checks for its invariants. See the Shelley ledger specification. -- editorconfig-checker-disable-file
Constructors
| CurrencySymbol | |
Fields | |
Instances
| RepIsStuckError CurrencySymbol :: Type -> Type) (Rep CurrencySymbol))) |
ByteString of a name of a token.
Shown as hex-encoded bytes.
Should be no longer than 32 bytes, empty for Ada.
Forms an AssetClass along with a CurrencySymbol.
This is a simple type without any validation, use with caution. You may want to add checks for its invariants. See the Shelley ledger specification. -- editorconfig-checker-disable-file
Constructors
| TokenName | |
Fields | |
singleton :: CurrencySymbol -> TokenName -> Integer -> Value #
Make a Value containing only the given quantity of the given currency.
unionWith :: (Integer -> Integer -> Integer) -> Value -> Value -> Value #
Combine two Value maps with the argument function.
Assumes the well-definedness of the two maps.
The CurrencySymbol of the Ada currency.
Constructors
| Lovelace | |
Fields
| |