| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
PlutusLedgerApi.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 Constructors
Credentialsdata StakingCredential # Staking credential used to assign rewards. Constructors
data Credential # Credentials required to unlock a transaction output. Constructors
Instances
ValueThe 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 Whenever we need to get the quantity of a currency in a There is no 'Ord Value' instance since newtype CurrencySymbol # ByteString representing the currency, hashed with BLAKE2b-224.
It is empty for 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. Constructors
Instances
ByteString of a name of a token.
Shown as hex-encoded bytes.
Should be no longer than 32 bytes, empty for Ada.
Forms an 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. Constructors
singleton :: CurrencySymbol -> TokenName -> Integer -> Value # Make a unionWith :: (Integer -> Integer -> Integer) -> Value -> Value -> Value # Combine two The Constructors
Time | |||||||||||||||||||||||||||||||||||||||||||||||||
Types for representing transactions
An address may contain two credentials,
the payment credential and optionally a StakingCredential.
Constructors
| Address | |
Fields
| |
newtype PubKeyHash #
The hash of a public key. This is frequently used to identify the public key, rather than the key itself. Hashed with BLAKE2b-224. 28 bytes.
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.
Constructors
| PubKeyHash | |
Fields | |
Instances
| Unroll PubKeyHash = '[PubKeyHash] |
A transaction ID, i.e. the hash of a transaction. Hashed with BLAKE2b-256. 32 byte.
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.
Constructors
| TxId | |
Fields | |
A pending transaction. This is the view as seen by validator scripts, so some details are stripped out.
Constructors
| TxInfo | |
Fields
| |
A transaction output, consisting of a target address, a value, optionally a datum/datum hash, and optionally a reference script.
Constructors
| TxOut | |
Fields
| |
A reference to a transaction output. This is a
pair of a transaction ID (TxId), and an index indicating which of the outputs
of that transaction we are referring to.
Constructors
| TxOutRef | |
Fields
| |
data OutputDatum #
The datum attached to an output: either nothing; a datum hash; or the datum itself (an "inline datum").
Constructors
| NoOutputDatum | |
| OutputDatumHash DatumHash | |
| OutputDatum Datum |
Instances
| RepIsStuckError OutputDatum :: Type -> Type) (Rep OutputDatum))) |
Intervals
An interval of as.
The interval may be either closed or open at either end, meaning that the endpoints may or may not be included in the interval.
The interval can also be unbounded on either side.
The Eq instance gives equality of the intervals, not structural equality.
There is no Enum in order to
handle non-inclusive endpoints. For this reason, it may not be safe to
use Intervals with non-inclusive endpoints on types whose Enum
instances have partial methods.
Constructors
| Interval | |
Fields
| |
from a is an Interval that includes all values that are
greater than or equal to a. In math. notation: [a,+∞]
to a is an Interval that includes all values that are
smaller than or equal to a. In math. notation: [-∞,a]
lowerBound :: a -> LowerBound a #
Construct a lower bound from a value. The resulting bound includes all values that are equal or greater than the input value.
upperBound :: a -> UpperBound a #
Construct an upper bound from a value. The resulting bound includes all values that are equal or smaller than the input value.
strictLowerBound :: a -> LowerBound a #
Construct a strict lower bound from a value. The resulting bound includes all values that are (strictly) greater than the input value.
strictUpperBound :: a -> UpperBound a #
Construct a strict upper bound from a value. The resulting bound includes all values that are (strictly) smaller than the input value.
Association maps
A Map of key-value pairs.
A Map is considered well-defined if there are no key collisions, meaning that each value
is uniquely identified by a key.
Use safeFromList to create well-defined Maps from arbitrary lists of pairs.
If cost minimisation is required, then you can use unsafeFromList but you must
be certain that the list you are converting to a Map abides by the well-definedness condition.
Most operations on Maps are definedness-preserving, meaning that for the resulting Map to be
well-defined then the input Map(s) have to also be well-defined. This is not checked explicitly
unless mentioned in the documentation.
Take care when using fromBuiltinData and unsafeFromBuiltinData, as neither function performs
deduplication of the input collection and may create invalid Maps!
Instances
| DefinitionId # | |
| (FromData k, FromData v) => FromData (Map k v) | A hand-written transformation from |
Defined in PlutusTx.AssocMap Methods fromBuiltinData :: BuiltinData -> Maybe (Map k v) # | |
| (ToData k, ToData v) => ToData (Map k v) | Hand-written instances to use the underlying |
Defined in PlutusTx.AssocMap Methods toBuiltinData :: Map k v -> BuiltinData # | |
| (UnsafeFromData k, UnsafeFromData v) => UnsafeFromData (Map k v) | A hand-written transformation from |
unsafeFromList :: [(k, v)] -> Map k v #
Unsafely create a Map from a list of pairs. This should _only_ be applied to lists which
have been checked to not contain duplicate keys, otherwise the resulting Map will contain
conflicting entries (two entries sharing the same key).
As usual, the "keys" are considered to be the first element of the pair.
Newtypes and hash types
newtype ScriptHash #
Type representing the BLAKE2b-224 hash of a script. 28 bytes.
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.
Constructors
| ScriptHash | |
Fields | |
newtype RedeemerHash #
Type representing the BLAKE2b-256 hash of a redeemer. 32 bytes.
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.
Constructors
| RedeemerHash BuiltinByteString |
Type representing the BLAKE2b-256 hash of a datum. 32 bytes.
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.
Constructors
| DatumHash BuiltinByteString |
Data
A generic "data" type.
The main constructor Constr represents a datatype value in sum-of-products
form: Constr i args represents a use of the ith constructor along with its arguments.
The other constructors are various primitives.
Constructors
| Constr DefaultUni Data) |
data BuiltinData #
A type corresponding to the Plutus Core builtin equivalent of Data.
The point of this type is to be an opaque equivalent of Data, so as to
ensure that it is only used in ways that the compiler can handle.
As such, you should use this type in your on-chain code, and in any data structures that you want to be representable on-chain.
For off-chain usage, there are conversion functions builtinDataToData and
dataToBuiltinData, but note that these will not work on-chain.
Constructors
| BuiltinData ~Data |
Instances
| BuiltinBLS12_381_G1_Element | For the BLS12-381 G1 and G2 types we use the | |||||
Defined in BuiltinBLS12_381_MlResult | We do not provide instances of any of these classes for BuiltinBLS12_381_MlResult since there is no serialisation format: we expect that values of that type will only occur as the result of on-chain computations. | |||||
Defined in PlutusTx.IsData.Class Methods toBuiltinData :: [a] -> BuiltinData # | ||||||
| (ToData k, ToData v) => ToData (Map k v) | Hand-written instances to use the underlying | |||||
Defined in PlutusTx.IsData.Class Methods fromBuiltinData :: BuiltinData -> Maybe [a] # | ||||||
| (FromData k, FromData v) => FromData (Map k v) | A hand-written transformation from | |||||
Defined in error if this fails.
This is typically much faster than When implementing this function, make sure to call This is a simple type without any validation, use with caution. Instances
unsafeFromData :: UnsafeFromData a => Data -> a # Convert a value from Note: off-chain only. dataToBuiltinData :: Data -> BuiltinData # NOT a builtin. Converts a builtinDataToData :: BuiltinData -> Data # NOT a builtin. Converts a Errorsclass Monad m => MonadError e (m :: Type -> Type) | m -> e # The strategy of combining computations that can throw exceptions by bypassing bound functions from the point an exception is thrown to the point that it is handled. Is parameterized over the type of error information and
the monad type constructor.
It is common to use Minimal complete definition BuiltinFailure logs. This is to compensate for the historical lack of error message content in operational errors (structural ones don't have this problem) in our evaluators (the CK and CEK machines). It would be better to fix the underlying issue and allow operational evaluation errors to carry some form of content, but for now we just fix the symptom in order for the end user to see the error message that they are supposed to see. The fix even makes some sense: what we do here is we emulate logging when the thrown unlifting error is an operational one, i.e. this is similar to what some builtins do manually (like when a crypto builtin fails and puts info about the failure into the logs). | ||||||
Defined in FreeVariableError | An error in the pre-evaluation step of converting from de-Bruijn indices | |||||
| CodecError !ScriptDecodeError | A deserialisation error 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 | |||||
| InvalidReturnValue | The script evaluated to a value that is not a valid return value. | |||||
Instances
| DeserialiseFailureInfo | an error from the underlying CBOR/serialise library |
| RemainderError !ByteString | Script was successfully parsed, but more (runaway) bytes encountered after script's position |
| LedgerLanguageNotAvailableError | the plutus version of the given script is not enabled yet |
Fields
| |
| PlutusCoreLanguageNotAvailableError | |
Fields
| |