{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE UndecidableSuperClasses #-}
{-# LANGUAGE NoPartialTypeSignatures #-}
{-# OPTIONS_GHC -Wno-redundant-constraints #-}
module Plutarch.Internal.Lift (
PLiftable (..),
LiftError (..),
pconstant,
plift,
DeriveBuiltinPLiftable (..),
DeriveDataPLiftable (..),
DeriveNewtypePLiftable (..),
unsafeHaskToUni,
reprToPlutUni,
plutToReprUni,
PLifted (PLifted),
mkPLifted,
getPLifted,
PLiftedClosed (..),
getPLiftedClosed,
mkPLiftedClosed,
pliftedToClosed,
pliftedFromClosed,
punsafeCoercePLifted,
) where
import Data.Bits (toIntegralSized)
import Data.ByteString (ByteString)
import Data.Coerce (Coercible, coerce)
import Data.Kind (Type)
import Data.Text (Text)
import Data.Text qualified as Text
import Data.Vector.Strict qualified as StrictVector
import Data.Word (Word8)
import GHC.Generics (Generic)
import Generics.SOP qualified as SOP
import Plutarch.Builtin.Array (PArray)
import Plutarch.Builtin.BLS (
PBuiltinBLS12_381_G1_Element,
PBuiltinBLS12_381_G2_Element,
PBuiltinBLS12_381_MlResult,
)
import Plutarch.Builtin.Bool (PBool)
import Plutarch.Builtin.ByteString (PByte, PByteString)
import Plutarch.Builtin.Data (
PAsData,
PBuiltinList,
PBuiltinPair,
PData,
)
import Plutarch.Builtin.Integer (PInteger)
import Plutarch.Builtin.Opaque (POpaque, popaque)
import Plutarch.Builtin.String (PString)
import Plutarch.Builtin.Unit (PUnit)
import Plutarch.Internal.Evaluate (evalScriptHuge)
import {-# SOURCE #-} Plutarch.Internal.IsData (PIsData)
import Plutarch.Internal.PlutusType (DeriveFakePlutusType (DeriveFakePlutusType), PlutusType (PInner))
import Plutarch.Internal.Subtype (PSubtype)
import Plutarch.Internal.Term (
Config (Tracing),
LogLevel (LogInfo),
S,
Term,
TracingMode (DoTracing),
compile,
punsafeCoerce,
punsafeConstantInternal,
)
import Plutarch.Script (Script (Script))
import PlutusCore qualified as PLC
import PlutusCore.Builtin (
BuiltinError,
KnownBuiltinType,
readKnownConstant,
)
import PlutusCore.Crypto.BLS12_381.G1 qualified as BLS12_381.G1
import PlutusCore.Crypto.BLS12_381.G2 qualified as BLS12_381.G2
import PlutusCore.Crypto.BLS12_381.Pairing qualified as BLS12_381.Pairing
import PlutusTx qualified as PTx
import Universe (Includes)
import UntypedPlutusCore qualified as UPLC
import UntypedPlutusCore.Evaluation.Machine.Cek qualified as Cek (CekEvaluationException)
data LiftError
=
CouldNotEvaluate (Cek.CekEvaluationException PLC.NamedDeBruijn PLC.DefaultUni PLC.DefaultFun)
|
TypeError BuiltinError
|
CouldNotCompile Text
|
CouldNotDecodeData
|
OtherLiftError Text
deriving stock
(
LiftError -> LiftError -> Bool
(LiftError -> LiftError -> Bool)
-> (LiftError -> LiftError -> Bool) -> Eq LiftError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LiftError -> LiftError -> Bool
== :: LiftError -> LiftError -> Bool
$c/= :: LiftError -> LiftError -> Bool
/= :: LiftError -> LiftError -> Bool
Eq
,
Int -> LiftError -> ShowS
[LiftError] -> ShowS
LiftError -> String
(Int -> LiftError -> ShowS)
-> (LiftError -> String)
-> ([LiftError] -> ShowS)
-> Show LiftError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LiftError -> ShowS
showsPrec :: Int -> LiftError -> ShowS
$cshow :: LiftError -> String
show :: LiftError -> String
$cshowList :: [LiftError] -> ShowS
showList :: [LiftError] -> ShowS
Show
)
class PlutusType a => PLiftable (a :: S -> Type) where
type AsHaskell a :: Type
type PlutusRepr a :: Type
haskToRepr :: AsHaskell a -> PlutusRepr a
reprToHask :: PlutusRepr a -> Either LiftError (AsHaskell a)
reprToPlut :: forall (s :: S). PlutusRepr a -> PLifted s a
plutToRepr :: (forall (s :: S). PLifted s a) -> Either LiftError (PlutusRepr a)
reprToPlutUni ::
forall (a :: S -> Type) (s :: S).
PLC.DefaultUni `Includes` PlutusRepr a =>
PlutusRepr a ->
PLifted s a
reprToPlutUni :: forall (a :: S -> Type) (s :: S).
Includes @Type DefaultUni (PlutusRepr a) =>
PlutusRepr a -> PLifted s a
reprToPlutUni = PlutusRepr a -> PLifted s a
forall h (a :: S -> Type) (s :: S).
Includes @Type DefaultUni h =>
h -> PLifted s a
unsafeHaskToUni
unsafeHaskToUni ::
forall (h :: Type) (a :: S -> Type) (s :: S).
PLC.DefaultUni `Includes` h =>
h ->
PLifted s a
unsafeHaskToUni :: forall h (a :: S -> Type) (s :: S).
Includes @Type DefaultUni h =>
h -> PLifted s a
unsafeHaskToUni h
x =
Term s POpaque -> PLifted s a
forall (s :: S) (a :: S -> Type). Term s POpaque -> PLifted s a
PLifted (Term s POpaque -> PLifted s a) -> Term s POpaque -> PLifted s a
forall a b. (a -> b) -> a -> b
$ Term s (Any @(S -> Type)) -> Term s POpaque
forall (s :: S) (a :: S -> Type). Term s a -> Term s POpaque
popaque (Term s (Any @(S -> Type)) -> Term s POpaque)
-> Term s (Any @(S -> Type)) -> Term s POpaque
forall a b. (a -> b) -> a -> b
$ Term s (Any @(S -> Type)) -> Term s (Any @(S -> Type))
forall (b :: S -> Type) (a :: S -> Type) (s :: S).
Term s a -> Term s b
punsafeCoerce (Term s (Any @(S -> Type)) -> Term s (Any @(S -> Type)))
-> Term s (Any @(S -> Type)) -> Term s (Any @(S -> Type))
forall a b. (a -> b) -> a -> b
$ Some @Type (ValueOf DefaultUni) -> Term s (Any @(S -> Type))
forall (s :: S) (a :: S -> Type).
Some @Type (ValueOf DefaultUni) -> Term s a
punsafeConstantInternal (Some @Type (ValueOf DefaultUni) -> Term s (Any @(S -> Type)))
-> Some @Type (ValueOf DefaultUni) -> Term s (Any @(S -> Type))
forall a b. (a -> b) -> a -> b
$ h -> Some @Type (ValueOf DefaultUni)
forall a (uni :: Type -> Type).
Contains @Type uni a =>
a -> Some @Type (ValueOf uni)
PLC.someValue h
x
plutToReprUni ::
forall (a :: S -> Type).
KnownBuiltinType (UPLC.Term UPLC.DeBruijn UPLC.DefaultUni UPLC.DefaultFun ()) (PlutusRepr a) =>
(forall (s :: S). PLifted s a) ->
Either LiftError (PlutusRepr a)
plutToReprUni :: forall (a :: S -> Type).
KnownBuiltinType
(Term DeBruijn DefaultUni DefaultFun ()) (PlutusRepr a) =>
(forall (s :: S). PLifted s a) -> Either LiftError (PlutusRepr a)
plutToReprUni forall (s :: S). PLifted s a
t = case Config -> (forall (s :: S). Term s POpaque) -> Either Text Script
forall (a :: S -> Type).
Config -> (forall (s :: S). Term s a) -> Either Text Script
compile (LogLevel -> TracingMode -> Config
Tracing LogLevel
LogInfo TracingMode
DoTracing) ((forall (s :: S). Term s POpaque) -> Either Text Script)
-> (forall (s :: S). Term s POpaque) -> Either Text Script
forall a b. (a -> b) -> a -> b
$ PLifted s a -> Term s POpaque
forall (s :: S) (a :: S -> Type). PLifted s a -> Term s POpaque
unPLifted PLifted s a
forall (s :: S). PLifted s a
t of
Left Text
err -> LiftError -> Either LiftError (PlutusRepr a)
forall a b. a -> Either a b
Left (LiftError -> Either LiftError (PlutusRepr a))
-> (Text -> LiftError) -> Text -> Either LiftError (PlutusRepr a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> LiftError
CouldNotCompile (Text -> Either LiftError (PlutusRepr a))
-> Text -> Either LiftError (PlutusRepr a)
forall a b. (a -> b) -> a -> b
$ Text
err
Right Script
compiled -> case Script
-> (Either
(CekEvaluationException NamedDeBruijn DefaultUni DefaultFun)
Script,
ExBudget, [Text])
evalScriptHuge Script
compiled of
(Either
(CekEvaluationException NamedDeBruijn DefaultUni DefaultFun) Script
evaluated, ExBudget
_, [Text]
_) -> case Either
(CekEvaluationException NamedDeBruijn DefaultUni DefaultFun) Script
evaluated of
Left CekEvaluationException NamedDeBruijn DefaultUni DefaultFun
err -> LiftError -> Either LiftError (PlutusRepr a)
forall a b. a -> Either a b
Left (LiftError -> Either LiftError (PlutusRepr a))
-> (CekEvaluationException NamedDeBruijn DefaultUni DefaultFun
-> LiftError)
-> CekEvaluationException NamedDeBruijn DefaultUni DefaultFun
-> Either LiftError (PlutusRepr a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CekEvaluationException NamedDeBruijn DefaultUni DefaultFun
-> LiftError
CouldNotEvaluate (CekEvaluationException NamedDeBruijn DefaultUni DefaultFun
-> Either LiftError (PlutusRepr a))
-> CekEvaluationException NamedDeBruijn DefaultUni DefaultFun
-> Either LiftError (PlutusRepr a)
forall a b. (a -> b) -> a -> b
$ CekEvaluationException NamedDeBruijn DefaultUni DefaultFun
err
Right (Script (UPLC.Program ()
_ Version
_ Term DeBruijn DefaultUni DefaultFun ()
term)) ->
case Term DeBruijn DefaultUni DefaultFun () -> ReadKnownM (PlutusRepr a)
forall val a. KnownBuiltinType val a => val -> ReadKnownM a
readKnownConstant Term DeBruijn DefaultUni DefaultFun ()
term of
Left BuiltinError
err -> LiftError -> Either LiftError (PlutusRepr a)
forall a b. a -> Either a b
Left (LiftError -> Either LiftError (PlutusRepr a))
-> (BuiltinError -> LiftError)
-> BuiltinError
-> Either LiftError (PlutusRepr a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BuiltinError -> LiftError
TypeError (BuiltinError -> Either LiftError (PlutusRepr a))
-> BuiltinError -> Either LiftError (PlutusRepr a)
forall a b. (a -> b) -> a -> b
$ BuiltinError
err
Right PlutusRepr a
res -> PlutusRepr a -> Either LiftError (PlutusRepr a)
forall a b. b -> Either a b
Right PlutusRepr a
res
pconstant ::
forall (a :: S -> Type) (s :: S).
PLiftable a =>
AsHaskell a ->
Term s a
pconstant :: forall (a :: S -> Type) (s :: S).
PLiftable a =>
AsHaskell a -> Term s a
pconstant = PLifted s a -> Term s a
forall (s :: S) (a :: S -> Type). PLifted s a -> Term s a
getPLifted (PLifted s a -> Term s a)
-> (AsHaskell a -> PLifted s a) -> AsHaskell a -> Term s a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PlutusRepr a -> PLifted s a
forall (s :: S). PlutusRepr a -> PLifted s a
forall (a :: S -> Type) (s :: S).
PLiftable a =>
PlutusRepr a -> PLifted s a
reprToPlut (PlutusRepr a -> PLifted s a)
-> (AsHaskell a -> PlutusRepr a) -> AsHaskell a -> PLifted s a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (a :: S -> Type). PLiftable a => AsHaskell a -> PlutusRepr a
haskToRepr @a
plift ::
forall (a :: S -> Type).
PLiftable a =>
(forall (s :: S). Term s a) ->
AsHaskell a
plift :: forall (a :: S -> Type).
PLiftable a =>
(forall (s :: S). Term s a) -> AsHaskell a
plift forall (s :: S). Term s a
t = case forall (a :: S -> Type).
PLiftable a =>
(forall (s :: S). PLifted s a) -> Either LiftError (PlutusRepr a)
plutToRepr @a ((forall (s :: S). PLifted s a) -> Either LiftError (PlutusRepr a))
-> (forall (s :: S). PLifted s a)
-> Either LiftError (PlutusRepr a)
forall a b. (a -> b) -> a -> b
$ Term s a -> PLifted s a
forall (s :: S) (a :: S -> Type). Term s a -> PLifted s a
mkPLifted Term s a
forall (s :: S). Term s a
t of
Left LiftError
err ->
String -> AsHaskell a
forall a. HasCallStack => String -> a
error (String -> AsHaskell a) -> String -> AsHaskell a
forall a b. (a -> b) -> a -> b
$
String
"plift failed: "
String -> ShowS
forall a. Semigroup a => a -> a -> a
<> ( case LiftError
err of
CouldNotEvaluate CekEvaluationException NamedDeBruijn DefaultUni DefaultFun
evalErr -> String
"term errored: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> CekEvaluationException NamedDeBruijn DefaultUni DefaultFun
-> String
forall a. Show a => a -> String
show CekEvaluationException NamedDeBruijn DefaultUni DefaultFun
evalErr
TypeError BuiltinError
builtinError -> String
"incorrect type: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> BuiltinError -> String
forall a. Show a => a -> String
show BuiltinError
builtinError
CouldNotCompile Text
compErr -> String
"could not compile: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Text -> String
Text.unpack Text
compErr
LiftError
CouldNotDecodeData -> String
"Data value is not a valid encoding for this type"
OtherLiftError Text
err -> String
"other error: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Text -> String
Text.unpack Text
err
)
Right PlutusRepr a
res -> case forall (a :: S -> Type).
PLiftable a =>
PlutusRepr a -> Either LiftError (AsHaskell a)
reprToHask @a PlutusRepr a
res of
Left LiftError
_ ->
String -> AsHaskell a
forall a. HasCallStack => String -> a
error (String -> AsHaskell a) -> String -> AsHaskell a
forall a b. (a -> b) -> a -> b
$
String
"plift failed: "
String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
"Plutus representation does not correspond to a Haskell value"
Right AsHaskell a
res' -> AsHaskell a
res'
newtype DeriveBuiltinPLiftable (a :: S -> Type) (h :: Type) (s :: S)
= DeriveBuiltinPLiftable (a s)
deriving stock ((forall x.
DeriveBuiltinPLiftable a h s
-> Rep (DeriveBuiltinPLiftable a h s) x)
-> (forall x.
Rep (DeriveBuiltinPLiftable a h s) x
-> DeriveBuiltinPLiftable a h s)
-> Generic (DeriveBuiltinPLiftable a h s)
forall x.
Rep (DeriveBuiltinPLiftable a h s) x
-> DeriveBuiltinPLiftable a h s
forall x.
DeriveBuiltinPLiftable a h s
-> Rep (DeriveBuiltinPLiftable a h s) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (a :: S -> Type) h (s :: S) x.
Rep (DeriveBuiltinPLiftable a h s) x
-> DeriveBuiltinPLiftable a h s
forall (a :: S -> Type) h (s :: S) x.
DeriveBuiltinPLiftable a h s
-> Rep (DeriveBuiltinPLiftable a h s) x
$cfrom :: forall (a :: S -> Type) h (s :: S) x.
DeriveBuiltinPLiftable a h s
-> Rep (DeriveBuiltinPLiftable a h s) x
from :: forall x.
DeriveBuiltinPLiftable a h s
-> Rep (DeriveBuiltinPLiftable a h s) x
$cto :: forall (a :: S -> Type) h (s :: S) x.
Rep (DeriveBuiltinPLiftable a h s) x
-> DeriveBuiltinPLiftable a h s
to :: forall x.
Rep (DeriveBuiltinPLiftable a h s) x
-> DeriveBuiltinPLiftable a h s
Generic)
deriving anyclass (All @[Type] (SListI @Type) (Code (DeriveBuiltinPLiftable a h s))
All @[Type] (SListI @Type) (Code (DeriveBuiltinPLiftable a h s)) =>
(DeriveBuiltinPLiftable a h s
-> Rep (DeriveBuiltinPLiftable a h s))
-> (Rep (DeriveBuiltinPLiftable a h s)
-> DeriveBuiltinPLiftable a h s)
-> Generic (DeriveBuiltinPLiftable a h s)
Rep (DeriveBuiltinPLiftable a h s) -> DeriveBuiltinPLiftable a h s
DeriveBuiltinPLiftable a h s -> Rep (DeriveBuiltinPLiftable a h s)
forall a.
All @[Type] (SListI @Type) (Code a) =>
(a -> Rep a) -> (Rep a -> a) -> Generic a
forall (a :: S -> Type) h (s :: S).
All @[Type] (SListI @Type) (Code (DeriveBuiltinPLiftable a h s))
forall (a :: S -> Type) h (s :: S).
Rep (DeriveBuiltinPLiftable a h s) -> DeriveBuiltinPLiftable a h s
forall (a :: S -> Type) h (s :: S).
DeriveBuiltinPLiftable a h s -> Rep (DeriveBuiltinPLiftable a h s)
$cfrom :: forall (a :: S -> Type) h (s :: S).
DeriveBuiltinPLiftable a h s -> Rep (DeriveBuiltinPLiftable a h s)
from :: DeriveBuiltinPLiftable a h s -> Rep (DeriveBuiltinPLiftable a h s)
$cto :: forall (a :: S -> Type) h (s :: S).
Rep (DeriveBuiltinPLiftable a h s) -> DeriveBuiltinPLiftable a h s
to :: Rep (DeriveBuiltinPLiftable a h s) -> DeriveBuiltinPLiftable a h s
SOP.Generic)
deriving
(
(forall (s :: S).
DeriveBuiltinPLiftable a h s
-> Term s (PInner (DeriveBuiltinPLiftable a h)))
-> (forall (s :: S) (b :: S -> Type).
Term s (PInner (DeriveBuiltinPLiftable a h))
-> (DeriveBuiltinPLiftable a h s -> Term s b) -> Term s b)
-> PlutusType (DeriveBuiltinPLiftable a h)
forall (s :: S).
DeriveBuiltinPLiftable a h s
-> Term s (PInner (DeriveBuiltinPLiftable a h))
forall (s :: S) (b :: S -> Type).
Term s (PInner (DeriveBuiltinPLiftable a h))
-> (DeriveBuiltinPLiftable a h s -> Term s b) -> Term s b
forall (a :: S -> Type).
(forall (s :: S). a s -> Term s (PInner a))
-> (forall (s :: S) (b :: S -> Type).
Term s (PInner a) -> (a s -> Term s b) -> Term s b)
-> PlutusType a
forall (a :: S -> Type) h (s :: S).
DeriveBuiltinPLiftable a h s
-> Term s (PInner (DeriveBuiltinPLiftable a h))
forall (a :: S -> Type) h (s :: S) (b :: S -> Type).
Term s (PInner (DeriveBuiltinPLiftable a h))
-> (DeriveBuiltinPLiftable a h s -> Term s b) -> Term s b
$cpcon' :: forall (a :: S -> Type) h (s :: S).
DeriveBuiltinPLiftable a h s
-> Term s (PInner (DeriveBuiltinPLiftable a h))
pcon' :: forall (s :: S).
DeriveBuiltinPLiftable a h s
-> Term s (PInner (DeriveBuiltinPLiftable a h))
$cpmatch' :: forall (a :: S -> Type) h (s :: S) (b :: S -> Type).
Term s (PInner (DeriveBuiltinPLiftable a h))
-> (DeriveBuiltinPLiftable a h s -> Term s b) -> Term s b
pmatch' :: forall (s :: S) (b :: S -> Type).
Term s (PInner (DeriveBuiltinPLiftable a h))
-> (DeriveBuiltinPLiftable a h s -> Term s b) -> Term s b
PlutusType
)
via (DeriveFakePlutusType (DeriveBuiltinPLiftable a h))
instance
( PlutusType a
, PLC.DefaultUni `Includes` h
, KnownBuiltinType (UPLC.Term UPLC.DeBruijn UPLC.DefaultUni UPLC.DefaultFun ()) h
) =>
PLiftable (DeriveBuiltinPLiftable a h)
where
type AsHaskell (DeriveBuiltinPLiftable a h) = h
type PlutusRepr (DeriveBuiltinPLiftable a h) = h
{-# INLINEABLE haskToRepr #-}
haskToRepr :: AsHaskell (DeriveBuiltinPLiftable a h)
-> PlutusRepr (DeriveBuiltinPLiftable a h)
haskToRepr = AsHaskell (DeriveBuiltinPLiftable a h)
-> PlutusRepr (DeriveBuiltinPLiftable a h)
AsHaskell (DeriveBuiltinPLiftable a h)
-> AsHaskell (DeriveBuiltinPLiftable a h)
forall a. a -> a
id
{-# INLINEABLE reprToHask #-}
reprToHask :: PlutusRepr (DeriveBuiltinPLiftable a h)
-> Either LiftError (AsHaskell (DeriveBuiltinPLiftable a h))
reprToHask = PlutusRepr (DeriveBuiltinPLiftable a h)
-> Either LiftError (PlutusRepr (DeriveBuiltinPLiftable a h))
PlutusRepr (DeriveBuiltinPLiftable a h)
-> Either LiftError (AsHaskell (DeriveBuiltinPLiftable a h))
forall a b. b -> Either a b
Right
{-# INLINEABLE reprToPlut #-}
reprToPlut :: forall (s :: S).
PlutusRepr (DeriveBuiltinPLiftable a h)
-> PLifted s (DeriveBuiltinPLiftable a h)
reprToPlut = PlutusRepr (DeriveBuiltinPLiftable a h)
-> PLifted s (DeriveBuiltinPLiftable a h)
forall (a :: S -> Type) (s :: S).
Includes @Type DefaultUni (PlutusRepr a) =>
PlutusRepr a -> PLifted s a
reprToPlutUni
{-# INLINEABLE plutToRepr #-}
plutToRepr :: (forall (s :: S). PLifted s (DeriveBuiltinPLiftable a h))
-> Either LiftError (PlutusRepr (DeriveBuiltinPLiftable a h))
plutToRepr = (forall (s :: S). PLifted s (DeriveBuiltinPLiftable a h))
-> Either LiftError (PlutusRepr (DeriveBuiltinPLiftable a h))
forall (a :: S -> Type).
KnownBuiltinType
(Term DeBruijn DefaultUni DefaultFun ()) (PlutusRepr a) =>
(forall (s :: S). PLifted s a) -> Either LiftError (PlutusRepr a)
plutToReprUni
newtype DeriveDataPLiftable (a :: S -> Type) (h :: Type) (s :: S)
= DeriveDataPLiftable (a s)
deriving stock ((forall x.
DeriveDataPLiftable a h s -> Rep (DeriveDataPLiftable a h s) x)
-> (forall x.
Rep (DeriveDataPLiftable a h s) x -> DeriveDataPLiftable a h s)
-> Generic (DeriveDataPLiftable a h s)
forall x.
Rep (DeriveDataPLiftable a h s) x -> DeriveDataPLiftable a h s
forall x.
DeriveDataPLiftable a h s -> Rep (DeriveDataPLiftable a h s) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (a :: S -> Type) h (s :: S) x.
Rep (DeriveDataPLiftable a h s) x -> DeriveDataPLiftable a h s
forall (a :: S -> Type) h (s :: S) x.
DeriveDataPLiftable a h s -> Rep (DeriveDataPLiftable a h s) x
$cfrom :: forall (a :: S -> Type) h (s :: S) x.
DeriveDataPLiftable a h s -> Rep (DeriveDataPLiftable a h s) x
from :: forall x.
DeriveDataPLiftable a h s -> Rep (DeriveDataPLiftable a h s) x
$cto :: forall (a :: S -> Type) h (s :: S) x.
Rep (DeriveDataPLiftable a h s) x -> DeriveDataPLiftable a h s
to :: forall x.
Rep (DeriveDataPLiftable a h s) x -> DeriveDataPLiftable a h s
Generic)
deriving anyclass (All @[Type] (SListI @Type) (Code (DeriveDataPLiftable a h s))
All @[Type] (SListI @Type) (Code (DeriveDataPLiftable a h s)) =>
(DeriveDataPLiftable a h s -> Rep (DeriveDataPLiftable a h s))
-> (Rep (DeriveDataPLiftable a h s) -> DeriveDataPLiftable a h s)
-> Generic (DeriveDataPLiftable a h s)
Rep (DeriveDataPLiftable a h s) -> DeriveDataPLiftable a h s
DeriveDataPLiftable a h s -> Rep (DeriveDataPLiftable a h s)
forall a.
All @[Type] (SListI @Type) (Code a) =>
(a -> Rep a) -> (Rep a -> a) -> Generic a
forall (a :: S -> Type) h (s :: S).
All @[Type] (SListI @Type) (Code (DeriveDataPLiftable a h s))
forall (a :: S -> Type) h (s :: S).
Rep (DeriveDataPLiftable a h s) -> DeriveDataPLiftable a h s
forall (a :: S -> Type) h (s :: S).
DeriveDataPLiftable a h s -> Rep (DeriveDataPLiftable a h s)
$cfrom :: forall (a :: S -> Type) h (s :: S).
DeriveDataPLiftable a h s -> Rep (DeriveDataPLiftable a h s)
from :: DeriveDataPLiftable a h s -> Rep (DeriveDataPLiftable a h s)
$cto :: forall (a :: S -> Type) h (s :: S).
Rep (DeriveDataPLiftable a h s) -> DeriveDataPLiftable a h s
to :: Rep (DeriveDataPLiftable a h s) -> DeriveDataPLiftable a h s
SOP.Generic)
deriving
(
(forall (s :: S).
DeriveDataPLiftable a h s
-> Term s (PInner (DeriveDataPLiftable a h)))
-> (forall (s :: S) (b :: S -> Type).
Term s (PInner (DeriveDataPLiftable a h))
-> (DeriveDataPLiftable a h s -> Term s b) -> Term s b)
-> PlutusType (DeriveDataPLiftable a h)
forall (s :: S).
DeriveDataPLiftable a h s
-> Term s (PInner (DeriveDataPLiftable a h))
forall (s :: S) (b :: S -> Type).
Term s (PInner (DeriveDataPLiftable a h))
-> (DeriveDataPLiftable a h s -> Term s b) -> Term s b
forall (a :: S -> Type).
(forall (s :: S). a s -> Term s (PInner a))
-> (forall (s :: S) (b :: S -> Type).
Term s (PInner a) -> (a s -> Term s b) -> Term s b)
-> PlutusType a
forall (a :: S -> Type) h (s :: S).
DeriveDataPLiftable a h s
-> Term s (PInner (DeriveDataPLiftable a h))
forall (a :: S -> Type) h (s :: S) (b :: S -> Type).
Term s (PInner (DeriveDataPLiftable a h))
-> (DeriveDataPLiftable a h s -> Term s b) -> Term s b
$cpcon' :: forall (a :: S -> Type) h (s :: S).
DeriveDataPLiftable a h s
-> Term s (PInner (DeriveDataPLiftable a h))
pcon' :: forall (s :: S).
DeriveDataPLiftable a h s
-> Term s (PInner (DeriveDataPLiftable a h))
$cpmatch' :: forall (a :: S -> Type) h (s :: S) (b :: S -> Type).
Term s (PInner (DeriveDataPLiftable a h))
-> (DeriveDataPLiftable a h s -> Term s b) -> Term s b
pmatch' :: forall (s :: S) (b :: S -> Type).
Term s (PInner (DeriveDataPLiftable a h))
-> (DeriveDataPLiftable a h s -> Term s b) -> Term s b
PlutusType
)
via (DeriveFakePlutusType (DeriveDataPLiftable a h))
instance
( PlutusType a
, PSubtype PData a
, PTx.ToData h
, PTx.FromData h
) =>
PLiftable (DeriveDataPLiftable a h)
where
type AsHaskell (DeriveDataPLiftable a h) = h
type PlutusRepr (DeriveDataPLiftable a h) = PTx.Data
{-# INLINEABLE haskToRepr #-}
haskToRepr :: AsHaskell (DeriveDataPLiftable a h)
-> PlutusRepr (DeriveDataPLiftable a h)
haskToRepr = AsHaskell (DeriveDataPLiftable a h) -> Data
AsHaskell (DeriveDataPLiftable a h)
-> PlutusRepr (DeriveDataPLiftable a h)
forall a. ToData a => a -> Data
PTx.toData
{-# INLINEABLE reprToHask #-}
reprToHask :: PlutusRepr (DeriveDataPLiftable a h)
-> Either LiftError (AsHaskell (DeriveDataPLiftable a h))
reprToHask = Either LiftError (AsHaskell (DeriveDataPLiftable a h))
-> (AsHaskell (DeriveDataPLiftable a h)
-> Either LiftError (AsHaskell (DeriveDataPLiftable a h)))
-> Maybe (AsHaskell (DeriveDataPLiftable a h))
-> Either LiftError (AsHaskell (DeriveDataPLiftable a h))
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (LiftError -> Either LiftError (AsHaskell (DeriveDataPLiftable a h))
forall a b. a -> Either a b
Left LiftError
CouldNotDecodeData) AsHaskell (DeriveDataPLiftable a h)
-> Either LiftError (AsHaskell (DeriveDataPLiftable a h))
forall a b. b -> Either a b
Right (Maybe (AsHaskell (DeriveDataPLiftable a h))
-> Either LiftError (AsHaskell (DeriveDataPLiftable a h)))
-> (Data -> Maybe (AsHaskell (DeriveDataPLiftable a h)))
-> Data
-> Either LiftError (AsHaskell (DeriveDataPLiftable a h))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Data -> Maybe (AsHaskell (DeriveDataPLiftable a h))
forall a. FromData a => Data -> Maybe a
PTx.fromData
{-# INLINEABLE reprToPlut #-}
reprToPlut :: forall (s :: S).
PlutusRepr (DeriveDataPLiftable a h)
-> PLifted s (DeriveDataPLiftable a h)
reprToPlut = PlutusRepr (DeriveDataPLiftable a h)
-> PLifted s (DeriveDataPLiftable a h)
forall (a :: S -> Type) (s :: S).
Includes @Type DefaultUni (PlutusRepr a) =>
PlutusRepr a -> PLifted s a
reprToPlutUni
{-# INLINEABLE plutToRepr #-}
plutToRepr :: (forall (s :: S). PLifted s (DeriveDataPLiftable a h))
-> Either LiftError (PlutusRepr (DeriveDataPLiftable a h))
plutToRepr = (forall (s :: S). PLifted s (DeriveDataPLiftable a h))
-> Either LiftError (PlutusRepr (DeriveDataPLiftable a h))
forall (a :: S -> Type).
KnownBuiltinType
(Term DeBruijn DefaultUni DefaultFun ()) (PlutusRepr a) =>
(forall (s :: S). PLifted s a) -> Either LiftError (PlutusRepr a)
plutToReprUni
newtype DeriveNewtypePLiftable (wrapper :: S -> Type) (h :: Type) (s :: S)
= DeriveNewtypePLiftable (wrapper s)
deriving stock ((forall x.
DeriveNewtypePLiftable wrapper h s
-> Rep (DeriveNewtypePLiftable wrapper h s) x)
-> (forall x.
Rep (DeriveNewtypePLiftable wrapper h s) x
-> DeriveNewtypePLiftable wrapper h s)
-> Generic (DeriveNewtypePLiftable wrapper h s)
forall x.
Rep (DeriveNewtypePLiftable wrapper h s) x
-> DeriveNewtypePLiftable wrapper h s
forall x.
DeriveNewtypePLiftable wrapper h s
-> Rep (DeriveNewtypePLiftable wrapper h s) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (wrapper :: S -> Type) h (s :: S) x.
Rep (DeriveNewtypePLiftable wrapper h s) x
-> DeriveNewtypePLiftable wrapper h s
forall (wrapper :: S -> Type) h (s :: S) x.
DeriveNewtypePLiftable wrapper h s
-> Rep (DeriveNewtypePLiftable wrapper h s) x
$cfrom :: forall (wrapper :: S -> Type) h (s :: S) x.
DeriveNewtypePLiftable wrapper h s
-> Rep (DeriveNewtypePLiftable wrapper h s) x
from :: forall x.
DeriveNewtypePLiftable wrapper h s
-> Rep (DeriveNewtypePLiftable wrapper h s) x
$cto :: forall (wrapper :: S -> Type) h (s :: S) x.
Rep (DeriveNewtypePLiftable wrapper h s) x
-> DeriveNewtypePLiftable wrapper h s
to :: forall x.
Rep (DeriveNewtypePLiftable wrapper h s) x
-> DeriveNewtypePLiftable wrapper h s
Generic)
deriving anyclass (All
@[Type] (SListI @Type) (Code (DeriveNewtypePLiftable wrapper h s))
All
@[Type]
(SListI @Type)
(Code (DeriveNewtypePLiftable wrapper h s)) =>
(DeriveNewtypePLiftable wrapper h s
-> Rep (DeriveNewtypePLiftable wrapper h s))
-> (Rep (DeriveNewtypePLiftable wrapper h s)
-> DeriveNewtypePLiftable wrapper h s)
-> Generic (DeriveNewtypePLiftable wrapper h s)
Rep (DeriveNewtypePLiftable wrapper h s)
-> DeriveNewtypePLiftable wrapper h s
DeriveNewtypePLiftable wrapper h s
-> Rep (DeriveNewtypePLiftable wrapper h s)
forall a.
All @[Type] (SListI @Type) (Code a) =>
(a -> Rep a) -> (Rep a -> a) -> Generic a
forall (wrapper :: S -> Type) h (s :: S).
All
@[Type] (SListI @Type) (Code (DeriveNewtypePLiftable wrapper h s))
forall (wrapper :: S -> Type) h (s :: S).
Rep (DeriveNewtypePLiftable wrapper h s)
-> DeriveNewtypePLiftable wrapper h s
forall (wrapper :: S -> Type) h (s :: S).
DeriveNewtypePLiftable wrapper h s
-> Rep (DeriveNewtypePLiftable wrapper h s)
$cfrom :: forall (wrapper :: S -> Type) h (s :: S).
DeriveNewtypePLiftable wrapper h s
-> Rep (DeriveNewtypePLiftable wrapper h s)
from :: DeriveNewtypePLiftable wrapper h s
-> Rep (DeriveNewtypePLiftable wrapper h s)
$cto :: forall (wrapper :: S -> Type) h (s :: S).
Rep (DeriveNewtypePLiftable wrapper h s)
-> DeriveNewtypePLiftable wrapper h s
to :: Rep (DeriveNewtypePLiftable wrapper h s)
-> DeriveNewtypePLiftable wrapper h s
SOP.Generic)
deriving
(
(forall (s :: S).
DeriveNewtypePLiftable wrapper h s
-> Term s (PInner (DeriveNewtypePLiftable wrapper h)))
-> (forall (s :: S) (b :: S -> Type).
Term s (PInner (DeriveNewtypePLiftable wrapper h))
-> (DeriveNewtypePLiftable wrapper h s -> Term s b) -> Term s b)
-> PlutusType (DeriveNewtypePLiftable wrapper h)
forall (s :: S).
DeriveNewtypePLiftable wrapper h s
-> Term s (PInner (DeriveNewtypePLiftable wrapper h))
forall (s :: S) (b :: S -> Type).
Term s (PInner (DeriveNewtypePLiftable wrapper h))
-> (DeriveNewtypePLiftable wrapper h s -> Term s b) -> Term s b
forall (a :: S -> Type).
(forall (s :: S). a s -> Term s (PInner a))
-> (forall (s :: S) (b :: S -> Type).
Term s (PInner a) -> (a s -> Term s b) -> Term s b)
-> PlutusType a
forall (wrapper :: S -> Type) h (s :: S).
DeriveNewtypePLiftable wrapper h s
-> Term s (PInner (DeriveNewtypePLiftable wrapper h))
forall (wrapper :: S -> Type) h (s :: S) (b :: S -> Type).
Term s (PInner (DeriveNewtypePLiftable wrapper h))
-> (DeriveNewtypePLiftable wrapper h s -> Term s b) -> Term s b
$cpcon' :: forall (wrapper :: S -> Type) h (s :: S).
DeriveNewtypePLiftable wrapper h s
-> Term s (PInner (DeriveNewtypePLiftable wrapper h))
pcon' :: forall (s :: S).
DeriveNewtypePLiftable wrapper h s
-> Term s (PInner (DeriveNewtypePLiftable wrapper h))
$cpmatch' :: forall (wrapper :: S -> Type) h (s :: S) (b :: S -> Type).
Term s (PInner (DeriveNewtypePLiftable wrapper h))
-> (DeriveNewtypePLiftable wrapper h s -> Term s b) -> Term s b
pmatch' :: forall (s :: S) (b :: S -> Type).
Term s (PInner (DeriveNewtypePLiftable wrapper h))
-> (DeriveNewtypePLiftable wrapper h s -> Term s b) -> Term s b
PlutusType
)
via (DeriveFakePlutusType (DeriveNewtypePLiftable wrapper h))
instance
( PLiftable (PInner wrapper)
, Coercible h (AsHaskell (PInner wrapper))
, PLC.DefaultUni `Includes` PlutusRepr (PInner wrapper)
, KnownBuiltinType (UPLC.Term UPLC.DeBruijn UPLC.DefaultUni UPLC.DefaultFun ()) (PlutusRepr (PInner wrapper))
) =>
PLiftable (DeriveNewtypePLiftable wrapper h)
where
type AsHaskell (DeriveNewtypePLiftable wrapper h) = h
type PlutusRepr (DeriveNewtypePLiftable wrapper h) = PlutusRepr (PInner wrapper)
{-# INLINEABLE haskToRepr #-}
haskToRepr :: AsHaskell (DeriveNewtypePLiftable wrapper h)
-> PlutusRepr (DeriveNewtypePLiftable wrapper h)
haskToRepr = forall (a :: S -> Type). PLiftable a => AsHaskell a -> PlutusRepr a
haskToRepr @(PInner wrapper) (AsHaskell (PInner wrapper) -> PlutusRepr (PInner wrapper))
-> (AsHaskell (DeriveNewtypePLiftable wrapper h)
-> AsHaskell (PInner wrapper))
-> AsHaskell (DeriveNewtypePLiftable wrapper h)
-> PlutusRepr (PInner wrapper)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AsHaskell (DeriveNewtypePLiftable wrapper h)
-> AsHaskell (PInner wrapper)
forall a b. Coercible @Type a b => a -> b
coerce
{-# INLINEABLE reprToHask #-}
reprToHask :: PlutusRepr (DeriveNewtypePLiftable wrapper h)
-> Either LiftError (AsHaskell (DeriveNewtypePLiftable wrapper h))
reprToHask = Either LiftError (AsHaskell (PInner wrapper))
-> Either LiftError (AsHaskell (DeriveNewtypePLiftable wrapper h))
forall a b. Coercible @Type a b => a -> b
coerce (Either LiftError (AsHaskell (PInner wrapper))
-> Either LiftError (AsHaskell (DeriveNewtypePLiftable wrapper h)))
-> (PlutusRepr (PInner wrapper)
-> Either LiftError (AsHaskell (PInner wrapper)))
-> PlutusRepr (PInner wrapper)
-> Either LiftError (AsHaskell (DeriveNewtypePLiftable wrapper h))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (a :: S -> Type).
PLiftable a =>
PlutusRepr a -> Either LiftError (AsHaskell a)
reprToHask @(PInner wrapper)
{-# INLINEABLE reprToPlut #-}
reprToPlut :: forall (s :: S).
PlutusRepr (DeriveNewtypePLiftable wrapper h)
-> PLifted s (DeriveNewtypePLiftable wrapper h)
reprToPlut = PLifted s (PInner wrapper)
-> PLifted s (DeriveNewtypePLiftable wrapper h)
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
PLifted s a -> PLifted s b
punsafeCoercePLifted (PLifted s (PInner wrapper)
-> PLifted s (DeriveNewtypePLiftable wrapper h))
-> (PlutusRepr (PInner wrapper) -> PLifted s (PInner wrapper))
-> PlutusRepr (PInner wrapper)
-> PLifted s (DeriveNewtypePLiftable wrapper h)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (a :: S -> Type) (s :: S).
Includes @Type DefaultUni (PlutusRepr a) =>
PlutusRepr a -> PLifted s a
reprToPlutUni @(PInner wrapper)
{-# INLINEABLE plutToRepr #-}
plutToRepr :: (forall (s :: S). PLifted s (DeriveNewtypePLiftable wrapper h))
-> Either LiftError (PlutusRepr (DeriveNewtypePLiftable wrapper h))
plutToRepr forall (s :: S). PLifted s (DeriveNewtypePLiftable wrapper h)
t = forall (a :: S -> Type).
KnownBuiltinType
(Term DeBruijn DefaultUni DefaultFun ()) (PlutusRepr a) =>
(forall (s :: S). PLifted s a) -> Either LiftError (PlutusRepr a)
plutToReprUni @(PInner wrapper) ((forall (s :: S). PLifted s (PInner wrapper))
-> Either LiftError (PlutusRepr (PInner wrapper)))
-> (forall (s :: S). PLifted s (PInner wrapper))
-> Either LiftError (PlutusRepr (PInner wrapper))
forall a b. (a -> b) -> a -> b
$ PLifted s (DeriveNewtypePLiftable wrapper h)
-> PLifted s (PInner wrapper)
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
PLifted s a -> PLifted s b
punsafeCoercePLifted PLifted s (DeriveNewtypePLiftable wrapper h)
forall (s :: S). PLifted s (DeriveNewtypePLiftable wrapper h)
t
newtype PLifted (s :: S) (a :: S -> Type) = PLifted {forall (s :: S) (a :: S -> Type). PLifted s a -> Term s POpaque
unPLifted :: Term s POpaque}
type role PLifted nominal nominal
punsafeCoercePLifted :: PLifted s a -> PLifted s b
punsafeCoercePLifted :: forall (s :: S) (a :: S -> Type) (b :: S -> Type).
PLifted s a -> PLifted s b
punsafeCoercePLifted (PLifted Term s POpaque
t) = Term s POpaque -> PLifted s b
forall (s :: S) (a :: S -> Type). Term s POpaque -> PLifted s a
PLifted Term s POpaque
t
getPLifted :: PLifted s a -> Term s a
getPLifted :: forall (s :: S) (a :: S -> Type). PLifted s a -> Term s a
getPLifted (PLifted Term s POpaque
t) = Term s POpaque -> Term s a
forall (b :: S -> Type) (a :: S -> Type) (s :: S).
Term s a -> Term s b
punsafeCoerce Term s POpaque
t
mkPLifted :: Term s a -> PLifted s a
mkPLifted :: forall (s :: S) (a :: S -> Type). Term s a -> PLifted s a
mkPLifted Term s a
t = Term s POpaque -> PLifted s a
forall (s :: S) (a :: S -> Type). Term s POpaque -> PLifted s a
PLifted (Term s a -> Term s POpaque
forall (s :: S) (a :: S -> Type). Term s a -> Term s POpaque
popaque Term s a
t)
newtype PLiftedClosed (a :: S -> Type) = PLiftedClosed
{ forall (a :: S -> Type).
PLiftedClosed a -> forall (s :: S). Term s POpaque
unPLiftedClosed :: forall (s :: S). Term s POpaque
}
getPLiftedClosed ::
forall (a :: S -> Type).
PLiftedClosed a ->
(forall (s :: S). Term s a)
getPLiftedClosed :: forall (a :: S -> Type).
PLiftedClosed a -> forall (s :: S). Term s a
getPLiftedClosed (PLiftedClosed forall (s :: S). Term s POpaque
x) = Term s POpaque -> Term s a
forall (b :: S -> Type) (a :: S -> Type) (s :: S).
Term s a -> Term s b
punsafeCoerce Term s POpaque
forall (s :: S). Term s POpaque
x
mkPLiftedClosed ::
forall (a :: S -> Type).
(forall (s :: S). Term s a) ->
PLiftedClosed a
mkPLiftedClosed :: forall (a :: S -> Type).
(forall (s :: S). Term s a) -> PLiftedClosed a
mkPLiftedClosed forall (s :: S). Term s a
t = (forall (s :: S). Term s POpaque) -> PLiftedClosed a
forall (a :: S -> Type).
(forall (s :: S). Term s POpaque) -> PLiftedClosed a
PLiftedClosed ((forall (s :: S). Term s POpaque) -> PLiftedClosed a)
-> (forall (s :: S). Term s POpaque) -> PLiftedClosed a
forall a b. (a -> b) -> a -> b
$ Term s a -> Term s POpaque
forall (s :: S) (a :: S -> Type). Term s a -> Term s POpaque
popaque Term s a
forall (s :: S). Term s a
t
pliftedToClosed ::
forall (a :: S -> Type).
(forall (s :: S). PLifted s a) ->
PLiftedClosed a
pliftedToClosed :: forall (a :: S -> Type).
(forall (s :: S). PLifted s a) -> PLiftedClosed a
pliftedToClosed forall (s :: S). PLifted s a
x = (forall (s :: S). Term s POpaque) -> PLiftedClosed a
forall (a :: S -> Type).
(forall (s :: S). Term s POpaque) -> PLiftedClosed a
PLiftedClosed ((forall (s :: S). Term s POpaque) -> PLiftedClosed a)
-> (forall (s :: S). Term s POpaque) -> PLiftedClosed a
forall a b. (a -> b) -> a -> b
$ Term s a -> Term s POpaque
forall (s :: S) (a :: S -> Type). Term s a -> Term s POpaque
popaque (Term s a -> Term s POpaque) -> Term s a -> Term s POpaque
forall a b. (a -> b) -> a -> b
$ PLifted s a -> Term s a
forall (s :: S) (a :: S -> Type). PLifted s a -> Term s a
getPLifted PLifted s a
forall (s :: S). PLifted s a
x
pliftedFromClosed ::
forall (a :: S -> Type) (s :: S).
PLiftedClosed a ->
PLifted s a
pliftedFromClosed :: forall (a :: S -> Type) (s :: S). PLiftedClosed a -> PLifted s a
pliftedFromClosed (PLiftedClosed forall (s :: S). Term s POpaque
x) = Term s POpaque -> PLifted s a
forall (s :: S) (a :: S -> Type). Term s POpaque -> PLifted s a
PLifted Term s POpaque
forall (s :: S). Term s POpaque
x
deriving via
(DeriveBuiltinPLiftable PInteger Integer)
instance
PLiftable PInteger
deriving via
(DeriveBuiltinPLiftable PBool Bool)
instance
PLiftable PBool
instance
(PTx.ToData (AsHaskell a), PTx.FromData (AsHaskell a), PIsData a) =>
PLiftable (PAsData a)
where
type AsHaskell (PAsData a) = AsHaskell a
type PlutusRepr (PAsData a) = PTx.Data
{-# INLINEABLE haskToRepr #-}
haskToRepr :: AsHaskell (PAsData a) -> PlutusRepr (PAsData a)
haskToRepr = AsHaskell (PAsData a) -> Data
AsHaskell (PAsData a) -> PlutusRepr (PAsData a)
forall a. ToData a => a -> Data
PTx.toData
{-# INLINEABLE reprToHask #-}
reprToHask :: PlutusRepr (PAsData a) -> Either LiftError (AsHaskell (PAsData a))
reprToHask = Either LiftError (AsHaskell (PAsData a))
-> (AsHaskell (PAsData a)
-> Either LiftError (AsHaskell (PAsData a)))
-> Maybe (AsHaskell (PAsData a))
-> Either LiftError (AsHaskell (PAsData a))
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (LiftError -> Either LiftError (AsHaskell (PAsData a))
forall a b. a -> Either a b
Left LiftError
CouldNotDecodeData) AsHaskell (PAsData a) -> Either LiftError (AsHaskell (PAsData a))
forall a b. b -> Either a b
Right (Maybe (AsHaskell (PAsData a))
-> Either LiftError (AsHaskell (PAsData a)))
-> (Data -> Maybe (AsHaskell (PAsData a)))
-> Data
-> Either LiftError (AsHaskell (PAsData a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Data -> Maybe (AsHaskell (PAsData a))
forall a. FromData a => Data -> Maybe a
PTx.fromData
{-# INLINEABLE reprToPlut #-}
reprToPlut :: forall (s :: S). PlutusRepr (PAsData a) -> PLifted s (PAsData a)
reprToPlut = PlutusRepr (PAsData a) -> PLifted s (PAsData a)
forall (a :: S -> Type) (s :: S).
Includes @Type DefaultUni (PlutusRepr a) =>
PlutusRepr a -> PLifted s a
reprToPlutUni
{-# INLINEABLE plutToRepr #-}
plutToRepr :: (forall (s :: S). PLifted s (PAsData a))
-> Either LiftError (PlutusRepr (PAsData a))
plutToRepr = (forall (s :: S). PLifted s (PAsData a))
-> Either LiftError (PlutusRepr (PAsData a))
forall (a :: S -> Type).
KnownBuiltinType
(Term DeBruijn DefaultUni DefaultFun ()) (PlutusRepr a) =>
(forall (s :: S). PLifted s a) -> Either LiftError (PlutusRepr a)
plutToReprUni
instance
( PLiftable a
, PLC.DefaultUni `Includes` PlutusRepr a
, KnownBuiltinType (UPLC.Term UPLC.DeBruijn UPLC.DefaultUni UPLC.DefaultFun ()) (PlutusRepr a)
, PLiftable b
, PLC.DefaultUni `Includes` PlutusRepr b
, KnownBuiltinType (UPLC.Term UPLC.DeBruijn UPLC.DefaultUni UPLC.DefaultFun ()) (PlutusRepr b)
) =>
PLiftable (PBuiltinPair a b)
where
type AsHaskell (PBuiltinPair a b) = (AsHaskell a, AsHaskell b)
type PlutusRepr (PBuiltinPair a b) = (PlutusRepr a, PlutusRepr b)
{-# INLINEABLE haskToRepr #-}
haskToRepr :: AsHaskell (PBuiltinPair a b) -> PlutusRepr (PBuiltinPair a b)
haskToRepr (AsHaskell a
a, AsHaskell b
b) = (forall (a :: S -> Type). PLiftable a => AsHaskell a -> PlutusRepr a
haskToRepr @a AsHaskell a
a, forall (a :: S -> Type). PLiftable a => AsHaskell a -> PlutusRepr a
haskToRepr @b AsHaskell b
b)
{-# INLINEABLE reprToHask #-}
reprToHask :: PlutusRepr (PBuiltinPair a b)
-> Either LiftError (AsHaskell (PBuiltinPair a b))
reprToHask (PlutusRepr a
a, PlutusRepr b
b) = (,) (AsHaskell a -> AsHaskell b -> (AsHaskell a, AsHaskell b))
-> Either LiftError (AsHaskell a)
-> Either LiftError (AsHaskell b -> (AsHaskell a, AsHaskell b))
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (a :: S -> Type).
PLiftable a =>
PlutusRepr a -> Either LiftError (AsHaskell a)
reprToHask @a PlutusRepr a
a Either LiftError (AsHaskell b -> (AsHaskell a, AsHaskell b))
-> Either LiftError (AsHaskell b)
-> Either LiftError (AsHaskell a, AsHaskell b)
forall a b.
Either LiftError (a -> b)
-> Either LiftError a -> Either LiftError b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> forall (a :: S -> Type).
PLiftable a =>
PlutusRepr a -> Either LiftError (AsHaskell a)
reprToHask @b PlutusRepr b
b
{-# INLINEABLE reprToPlut #-}
reprToPlut :: forall (s :: S).
PlutusRepr (PBuiltinPair a b) -> PLifted s (PBuiltinPair a b)
reprToPlut = PlutusRepr (PBuiltinPair a b) -> PLifted s (PBuiltinPair a b)
forall (a :: S -> Type) (s :: S).
Includes @Type DefaultUni (PlutusRepr a) =>
PlutusRepr a -> PLifted s a
reprToPlutUni
{-# INLINEABLE plutToRepr #-}
plutToRepr :: (forall (s :: S). PLifted s (PBuiltinPair a b))
-> Either LiftError (PlutusRepr (PBuiltinPair a b))
plutToRepr = (forall (s :: S). PLifted s (PBuiltinPair a b))
-> Either LiftError (PlutusRepr (PBuiltinPair a b))
forall (a :: S -> Type).
KnownBuiltinType
(Term DeBruijn DefaultUni DefaultFun ()) (PlutusRepr a) =>
(forall (s :: S). PLifted s a) -> Either LiftError (PlutusRepr a)
plutToReprUni
instance
( PLiftable a
, PLC.DefaultUni `Includes` PlutusRepr a
, KnownBuiltinType (UPLC.Term UPLC.DeBruijn UPLC.DefaultUni UPLC.DefaultFun ()) (PlutusRepr a)
) =>
PLiftable (PBuiltinList a)
where
type AsHaskell (PBuiltinList a) = [AsHaskell a]
type PlutusRepr (PBuiltinList a) = [PlutusRepr a]
{-# INLINEABLE haskToRepr #-}
haskToRepr :: AsHaskell (PBuiltinList a) -> PlutusRepr (PBuiltinList a)
haskToRepr = (AsHaskell a -> PlutusRepr a) -> [AsHaskell a] -> [PlutusRepr a]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (a :: S -> Type). PLiftable a => AsHaskell a -> PlutusRepr a
haskToRepr @a)
{-# INLINEABLE reprToHask #-}
reprToHask :: PlutusRepr (PBuiltinList a)
-> Either LiftError (AsHaskell (PBuiltinList a))
reprToHask = (PlutusRepr a -> Either LiftError (AsHaskell a))
-> [PlutusRepr a] -> Either LiftError [AsHaskell a]
forall (t :: Type -> Type) (f :: Type -> Type) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse (forall (a :: S -> Type).
PLiftable a =>
PlutusRepr a -> Either LiftError (AsHaskell a)
reprToHask @a)
{-# INLINEABLE reprToPlut #-}
reprToPlut :: forall (s :: S).
PlutusRepr (PBuiltinList a) -> PLifted s (PBuiltinList a)
reprToPlut = PlutusRepr (PBuiltinList a) -> PLifted s (PBuiltinList a)
forall (a :: S -> Type) (s :: S).
Includes @Type DefaultUni (PlutusRepr a) =>
PlutusRepr a -> PLifted s a
reprToPlutUni
{-# INLINEABLE plutToRepr #-}
plutToRepr :: (forall (s :: S). PLifted s (PBuiltinList a))
-> Either LiftError (PlutusRepr (PBuiltinList a))
plutToRepr = (forall (s :: S). PLifted s (PBuiltinList a))
-> Either LiftError (PlutusRepr (PBuiltinList a))
forall (a :: S -> Type).
KnownBuiltinType
(Term DeBruijn DefaultUni DefaultFun ()) (PlutusRepr a) =>
(forall (s :: S). PLifted s a) -> Either LiftError (PlutusRepr a)
plutToReprUni
instance PLiftable PByteString where
type AsHaskell PByteString = ByteString
type PlutusRepr PByteString = ByteString
{-# INLINEABLE haskToRepr #-}
haskToRepr :: AsHaskell PByteString -> PlutusRepr PByteString
haskToRepr = AsHaskell PByteString -> PlutusRepr PByteString
AsHaskell PByteString -> AsHaskell PByteString
forall a. a -> a
id
{-# INLINEABLE reprToHask #-}
reprToHask :: PlutusRepr PByteString -> Either LiftError (AsHaskell PByteString)
reprToHask = PlutusRepr PByteString -> Either LiftError (PlutusRepr PByteString)
PlutusRepr PByteString -> Either LiftError (AsHaskell PByteString)
forall a b. b -> Either a b
Right
{-# INLINEABLE reprToPlut #-}
reprToPlut :: forall (s :: S). PlutusRepr PByteString -> PLifted s PByteString
reprToPlut = PlutusRepr PByteString -> PLifted s PByteString
forall (a :: S -> Type) (s :: S).
Includes @Type DefaultUni (PlutusRepr a) =>
PlutusRepr a -> PLifted s a
reprToPlutUni
{-# INLINEABLE plutToRepr #-}
plutToRepr :: (forall (s :: S). PLifted s PByteString)
-> Either LiftError (PlutusRepr PByteString)
plutToRepr = (forall (s :: S). PLifted s PByteString)
-> Either LiftError (PlutusRepr PByteString)
forall (a :: S -> Type).
KnownBuiltinType
(Term DeBruijn DefaultUni DefaultFun ()) (PlutusRepr a) =>
(forall (s :: S). PLifted s a) -> Either LiftError (PlutusRepr a)
plutToReprUni
instance PLiftable PData where
type AsHaskell PData = PTx.Data
type PlutusRepr PData = PTx.Data
{-# INLINEABLE haskToRepr #-}
haskToRepr :: AsHaskell PData -> PlutusRepr PData
haskToRepr = AsHaskell PData -> PlutusRepr PData
AsHaskell PData -> AsHaskell PData
forall a. a -> a
id
{-# INLINEABLE reprToHask #-}
reprToHask :: PlutusRepr PData -> Either LiftError (AsHaskell PData)
reprToHask = PlutusRepr PData -> Either LiftError (PlutusRepr PData)
PlutusRepr PData -> Either LiftError (AsHaskell PData)
forall a b. b -> Either a b
Right
{-# INLINEABLE reprToPlut #-}
reprToPlut :: forall (s :: S). PlutusRepr PData -> PLifted s PData
reprToPlut = PlutusRepr PData -> PLifted s PData
forall (a :: S -> Type) (s :: S).
Includes @Type DefaultUni (PlutusRepr a) =>
PlutusRepr a -> PLifted s a
reprToPlutUni
{-# INLINEABLE plutToRepr #-}
plutToRepr :: (forall (s :: S). PLifted s PData)
-> Either LiftError (PlutusRepr PData)
plutToRepr = (forall (s :: S). PLifted s PData)
-> Either LiftError (PlutusRepr PData)
forall (a :: S -> Type).
KnownBuiltinType
(Term DeBruijn DefaultUni DefaultFun ()) (PlutusRepr a) =>
(forall (s :: S). PLifted s a) -> Either LiftError (PlutusRepr a)
plutToReprUni
instance PLiftable PByte where
type AsHaskell PByte = Word8
type PlutusRepr PByte = Integer
{-# INLINEABLE haskToRepr #-}
haskToRepr :: AsHaskell PByte -> PlutusRepr PByte
haskToRepr = AsHaskell PByte -> PlutusRepr PByte
forall a b. (Integral a, Num b) => a -> b
fromIntegral
{-# INLINEABLE reprToHask #-}
reprToHask :: PlutusRepr PByte -> Either LiftError (AsHaskell PByte)
reprToHask = Either LiftError (AsHaskell PByte)
-> (AsHaskell PByte -> Either LiftError (AsHaskell PByte))
-> Maybe (AsHaskell PByte)
-> Either LiftError (AsHaskell PByte)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (LiftError -> Either LiftError (AsHaskell PByte)
forall a b. a -> Either a b
Left (Text -> LiftError
OtherLiftError Text
"Integral size out of range")) AsHaskell PByte -> Either LiftError (AsHaskell PByte)
forall a b. b -> Either a b
Right (Maybe (AsHaskell PByte) -> Either LiftError (AsHaskell PByte))
-> (PlutusRepr PByte -> Maybe (AsHaskell PByte))
-> PlutusRepr PByte
-> Either LiftError (AsHaskell PByte)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PlutusRepr PByte -> Maybe (AsHaskell PByte)
forall a b.
(Integral a, Integral b, Bits a, Bits b) =>
a -> Maybe b
toIntegralSized
{-# INLINEABLE reprToPlut #-}
reprToPlut :: forall (s :: S). PlutusRepr PByte -> PLifted s PByte
reprToPlut = PlutusRepr PByte -> PLifted s PByte
forall (a :: S -> Type) (s :: S).
Includes @Type DefaultUni (PlutusRepr a) =>
PlutusRepr a -> PLifted s a
reprToPlutUni
{-# INLINEABLE plutToRepr #-}
plutToRepr :: (forall (s :: S). PLifted s PByte)
-> Either LiftError (PlutusRepr PByte)
plutToRepr = (forall (s :: S). PLifted s PByte)
-> Either LiftError (PlutusRepr PByte)
forall (a :: S -> Type).
KnownBuiltinType
(Term DeBruijn DefaultUni DefaultFun ()) (PlutusRepr a) =>
(forall (s :: S). PLifted s a) -> Either LiftError (PlutusRepr a)
plutToReprUni
deriving via
(DeriveBuiltinPLiftable PUnit ())
instance
PLiftable PUnit
deriving via
(DeriveBuiltinPLiftable PString Text)
instance
PLiftable PString
deriving via
(DeriveBuiltinPLiftable PBuiltinBLS12_381_G1_Element BLS12_381.G1.Element)
instance
PLiftable PBuiltinBLS12_381_G1_Element
deriving via
(DeriveBuiltinPLiftable PBuiltinBLS12_381_G2_Element BLS12_381.G2.Element)
instance
PLiftable PBuiltinBLS12_381_G2_Element
deriving via
(DeriveBuiltinPLiftable PBuiltinBLS12_381_MlResult BLS12_381.Pairing.MlResult)
instance
PLiftable PBuiltinBLS12_381_MlResult
instance
( PLC.Contains UPLC.DefaultUni (PlutusRepr a)
, PLiftable a
, KnownBuiltinType (UPLC.Term UPLC.DeBruijn UPLC.DefaultUni UPLC.DefaultFun ()) (PlutusRepr a)
) =>
PLiftable (PArray a)
where
type AsHaskell (PArray a) = StrictVector.Vector (AsHaskell a)
type PlutusRepr (PArray a) = StrictVector.Vector (PlutusRepr a)
{-# INLINEABLE haskToRepr #-}
haskToRepr :: AsHaskell (PArray a) -> PlutusRepr (PArray a)
haskToRepr = (AsHaskell a -> PlutusRepr a)
-> Vector (AsHaskell a) -> Vector (PlutusRepr a)
forall a b. (a -> b) -> Vector a -> Vector b
StrictVector.map (forall (a :: S -> Type). PLiftable a => AsHaskell a -> PlutusRepr a
haskToRepr @a)
{-# INLINEABLE reprToHask #-}
reprToHask :: PlutusRepr (PArray a) -> Either LiftError (AsHaskell (PArray a))
reprToHask = (PlutusRepr a -> Either LiftError (AsHaskell a))
-> Vector (PlutusRepr a) -> Either LiftError (Vector (AsHaskell a))
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> Vector a -> m (Vector b)
StrictVector.mapM (forall (a :: S -> Type).
PLiftable a =>
PlutusRepr a -> Either LiftError (AsHaskell a)
reprToHask @a)
{-# INLINEABLE reprToPlut #-}
reprToPlut :: forall (s :: S). PlutusRepr (PArray a) -> PLifted s (PArray a)
reprToPlut = PlutusRepr (PArray a) -> PLifted s (PArray a)
forall (a :: S -> Type) (s :: S).
Includes @Type DefaultUni (PlutusRepr a) =>
PlutusRepr a -> PLifted s a
reprToPlutUni
{-# INLINEABLE plutToRepr #-}
plutToRepr :: (forall (s :: S). PLifted s (PArray a))
-> Either LiftError (PlutusRepr (PArray a))
plutToRepr = (forall (s :: S). PLifted s (PArray a))
-> Either LiftError (PlutusRepr (PArray a))
forall (a :: S -> Type).
KnownBuiltinType
(Term DeBruijn DefaultUni DefaultFun ()) (PlutusRepr a) =>
(forall (s :: S). PLifted s a) -> Either LiftError (PlutusRepr a)
plutToReprUni