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
- unsafeFromBuiltinData :: BuiltinData -> a
- 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
Instances
Data Data | |
Defined in PlutusCore.Data gfoldl :: (forall d b. Data0 d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Data -> c Data Source # gunfold :: (forall b r. Data0 b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Data Source # toConstr :: Data -> Constr Source # dataTypeOf :: Data -> DataType Source # dataCast1 :: Typeable t => (forall d. Data0 d => c (t d)) -> Maybe (c Data) Source # dataCast2 :: Typeable t => (forall d e. (Data0 d, Data0 e) => c (t d e)) -> Maybe (c Data) Source # gmapT :: (forall b. Data0 b => b -> b) -> Data -> Data Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data0 d => d -> r') -> Data -> r Source # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data0 d => d -> r') -> Data -> r Source # gmapQ :: (forall d. Data0 d => d -> u) -> Data -> [u] Source # gmapQi :: Int -> (forall d. Data0 d => d -> u) -> Data -> u Source # gmapM :: Monad m => (forall d. Data0 d => d -> m d) -> Data -> m Data Source # gmapMp :: MonadPlus m => (forall d. Data0 d => d -> m d) -> Data -> m Data Source # gmapMo :: MonadPlus m => (forall d. Data0 d => d -> m d) -> Data -> m Data Source # | |
Generic Data | |
Read Data | |
Show Data | |
NFData Data | |
Defined in PlutusCore.Data | |
Eq Data | |
Ord Data | |
Hashable Data | |
Defined in PlutusCore.Data | |
NoThunks Data | |
HasToBuiltin Data Source # | |
Pretty Data | |
Defined in PlutusCore.Data prettyList :: [Data] -> Doc ann | |
Serialise Data | |
Defined in PlutusCore.Data encodeList :: [Data] -> Encoding decodeList :: Decoder s [Data] | |
PrettyBy ConstConfig Data | |
Defined in PlutusCore.Pretty.PrettyConst prettyBy :: ConstConfig -> Data -> Doc ann prettyListBy :: ConstConfig -> [Data] -> Doc ann | |
KnownBuiltinTypeIn DefaultUni term Data => MakeKnownIn DefaultUni term Data | |
Defined in PlutusCore.Default.Universe | |
KnownBuiltinTypeIn DefaultUni term Data => ReadKnownIn DefaultUni term Data | |
Defined in PlutusCore.Default.Universe | |
Contains DefaultUni Data | |
Defined in PlutusCore.Default.Universe | |
KnownBuiltinTypeAst tyname DefaultUni Data => KnownTypeAst tyname DefaultUni Data | |
type Rep Data | |
Defined in PlutusCore.Data type Rep Data = D1 ('MetaData "Data" "PlutusCore.Data" "plutus-core-1.36.0.0-7ehJj5tIPqoJIiiivXkX9N" 'False) ((C1 ('MetaCons "Constr" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Integer) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Data])) :+: C1 ('MetaCons "Map" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [(Data, Data)]))) :+: (C1 ('MetaCons "List" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Data])) :+: (C1 ('MetaCons "I" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Integer)) :+: C1 ('MetaCons "B" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString))))) | |
type ToBuiltin Data Source # | |
Defined in PlutusTx.Builtins.HasBuiltin | |
type IsBuiltin DefaultUni Data | |
Defined in PlutusCore.Default.Universe | |
type ToHoles DefaultUni Data | |
Defined in PlutusCore.Default.Universe | |
type ToBinds DefaultUni acc Data | |
Defined in PlutusCore.Default.Universe |
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 toBuiltinData :: Void -> BuiltinData Source # | |
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 toBuiltinData :: Rational -> BuiltinData Source # | |
ToData Sqrt Source # | |
Defined in PlutusTx.Sqrt toBuiltinData :: Sqrt -> BuiltinData Source # | |
ToData Integer Source # | |
Defined in PlutusTx.IsData.Class toBuiltinData :: Integer -> BuiltinData Source # | |
ToData () Source # | |
Defined in PlutusTx.IsData.Instances toBuiltinData :: () -> BuiltinData Source # | |
ToData Bool Source # | |
Defined in PlutusTx.IsData.Instances toBuiltinData :: Bool -> BuiltinData Source # | |
(TypeError ('Text "Int is not supported, use Integer instead") :: Constraint) => ToData Int Source # | |
Defined in PlutusTx.IsData.Class toBuiltinData :: Int -> BuiltinData Source # | |
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
Lift DefaultUni Rational Source # | |
Lift DefaultUni Sqrt Source # | |
Lift DefaultUni () Source # | |
Defined in PlutusTx.Lift.Instances | |
Lift DefaultUni Bool Source # | |
HasTermLevel uni Element => Lift uni BuiltinBLS12_381_G1_Element Source # | |
Defined in PlutusTx.Lift.Class lift :: BuiltinBLS12_381_G1_Element -> RTCompile uni fun (Term TyName Name uni fun ()) Source # | |
HasTermLevel uni Element => Lift uni BuiltinBLS12_381_G2_Element Source # | |
Defined in PlutusTx.Lift.Class lift :: BuiltinBLS12_381_G2_Element -> RTCompile uni fun (Term TyName Name uni fun ()) Source # | |
HasTermLevel uni MlResult => Lift uni BuiltinBLS12_381_MlResult Source # | |
Defined in PlutusTx.Lift.Class lift :: BuiltinBLS12_381_MlResult -> RTCompile uni fun (Term TyName Name uni fun ()) Source # | |
HasTermLevel uni Bool => Lift uni BuiltinBool Source # | |
Defined in PlutusTx.Lift.Class lift :: BuiltinBool -> RTCompile uni fun (Term TyName Name uni fun ()) Source # | |
HasTermLevel uni ByteString => Lift uni BuiltinByteString Source # | |
Defined in PlutusTx.Lift.Class lift :: BuiltinByteString -> RTCompile uni fun (Term TyName Name uni fun ()) Source # | |
HasTermLevel uni Data => Lift uni BuiltinData Source # | |
Defined in PlutusTx.Lift.Class lift :: BuiltinData -> RTCompile uni fun (Term TyName Name uni fun ()) Source # | |
HasTermLevel uni Integer => Lift uni BuiltinInteger Source # | |
Defined in PlutusTx.Lift.Class lift :: BuiltinInteger -> RTCompile uni fun (Term TyName Name uni fun ()) Source # | |
HasTermLevel uni Text => Lift uni BuiltinString Source # | |
Defined in PlutusTx.Lift.Class lift :: BuiltinString -> RTCompile uni fun (Term TyName Name uni fun ()) Source # | |
HasTermLevel uni () => Lift uni BuiltinUnit Source # | |
Defined in PlutusTx.Lift.Class lift :: BuiltinUnit -> RTCompile uni fun (Term TyName Name uni fun ()) Source # | |
(TypeError ('Text "Int is not supported, use Integer instead") :: Constraint) => Lift uni Int Source # | |
(Typeable DefaultUni a, Lift DefaultUni a) => Lift DefaultUni (Maybe a) Source # | |
(Typeable DefaultUni a, Lift DefaultUni a) => Lift DefaultUni [a] Source # | |
Defined in PlutusTx.Lift.Instances | |
(HasFromBuiltin arep, HasTermLevel uni [FromBuiltin arep]) => Lift uni (BuiltinList arep) Source # | |
Defined in PlutusTx.Lift.Class lift :: BuiltinList arep -> RTCompile uni fun (Term TyName Name uni fun ()) Source # | |
(Typeable DefaultUni a, Typeable DefaultUni b, Lift DefaultUni a, Lift DefaultUni b) => Lift DefaultUni (Either a b) Source # | |
Lift DefaultUni [(k, v)] => Lift DefaultUni (Map k v) Source # | |
Lift DefaultUni (Map k a) Source # | |
(Typeable DefaultUni a, Typeable DefaultUni b, Lift DefaultUni a, Lift DefaultUni b) => Lift DefaultUni (These a b) Source # | |
(Typeable DefaultUni a, Typeable DefaultUni b, Lift DefaultUni a, Lift DefaultUni b) => Lift DefaultUni (a, b) Source # | |
Defined in PlutusTx.Lift.Instances | |
(HasFromBuiltin arep, HasFromBuiltin brep, HasTermLevel uni (FromBuiltin arep, FromBuiltin brep)) => Lift uni (BuiltinPair arep brep) Source # | |
Defined in PlutusTx.Lift.Class lift :: BuiltinPair arep brep -> RTCompile uni fun (Term TyName Name uni fun ()) Source # | |
(Typeable DefaultUni a, Typeable DefaultUni b, Typeable DefaultUni c, Lift DefaultUni a, Lift DefaultUni b, Lift DefaultUni c) => Lift DefaultUni (a, b, c) Source # | |
Defined in PlutusTx.Lift.Instances | |
(Typeable DefaultUni a, Typeable DefaultUni b, Typeable DefaultUni c, Typeable DefaultUni d, Lift DefaultUni a, Lift DefaultUni b, Lift DefaultUni c, Lift DefaultUni d) => Lift DefaultUni (a, b, c, d) Source # | |
Defined in PlutusTx.Lift.Instances | |
(Typeable DefaultUni a, Typeable DefaultUni b, Typeable DefaultUni c, Typeable DefaultUni d, Typeable DefaultUni e, Lift DefaultUni a, Lift DefaultUni b, Lift DefaultUni c, Lift DefaultUni d, Lift DefaultUni e) => Lift DefaultUni (a, b, c, d, e) Source # | |
Defined in PlutusTx.Lift.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.