Safe Haskell | None |
---|---|
Language | Haskell2010 |
The interface to Plutus V1 for the ledger.
Synopsis
- type SerializedScript = ShortByteString
- data Script
- fromCompiledCode :: CompiledCode a -> Script
- isScriptWellFormed :: ProtocolVersion -> SerializedScript -> Bool
- evaluateScriptRestricting :: ProtocolVersion -> VerboseMode -> EvaluationContext -> ExBudget -> SerializedScript -> [ Data ] -> ( LogOutput , Either EvaluationError ExBudget )
- evaluateScriptCounting :: ProtocolVersion -> VerboseMode -> EvaluationContext -> SerializedScript -> [ Data ] -> ( LogOutput , Either EvaluationError ExBudget )
- data ProtocolVersion = ProtocolVersion { }
- data VerboseMode
- type LogOutput = [ Text ]
- data ExBudget = ExBudget { }
- newtype ExCPU = ExCPU CostingInteger
- newtype ExMemory = ExMemory CostingInteger
- data SatInt
- data EvaluationContext
- mkEvaluationContext :: MonadError CostModelApplyError m => CostModelParams -> m EvaluationContext
- data CostModelApplyError
- type CostModelParams = Map Text Integer
- assertWellFormedCostModelParams :: MonadError CostModelApplyError m => CostModelParams -> m ()
- costModelParamNames :: Set Text
- data ScriptContext = ScriptContext { }
- data ScriptPurpose
- data BuiltinByteString
- toBuiltin :: ToBuiltin a arep => a -> arep
- fromBuiltin :: FromBuiltin arep a => arep -> a
- newtype LedgerBytes = LedgerBytes { }
- fromBytes :: ByteString -> LedgerBytes
- data DCert
- data StakingCredential
- data Credential
- newtype Value = Value { }
- newtype CurrencySymbol = CurrencySymbol { }
- newtype TokenName = TokenName { }
- singleton :: CurrencySymbol -> TokenName -> Integer -> Value
- unionWith :: ( Integer -> Integer -> Integer ) -> Value -> Value -> Value
- adaSymbol :: CurrencySymbol
- adaToken :: TokenName
- newtype POSIXTime = POSIXTime { }
- type POSIXTimeRange = Interval POSIXTime
- data Address = Address { }
- newtype PubKeyHash = PubKeyHash { }
- newtype TxId = TxId { }
-
data
TxInfo
=
TxInfo
{
- txInfoInputs :: [ TxInInfo ]
- txInfoOutputs :: [ TxOut ]
- txInfoFee :: Value
- txInfoMint :: Value
- txInfoDCert :: [ DCert ]
- txInfoWdrl :: [( StakingCredential , Integer )]
- txInfoValidRange :: POSIXTimeRange
- txInfoSignatories :: [ PubKeyHash ]
- txInfoData :: [( DatumHash , Datum )]
- txInfoId :: TxId
- data TxOut = TxOut { }
-
data
TxOutRef
=
TxOutRef
{
- txOutRefId :: TxId
- txOutRefIdx :: Integer
- data TxInInfo = TxInInfo { }
-
data
Interval
a =
Interval
{
- ivFrom :: LowerBound a
- ivTo :: UpperBound a
- data Extended a
- type Closure = Bool
- data UpperBound a = UpperBound ( Extended a) Closure
- data LowerBound a = LowerBound ( Extended a) Closure
- always :: Interval a
- from :: a -> Interval a
- to :: a -> Interval a
- lowerBound :: a -> LowerBound a
- upperBound :: a -> UpperBound a
- strictLowerBound :: a -> LowerBound a
- strictUpperBound :: a -> UpperBound a
- newtype Validator = Validator { }
- mkValidatorScript :: CompiledCode ( BuiltinData -> BuiltinData -> BuiltinData -> ()) -> Validator
- unValidatorScript :: Validator -> Script
- newtype ValidatorHash = ValidatorHash BuiltinByteString
- newtype MintingPolicy = MintingPolicy { }
- mkMintingPolicyScript :: CompiledCode ( BuiltinData -> BuiltinData -> ()) -> MintingPolicy
- unMintingPolicyScript :: MintingPolicy -> Script
- newtype MintingPolicyHash = MintingPolicyHash BuiltinByteString
- newtype StakeValidator = StakeValidator { }
- mkStakeValidatorScript :: CompiledCode ( BuiltinData -> BuiltinData -> ()) -> StakeValidator
- unStakeValidatorScript :: StakeValidator -> Script
- newtype StakeValidatorHash = StakeValidatorHash BuiltinByteString
- newtype Redeemer = Redeemer { }
- newtype RedeemerHash = RedeemerHash BuiltinByteString
- newtype Datum = Datum { }
- newtype DatumHash = DatumHash BuiltinByteString
- data Data
- data BuiltinData = BuiltinData Data
-
class
ToData
a
where
- toBuiltinData :: a -> BuiltinData
-
class
FromData
a
where
- fromBuiltinData :: BuiltinData -> Maybe a
-
class
UnsafeFromData
a
where
- unsafeFromBuiltinData :: BuiltinData -> a
- toData :: ToData a => a -> Data
- fromData :: FromData a => Data -> Maybe a
- dataToBuiltinData :: Data -> BuiltinData
- builtinDataToData :: BuiltinData -> Data
- data EvaluationError
Scripts
type SerializedScript = ShortByteString Source #
Scripts to the ledger are serialised bytestrings.
A script on the chain. This is an opaque type as far as the chain is concerned.
Instances
Eq Script Source # |
Note [Using Flat inside CBOR instance of 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 a Serialise instance for Script, which is a wrapper over Programs serialised with Flat. The instance will see programs as an opaque ByteString, which is the result of encoding programs using Flat. 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. |
Ord Script Source # | |
Show Script Source # | |
Generic Script Source # | |
NFData Script Source # | |
Defined in Plutus.V1.Ledger.Scripts |
|
Serialise Script Source # | |
type Rep Script Source # | |
Defined in Plutus.V1.Ledger.Scripts
type
Rep
Script
=
D1
('
MetaData
"Script" "Plutus.V1.Ledger.Scripts" "plutus-ledger-api-1.0.0.1-GlUFhIIE0LJGuJDDdHh5lQ" '
True
) (
C1
('
MetaCons
"Script" '
PrefixI
'
True
) (
S1
('
MetaSel
('
Just
"unScript") '
NoSourceUnpackedness
'
NoSourceStrictness
'
DecidedLazy
) (
Rec0
(
Program
DeBruijn
DefaultUni
DefaultFun
()))))
|
fromCompiledCode :: CompiledCode a -> Script Source #
Turn a
CompiledCode
(usually produced by
compile
) into a
Script
for use with this package.
Validating scripts
isScriptWellFormed :: ProtocolVersion -> SerializedScript -> Bool 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.
Running scripts
evaluateScriptRestricting Source #
:: 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 |
-> SerializedScript |
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.
evaluateScriptCounting Source #
:: 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 |
-> SerializedScript |
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
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
Eq ProtocolVersion Source # | |
Defined in Plutus.ApiCommon (==) :: ProtocolVersion -> ProtocolVersion -> Bool Source # (/=) :: ProtocolVersion -> ProtocolVersion -> Bool Source # |
|
Ord ProtocolVersion Source # | |
Defined in Plutus.ApiCommon compare :: ProtocolVersion -> ProtocolVersion -> Ordering Source # (<) :: ProtocolVersion -> ProtocolVersion -> Bool Source # (<=) :: ProtocolVersion -> ProtocolVersion -> Bool Source # (>) :: ProtocolVersion -> ProtocolVersion -> Bool Source # (>=) :: ProtocolVersion -> ProtocolVersion -> Bool Source # max :: ProtocolVersion -> ProtocolVersion -> ProtocolVersion Source # min :: ProtocolVersion -> ProtocolVersion -> ProtocolVersion Source # |
|
Show ProtocolVersion Source # | |
Defined in Plutus.ApiCommon |
|
Pretty ProtocolVersion Source # | |
Defined in Plutus.ApiCommon pretty :: ProtocolVersion -> Doc ann Source # prettyList :: [ ProtocolVersion ] -> Doc ann Source # |
Verbose mode and log output
data VerboseMode Source #
A simple toggle indicating whether or not we should produce logs.
Instances
Eq VerboseMode Source # | |
Defined in Plutus.ApiCommon (==) :: VerboseMode -> VerboseMode -> Bool Source # (/=) :: VerboseMode -> VerboseMode -> Bool Source # |
Costing-related types
Instances
Eq ExBudget | |
Show ExBudget | |
Generic ExBudget | |
Semigroup ExBudget | |
Monoid ExBudget | |
ToJSON ExBudget | |
FromJSON ExBudget | |
NFData ExBudget | |
Defined in PlutusCore.Evaluation.Machine.ExBudget |
|
NoThunks ExBudget | |
Pretty ExBudget | |
Lift ExBudget | |
PrettyBy config ExBudget | |
type Rep ExBudget | |
Defined in PlutusCore.Evaluation.Machine.ExBudget
type
Rep
ExBudget
=
D1
('
MetaData
"ExBudget" "PlutusCore.Evaluation.Machine.ExBudget" "plutus-core-1.0.0.1-76bWF9ZEWyb4eDyjHx0kCS" '
False
) (
C1
('
MetaCons
"ExBudget" '
PrefixI
'
True
) (
S1
('
MetaSel
('
Just
"exBudgetCPU") '
NoSourceUnpackedness
'
NoSourceStrictness
'
DecidedUnpack
) (
Rec0
ExCPU
)
:*:
S1
('
MetaSel
('
Just
"exBudgetMemory") '
NoSourceUnpackedness
'
NoSourceStrictness
'
DecidedUnpack
) (
Rec0
ExMemory
)))
|
Counts CPU units in picoseconds: maximum value for SatInt is 2^63 ps, or appproximately 106 days.
Instances
Eq ExCPU | |
Num ExCPU | |
Defined in PlutusCore.Evaluation.Machine.ExMemory |
|
Ord ExCPU | |
Defined in PlutusCore.Evaluation.Machine.ExMemory |
|
Show ExCPU | |
Generic ExCPU | |
Semigroup ExCPU | |
Monoid ExCPU | |
ToJSON ExCPU | |
FromJSON ExCPU | |
NFData ExCPU | |
Defined in PlutusCore.Evaluation.Machine.ExMemory |
|
NoThunks ExCPU | |
Pretty ExCPU | |
Lift ExCPU | |
PrettyBy config ExCPU | |
type Rep ExCPU | |
Defined in PlutusCore.Evaluation.Machine.ExMemory
type
Rep
ExCPU
=
D1
('
MetaData
"ExCPU" "PlutusCore.Evaluation.Machine.ExMemory" "plutus-core-1.0.0.1-76bWF9ZEWyb4eDyjHx0kCS" '
True
) (
C1
('
MetaCons
"ExCPU" '
PrefixI
'
False
) (
S1
('
MetaSel
('
Nothing
::
Maybe
Symbol
) '
NoSourceUnpackedness
'
NoSourceStrictness
'
DecidedLazy
) (
Rec0
CostingInteger
)))
|
Counts size in machine words.
Instances
Instances
Cost model
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 Plutus.ApiCommon from :: EvaluationContext -> Rep EvaluationContext x Source # to :: Rep EvaluationContext x -> EvaluationContext Source # |
|
NFData EvaluationContext Source # | |
Defined in Plutus.ApiCommon rnf :: EvaluationContext -> () Source # |
|
NoThunks EvaluationContext Source # | |
Defined in Plutus.ApiCommon |
|
type Rep EvaluationContext Source # | |
Defined in Plutus.ApiCommon
type
Rep
EvaluationContext
=
D1
('
MetaData
"EvaluationContext" "Plutus.ApiCommon" "plutus-ledger-api-1.0.0.1-GlUFhIIE0LJGuJDDdHh5lQ" '
False
) (
C1
('
MetaCons
"EvaluationContext" '
PrefixI
'
True
) (
S1
('
MetaSel
('
Just
"machineParametersImmediate") '
NoSourceUnpackedness
'
NoSourceStrictness
'
DecidedStrict
) (
Rec0
DefaultMachineParameters
)
:*:
S1
('
MetaSel
('
Just
"machineParametersDeferred") '
NoSourceUnpackedness
'
NoSourceStrictness
'
DecidedStrict
) (
Rec0
DefaultMachineParameters
)))
|
mkEvaluationContext :: MonadError CostModelApplyError m => CostModelParams -> m EvaluationContext Source #
Build the
EvaluationContext
.
The input is a
Map
of strings to cost integer values (aka
CostModelParams
,
CostModel
)
See Note [Inlining meanings of builtins].
data CostModelApplyError Source #
The type of errors that
applyParams
can throw.
CMUnknownParamError Text |
a costmodel parameter with the give name does not exist in the costmodel to be applied upon |
CMInternalReadError |
internal error when we are transforming the applyParams' input to json (should not happen) |
CMInternalWriteError String |
internal error when we are transforming the applied params from json with given jsonstring error (should not happen) |
Instances
Show CostModelApplyError | |
|
|
Exception CostModelApplyError | |
Pretty CostModelApplyError | |
Defined in PlutusCore.Evaluation.Machine.CostModelInterface pretty :: CostModelApplyError -> Doc ann Source # prettyList :: [ CostModelApplyError ] -> Doc ann Source # |
assertWellFormedCostModelParams :: MonadError CostModelApplyError m => CostModelParams -> m () Source #
Comparably expensive to
mkEvaluationContext
, so it should only be used sparingly.
costModelParamNames :: Set Text Source #
The set of valid names that a cost model parameter can take for this language version.
It is used for the deserialization of
CostModelParams
.
Context types
data ScriptContext Source #
Instances
data ScriptPurpose Source #
Purpose of the script that is currently running
Instances
Supporting types used in the context types
ByteStrings
data BuiltinByteString Source #
An opaque type representing Plutus Core ByteStrings.
Instances
fromBuiltin :: FromBuiltin arep a => arep -> a Source #
Bytes
newtype LedgerBytes Source #
Instances
fromBytes :: ByteString -> LedgerBytes Source #
Certificates
A representation of the ledger DCert. Some information is digested, and not included
DCertDelegRegKey StakingCredential | |
DCertDelegDeRegKey StakingCredential | |
DCertDelegDelegate | |
|
|
DCertPoolRegister |
A digest of the PoolParams |
|
|
DCertPoolRetire PubKeyHash Integer |
The retiremant certificate and the Epoch N |
DCertGenesis |
A really terse Digest |
DCertMir |
Another really terse Digest |
Instances
Credentials
data StakingCredential Source #
Staking credential used to assign rewards
Instances
data Credential Source #
Credential required to unlock a transaction output
PubKeyCredential PubKeyHash |
The transaction that spends this output must be signed by the private key |
ScriptCredential ValidatorHash |
The transaction that spends this output must include the validator script and be accepted by the validator. |
Instances
Value
A cryptocurrency value. This is a map from
CurrencySymbol
s to a
quantity of that currency.
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
Value
s 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.
See note [Currencies] for more details.
Instances
newtype CurrencySymbol Source #
Instances
ByteString of a name of a token, shown as UTF-8 string when possible
Instances
singleton :: CurrencySymbol -> TokenName -> Integer -> Value Source #
Make a
Value
containing only the given quantity of the given currency.
adaSymbol :: CurrencySymbol Source #
The
CurrencySymbol
of the
Ada
currency.
Time
POSIX time is measured as the number of milliseconds since 1970-01-01T00:00:00Z
Instances
Types for representing transactions
Address with two kinds of credentials, normal and staking.
Instances
newtype PubKeyHash Source #
The hash of a public key. This is frequently used to identify the public key, rather than the key itself.
Instances
A transaction ID, using a SHA256 hash as the transaction id.
Instances
A pending transaction. This is the view as seen by validator scripts, so some details are stripped out.
TxInfo | |
|
Instances
A transaction output, consisting of a target address, a value, and optionally a datum hash.
Instances
A reference to a transaction output. This is a pair of a transaction reference, and an index indicating which of the outputs of that transaction we are referring to.
TxOutRef | |
|
Instances
An input of a pending transaction.
Instances
Intervals
An interval of
a
s.
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.
Interval | |
|
Instances
A set extended with a positive and negative infinity.
Instances
data UpperBound a Source #
The upper bound of an interval.
UpperBound ( Extended a) Closure |
Instances
data LowerBound a Source #
The lower bound of an interval.
LowerBound ( Extended a) Closure |
Instances
from :: a -> Interval a Source #
from a
is an
Interval
that includes all values that are
greater than or equal to
a
.
to :: a -> Interval a Source #
to a
is an
Interval
that includes all values that are
smaller than or equal to
a
.
lowerBound :: a -> LowerBound a Source #
upperBound :: a -> UpperBound a Source #
strictLowerBound :: a -> LowerBound a Source #
strictUpperBound :: a -> UpperBound a Source #
Newtypes for script/datum types and hash types
Instances
Eq Validator Source # | |
Ord Validator Source # | |
Defined in Plutus.V1.Ledger.Scripts |
|
Show Validator Source # | |
Generic Validator Source # | |
NFData Validator Source # | |
Defined in Plutus.V1.Ledger.Scripts |
|
Pretty Validator Source # | |
Serialise Validator Source # | |
type Rep Validator Source # | |
Defined in Plutus.V1.Ledger.Scripts
type
Rep
Validator
=
D1
('
MetaData
"Validator" "Plutus.V1.Ledger.Scripts" "plutus-ledger-api-1.0.0.1-GlUFhIIE0LJGuJDDdHh5lQ" '
True
) (
C1
('
MetaCons
"Validator" '
PrefixI
'
True
) (
S1
('
MetaSel
('
Just
"getValidator") '
NoSourceUnpackedness
'
NoSourceStrictness
'
DecidedLazy
) (
Rec0
Script
)))
|
mkValidatorScript :: CompiledCode ( BuiltinData -> BuiltinData -> BuiltinData -> ()) -> Validator Source #
unValidatorScript :: Validator -> Script Source #
newtype ValidatorHash Source #
Script runtime representation of a
Digest SHA256
.
Instances
newtype MintingPolicy Source #
MintingPolicy
is a wrapper around
Script
s which are used as validators for minting constraints.
Instances
mkMintingPolicyScript :: CompiledCode ( BuiltinData -> BuiltinData -> ()) -> MintingPolicy Source #
newtype MintingPolicyHash Source #
Script runtime representation of a
Digest SHA256
.
Instances
newtype StakeValidator Source #
StakeValidator
is a wrapper around
Script
s which are used as validators for withdrawals and stake address certificates.
Instances
mkStakeValidatorScript :: CompiledCode ( BuiltinData -> BuiltinData -> ()) -> StakeValidator Source #
newtype StakeValidatorHash Source #
Script runtime representation of a
Digest SHA256
.
Instances
Redeemer
is a wrapper around
Data
values that are used as redeemers in transaction inputs.
Instances
newtype RedeemerHash Source #
Script runtime representation of a
Digest SHA256
.
Instances
Datum
is a wrapper around
Data
values which are used as data in transaction outputs.
Instances
Script runtime representation of a
Digest SHA256
.
Instances
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
i
th constructor along with its arguments.
The other constructors are various primitives.
Instances
data BuiltinData Source #
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.
Instances
A typeclass for types that can be converted to and from
BuiltinData
.
toBuiltinData :: a -> BuiltinData Source #
Convert a value to
BuiltinData
.
Instances
class FromData a where Source #
fromBuiltinData :: BuiltinData -> Maybe a Source #
Convert a value from
BuiltinData
, returning
Nothing
if this fails.
Instances
class UnsafeFromData a where Source #
unsafeFromBuiltinData :: BuiltinData -> a Source #
Convert a value from
BuiltinData
, calling
error
if this fails.
This is typically much faster than
fromBuiltinData
.
When implementing this function, make sure to call
unsafeFromBuiltinData
rather than
fromBuiltinData
when converting substructures!
Instances
dataToBuiltinData :: Data -> BuiltinData Source #
Convert a
Data
into a
BuiltinData
. Only works off-chain.
builtinDataToData :: BuiltinData -> Data Source #
Convert a
BuiltinData
into a
Data
. Only works off-chain.
Errors
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 DeserialiseFailure |
A serialisation 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
Eq EvaluationError Source # | |
Defined in Plutus.ApiCommon (==) :: EvaluationError -> EvaluationError -> Bool Source # (/=) :: EvaluationError -> EvaluationError -> Bool Source # |
|
Show EvaluationError Source # | |
Defined in Plutus.ApiCommon |
|
Pretty EvaluationError Source # | |
Defined in Plutus.ApiCommon pretty :: EvaluationError -> Doc ann Source # prettyList :: [ EvaluationError ] -> Doc ann Source # |