Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- module PlutusTx.TH
- type CompiledCode = CompiledCodeIn DefaultUni DefaultFun
- data CompiledCodeIn uni fun a
- getPlc ∷ (Closed uni, uni `Everywhere` Flat, Flat fun) ⇒ CompiledCodeIn uni fun a → Program NamedDeBruijn uni fun SrcSpans
- getPlcNoAnn ∷ (Closed uni, uni `Everywhere` Flat, Flat fun) ⇒ CompiledCodeIn uni fun a → Program NamedDeBruijn uni fun ()
- getPir ∷ (Closed uni, uni `Everywhere` Flat, Flat fun) ⇒ CompiledCodeIn uni fun a → Maybe (Program TyName Name uni fun SrcSpans)
- getPirNoAnn ∷ (Closed uni, uni `Everywhere` Flat, Flat fun) ⇒ CompiledCodeIn uni fun a → Maybe (Program TyName Name uni fun ())
- applyCode ∷ (Closed uni, uni `Everywhere` Flat, Flat fun, Pretty fun, Everywhere uni PrettyConst, PrettyBy RenderContext (SomeTypeIn uni)) ⇒ CompiledCodeIn uni fun (a → b) → CompiledCodeIn uni fun a → Either String (CompiledCodeIn uni fun b)
- unsafeApplyCode ∷ (Closed uni, uni `Everywhere` Flat, Flat fun, Pretty fun, Everywhere uni PrettyConst, PrettyBy RenderContext (SomeTypeIn uni)) ⇒ CompiledCodeIn uni fun (a → b) → CompiledCodeIn uni fun a → CompiledCodeIn uni fun b
- data BuiltinData
- data Data
- class ToData (a ∷ Type) where
- toBuiltinData ∷ a → BuiltinData
- class FromData (a ∷ Type) where
- fromBuiltinData ∷ BuiltinData → Maybe a
- class UnsafeFromData (a ∷ Type) where
- toData ∷ ToData a ⇒ a → Data
- fromData ∷ FromData a ⇒ Data → Maybe a
- builtinDataToData ∷ BuiltinData → Data
- dataToBuiltinData ∷ Data → BuiltinData
- unstableMakeIsData ∷ Name → Q [Dec]
- makeIsDataIndexed ∷ Name → [(Name, Int)] → Q [Dec]
- makeIsDataSchemaIndexed ∷ Name → [(Name, Natural)] → Q [InstanceDec]
- class Lift uni a
- class Typeable uni (a ∷ k)
- makeLift ∷ Name → Q [Dec]
- safeLiftCode ∷ (Lift uni a, AsTypeError e (Term TyName Name uni fun ()) uni fun (Provenance ()), GEq uni, AsTypeErrorExt e uni (Provenance ()), AsFreeVariableError e, AsError e uni fun (Provenance ()), MonadError e m, MonadQuote m, Typecheckable uni fun, PrettyUni uni, Pretty fun, Default (CostingPart uni fun), Default (BuiltinsInfo uni fun), Default (RewriteRules uni fun), Hashable fun) ⇒ Version → a → m (CompiledCodeIn uni fun a)
- liftCode ∷ (Lift uni a, GEq uni, ThrowableBuiltins uni fun, Typecheckable uni fun, Default (CostingPart uni fun), Default (BuiltinsInfo uni fun), Default (RewriteRules uni fun), Hashable fun) ⇒ Version → a → CompiledCodeIn uni fun a
- liftCodeDef ∷ (Lift uni a, GEq uni, ThrowableBuiltins uni fun, Typecheckable uni fun, Default (CostingPart uni fun), Default (BuiltinsInfo uni fun), Default (RewriteRules uni fun), Hashable fun) ⇒ a → CompiledCodeIn uni fun a
Documentation
module PlutusTx.TH
type CompiledCode = CompiledCodeIn DefaultUni DefaultFun Source #
CompiledCodeIn
instantiated with default built-in types and functions.
data CompiledCodeIn uni fun a Source #
A compiled Plutus Tx program. The last type parameter indicates the type of the Haskell expression that was compiled, and hence the type of the compiled code.
Note: the compiled PLC program does *not* have normalized types, if you want to put it on the chain you must normalize the types first.
getPlc ∷ (Closed uni, uni `Everywhere` Flat, Flat fun) ⇒ CompiledCodeIn uni fun a → Program NamedDeBruijn uni fun SrcSpans Source #
Get the actual Plutus Core program out of a CompiledCodeIn
.
getPlcNoAnn ∷ (Closed uni, uni `Everywhere` Flat, Flat fun) ⇒ CompiledCodeIn uni fun a → Program NamedDeBruijn uni fun () Source #
getPir ∷ (Closed uni, uni `Everywhere` Flat, Flat fun) ⇒ CompiledCodeIn uni fun a → Maybe (Program TyName Name uni fun SrcSpans) Source #
Get the Plutus IR program, if there is one, out of a CompiledCodeIn
.
getPirNoAnn ∷ (Closed uni, uni `Everywhere` Flat, Flat fun) ⇒ CompiledCodeIn uni fun a → Maybe (Program TyName Name uni fun ()) Source #
applyCode ∷ (Closed uni, uni `Everywhere` Flat, Flat fun, Pretty fun, Everywhere uni PrettyConst, PrettyBy RenderContext (SomeTypeIn uni)) ⇒ CompiledCodeIn uni fun (a → b) → CompiledCodeIn uni fun a → Either String (CompiledCodeIn uni fun b) Source #
Apply a compiled function to a compiled argument. Will fail if the versions don't match.
unsafeApplyCode ∷ (Closed uni, uni `Everywhere` Flat, Flat fun, Pretty fun, Everywhere uni PrettyConst, PrettyBy RenderContext (SomeTypeIn uni)) ⇒ CompiledCodeIn uni fun (a → b) → CompiledCodeIn uni fun a → CompiledCodeIn uni fun b Source #
Apply a compiled function to a compiled argument. Will throw if the versions don't match, should only be used in non-production code.
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 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
class ToData (a ∷ Type) where Source #
A typeclass for types that can be converted to and from BuiltinData
.
toBuiltinData ∷ a → BuiltinData Source #
Convert a value to BuiltinData
.
Instances
ToData Void Source # | |
Defined in PlutusTx.IsData.Class | |
ToData BuiltinBLS12_381_G1_Element Source # | For the BLS12-381 G1 and G2 types we use the |
Defined in PlutusTx.IsData.Class | |
ToData BuiltinBLS12_381_G2_Element Source # | |
Defined in PlutusTx.IsData.Class | |
(TypeError ('Text "toBuiltinData is not supported for BuiltinBLS12_381_MlResult") ∷ Constraint) ⇒ ToData BuiltinBLS12_381_MlResult Source # | 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 | |
ToData BuiltinByteString Source # | |
Defined in PlutusTx.IsData.Class | |
ToData BuiltinData Source # | |
Defined in PlutusTx.IsData.Class | |
ToData Rational Source # | |
Defined in PlutusTx.Ratio | |
ToData Sqrt Source # | |
Defined in PlutusTx.Sqrt | |
ToData Integer Source # | |
Defined in PlutusTx.IsData.Class | |
ToData () Source # | |
Defined in PlutusTx.IsData.Instances toBuiltinData ∷ () → BuiltinData Source # | |
ToData Bool Source # | |
Defined in PlutusTx.IsData.Instances | |
(TypeError ('Text "Int is not supported, use Integer instead") ∷ Constraint) ⇒ ToData Int Source # | |
Defined in PlutusTx.IsData.Class | |
ToData a ⇒ ToData (Maybe a) Source # | |
Defined in PlutusTx.IsData.Instances toBuiltinData ∷ Maybe a → BuiltinData Source # | |
ToData a ⇒ ToData [a] Source # | |
Defined in PlutusTx.IsData.Class toBuiltinData ∷ [a] → BuiltinData Source # | |
(ToData a, ToData b) ⇒ ToData (Either a b) Source # | |
Defined in PlutusTx.IsData.Instances toBuiltinData ∷ Either a b → BuiltinData Source # | |
(ToData k, ToData v) ⇒ ToData (Map k v) Source # | Hand-written instances to use the underlying |
Defined in PlutusTx.AssocMap toBuiltinData ∷ Map k v → BuiltinData Source # | |
ToData (Map k a) Source # | |
Defined in PlutusTx.Data.AssocMap toBuiltinData ∷ Map k a → BuiltinData Source # | |
(ToData a, ToData b) ⇒ ToData (These a b) Source # | |
Defined in PlutusTx.IsData.Instances toBuiltinData ∷ These a b → BuiltinData Source # | |
(ToData a, ToData b) ⇒ ToData (a, b) Source # | |
Defined in PlutusTx.IsData.Instances toBuiltinData ∷ (a, b) → BuiltinData Source # | |
(ToData a, ToData b, ToData c) ⇒ ToData (a, b, c) Source # | |
Defined in PlutusTx.IsData.Instances toBuiltinData ∷ (a, b, c) → BuiltinData Source # | |
(ToData a, ToData b, ToData c, ToData d) ⇒ ToData (a, b, c, d) Source # | |
Defined in PlutusTx.IsData.Instances toBuiltinData ∷ (a, b, c, d) → BuiltinData Source # |
class FromData (a ∷ Type) where Source #
fromBuiltinData ∷ BuiltinData → Maybe a Source #
Convert a value from BuiltinData
, returning Nothing
if this fails.
Instances
class UnsafeFromData (a ∷ Type) 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!
This is a simple type without any validation, use with caution.
Instances
builtinDataToData ∷ BuiltinData → Data Source #
Convert a BuiltinData
into a Data
. Only works off-chain.
dataToBuiltinData ∷ Data → BuiltinData Source #
Convert a Data
into a BuiltinData
. Only works off-chain.
unstableMakeIsData ∷ Name → Q [Dec] Source #
Generate a FromData
and a ToData
instance for a type.
This may not be stable in the face of constructor additions,
renamings, etc. Use makeIsDataIndexed
if you need stability.
makeIsDataIndexed ∷ Name → [(Name, Int)] → Q [Dec] Source #
Generate a ToData
, 'FromData and a UnsafeFromData
instances for a type,
using an explicit mapping of constructor names to indices.
Use this for types where you need to keep the representation stable.
makeIsDataSchemaIndexed ∷ Name → [(Name, Natural)] → Q [InstanceDec] Source #
Generate a ToData
, FromData
, UnsafeFromData
, HasBlueprintSchema
instances for a type,
using an explicit mapping of constructor names to indices.
Use this for types where you need to keep the representation stable.
Class for types which can be lifted into Plutus IR. Instances should be derived, do not write your own instance!
Instances
class Typeable uni (a ∷ k) Source #
Class for types which have a corresponding Plutus IR type. Instances should always be derived, do not write your own instance!
Instances
safeLiftCode ∷ (Lift uni a, AsTypeError e (Term TyName Name uni fun ()) uni fun (Provenance ()), GEq uni, AsTypeErrorExt e uni (Provenance ()), AsFreeVariableError e, AsError e uni fun (Provenance ()), MonadError e m, MonadQuote m, Typecheckable uni fun, PrettyUni uni, Pretty fun, Default (CostingPart uni fun), Default (BuiltinsInfo uni fun), Default (RewriteRules uni fun), Hashable fun) ⇒ Version → a → m (CompiledCodeIn uni fun a) Source #
liftCode ∷ (Lift uni a, GEq uni, ThrowableBuiltins uni fun, Typecheckable uni fun, Default (CostingPart uni fun), Default (BuiltinsInfo uni fun), Default (RewriteRules uni fun), Hashable fun) ⇒ Version → a → CompiledCodeIn uni fun a Source #
Get a Plutus Core program corresponding to the given value as a CompiledCodeIn
, throwing any errors that occur as exceptions and ignoring fresh names.
liftCodeDef ∷ (Lift uni a, GEq uni, ThrowableBuiltins uni fun, Typecheckable uni fun, Default (CostingPart uni fun), Default (BuiltinsInfo uni fun), Default (RewriteRules uni fun), Hashable fun) ⇒ a → CompiledCodeIn uni fun a Source #
Get a Plutus Core program with the default version, corresponding to the given value as a CompiledCodeIn
, throwing any errors that occur as exceptions and ignoring fresh names.