{-# LANGUAGE DeriveAnyClass     #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE KindSignatures     #-}
{-# LANGUAGE OverloadedStrings  #-}
{-# LANGUAGE TypeApplications   #-}
-- This ensures that we don't put *anything* about these functions into the interface
-- file, otherwise GHC can be clever about the ones that are always error, even though
-- they're NOINLINE!
{-# OPTIONS_GHC -O0 #-}
-- | This module contains the special Haskell names that are used to map to builtin types or functions
-- in Plutus Core.
--
-- Most users should not use this module directly, but rather use 'PlutusTx.Builtins'.
module PlutusTx.Builtins.Internal where

import Codec.Serialise
import Control.DeepSeq (NFData (..))
import Control.Monad.Trans.Writer.Strict (runWriter)
import Crypto qualified
import Data.ByteArray qualified as BA
import Data.ByteString as BS
import Data.ByteString.Hash qualified as Hash
import Data.ByteString.Lazy as BS (toStrict)
import Data.Coerce (coerce)
import Data.Data
import Data.Foldable qualified as Foldable
import Data.Hashable (Hashable (..))
import Data.Kind (Type)
import Data.Maybe (fromMaybe)
import Data.Text as Text (Text, empty)
import Data.Text.Encoding as Text (decodeUtf8, encodeUtf8)
import PlutusCore.Builtin.Emitter (Emitter (Emitter))
import PlutusCore.Data qualified as PLC
import PlutusCore.Evaluation.Result (EvaluationResult (EvaluationFailure, EvaluationSuccess))
import PlutusTx.Utils (mustBeReplaced)
import Prettyprinter (Pretty (..), viaShow)

{-
We do not use qualified import because the whole module contains off-chain code
which is replaced later with on-chain implementations by the plutus-tx-plugin.
-}
import Prelude as Haskell

{- Note [Builtin name definitions]
The builtins here have definitions so they can be used in off-chain code too.

However they *must* be replaced by the compiler when used in Plutus Tx code, so
in particular they must *not* be inlined, otherwise we can't spot them to replace
them.
-}

{- Note [Delaying error]
The Plutus Core 'error' builtin is of type 'forall a . a', but the
one we expose here is of type 'forall a . () -> a'.

This is because it's hard to get the evaluation order right with
the non-delayed version - it's easy to end up with it getting thrown
unconditionally, or before some other effect (e.g. tracing). On the other
hand, it's much easier to work with the delayed version.

But why not just define that in the library? i.e.

    error = \_ -> Builtins.error

The answer is that GHC is eager to inline and reduce this function, which
does the Wrong Thing. We can't stop GHC doing this (at the moment), but
for most of our functions it's not a *semantic* problem. Here, however,
it is a problem. So we just expose the delayed version as the builtin.
-}

{- Note [Opaque builtin types]
We have some opaque types that we use to represent the Plutus builtin types
in Haskell.

We want them to be opaque so that our users don't do anything with them that
we can't handle, but also so that GHC doesn't look inside and try and get clever.

In particular, we need to use 'data' rather than 'newtype' even for simple wrappers,
otherwise GHC gets very keen to optimize through the newtype and e.g. our users
see 'Addr#' popping up everywhere.
-}

{-# NOINLINE error #-}
error :: BuiltinUnit -> a
error :: BuiltinUnit -> a
error = String -> BuiltinUnit -> a
forall a. String -> a
mustBeReplaced String
"error"

{-
BOOL
-}

-- See Note [Opaque builtin types]
data BuiltinBool = BuiltinBool Bool deriving stock Typeable BuiltinBool
DataType
Constr
Typeable BuiltinBool
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> BuiltinBool -> c BuiltinBool)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c BuiltinBool)
-> (BuiltinBool -> Constr)
-> (BuiltinBool -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c BuiltinBool))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c BuiltinBool))
-> ((forall b. Data b => b -> b) -> BuiltinBool -> BuiltinBool)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> BuiltinBool -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> BuiltinBool -> r)
-> (forall u. (forall d. Data d => d -> u) -> BuiltinBool -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> BuiltinBool -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> BuiltinBool -> m BuiltinBool)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> BuiltinBool -> m BuiltinBool)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> BuiltinBool -> m BuiltinBool)
-> Data BuiltinBool
BuiltinBool -> DataType
BuiltinBool -> Constr
(forall b. Data b => b -> b) -> BuiltinBool -> BuiltinBool
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinBool -> c BuiltinBool
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinBool
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> BuiltinBool -> u
forall u. (forall d. Data d => d -> u) -> BuiltinBool -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinBool -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinBool -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BuiltinBool -> m BuiltinBool
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuiltinBool -> m BuiltinBool
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinBool
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinBool -> c BuiltinBool
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BuiltinBool)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BuiltinBool)
$cBuiltinBool :: Constr
$tBuiltinBool :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> BuiltinBool -> m BuiltinBool
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuiltinBool -> m BuiltinBool
gmapMp :: (forall d. Data d => d -> m d) -> BuiltinBool -> m BuiltinBool
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuiltinBool -> m BuiltinBool
gmapM :: (forall d. Data d => d -> m d) -> BuiltinBool -> m BuiltinBool
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BuiltinBool -> m BuiltinBool
gmapQi :: Int -> (forall d. Data d => d -> u) -> BuiltinBool -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> BuiltinBool -> u
gmapQ :: (forall d. Data d => d -> u) -> BuiltinBool -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> BuiltinBool -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinBool -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinBool -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinBool -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinBool -> r
gmapT :: (forall b. Data b => b -> b) -> BuiltinBool -> BuiltinBool
$cgmapT :: (forall b. Data b => b -> b) -> BuiltinBool -> BuiltinBool
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BuiltinBool)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BuiltinBool)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c BuiltinBool)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BuiltinBool)
dataTypeOf :: BuiltinBool -> DataType
$cdataTypeOf :: BuiltinBool -> DataType
toConstr :: BuiltinBool -> Constr
$ctoConstr :: BuiltinBool -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinBool
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinBool
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinBool -> c BuiltinBool
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinBool -> c BuiltinBool
$cp1Data :: Typeable BuiltinBool
Data

{-# NOINLINE true #-}
true :: BuiltinBool
true :: BuiltinBool
true = Bool -> BuiltinBool
BuiltinBool Bool
True

{-# NOINLINE false #-}
false :: BuiltinBool
false :: BuiltinBool
false = Bool -> BuiltinBool
BuiltinBool Bool
False

{-# NOINLINE ifThenElse #-}
ifThenElse :: BuiltinBool -> a -> a -> a
ifThenElse :: BuiltinBool -> a -> a -> a
ifThenElse (BuiltinBool Bool
b) a
x a
y = if Bool
b then a
x else a
y

{-
UNIT
-}

-- See Note [Opaque builtin types]
data BuiltinUnit = BuiltinUnit () deriving stock Typeable BuiltinUnit
DataType
Constr
Typeable BuiltinUnit
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> BuiltinUnit -> c BuiltinUnit)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c BuiltinUnit)
-> (BuiltinUnit -> Constr)
-> (BuiltinUnit -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c BuiltinUnit))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c BuiltinUnit))
-> ((forall b. Data b => b -> b) -> BuiltinUnit -> BuiltinUnit)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> BuiltinUnit -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> BuiltinUnit -> r)
-> (forall u. (forall d. Data d => d -> u) -> BuiltinUnit -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> BuiltinUnit -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> BuiltinUnit -> m BuiltinUnit)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> BuiltinUnit -> m BuiltinUnit)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> BuiltinUnit -> m BuiltinUnit)
-> Data BuiltinUnit
BuiltinUnit -> DataType
BuiltinUnit -> Constr
(forall b. Data b => b -> b) -> BuiltinUnit -> BuiltinUnit
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinUnit -> c BuiltinUnit
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinUnit
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> BuiltinUnit -> u
forall u. (forall d. Data d => d -> u) -> BuiltinUnit -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinUnit -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinUnit -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BuiltinUnit -> m BuiltinUnit
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuiltinUnit -> m BuiltinUnit
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinUnit
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinUnit -> c BuiltinUnit
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BuiltinUnit)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BuiltinUnit)
$cBuiltinUnit :: Constr
$tBuiltinUnit :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> BuiltinUnit -> m BuiltinUnit
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuiltinUnit -> m BuiltinUnit
gmapMp :: (forall d. Data d => d -> m d) -> BuiltinUnit -> m BuiltinUnit
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuiltinUnit -> m BuiltinUnit
gmapM :: (forall d. Data d => d -> m d) -> BuiltinUnit -> m BuiltinUnit
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BuiltinUnit -> m BuiltinUnit
gmapQi :: Int -> (forall d. Data d => d -> u) -> BuiltinUnit -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> BuiltinUnit -> u
gmapQ :: (forall d. Data d => d -> u) -> BuiltinUnit -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> BuiltinUnit -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinUnit -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinUnit -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinUnit -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinUnit -> r
gmapT :: (forall b. Data b => b -> b) -> BuiltinUnit -> BuiltinUnit
$cgmapT :: (forall b. Data b => b -> b) -> BuiltinUnit -> BuiltinUnit
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BuiltinUnit)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BuiltinUnit)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c BuiltinUnit)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BuiltinUnit)
dataTypeOf :: BuiltinUnit -> DataType
$cdataTypeOf :: BuiltinUnit -> DataType
toConstr :: BuiltinUnit -> Constr
$ctoConstr :: BuiltinUnit -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinUnit
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinUnit
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinUnit -> c BuiltinUnit
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinUnit -> c BuiltinUnit
$cp1Data :: Typeable BuiltinUnit
Data

{-# NOINLINE unitval #-}
unitval :: BuiltinUnit
unitval :: BuiltinUnit
unitval = () -> BuiltinUnit
BuiltinUnit ()

{-# NOINLINE chooseUnit #-}
chooseUnit :: BuiltinUnit -> a -> a
chooseUnit :: BuiltinUnit -> a -> a
chooseUnit (BuiltinUnit ()) a
a = a
a

{-
INTEGER
-}

-- I'm somewhat surprised that this works despite not being opaque! GHC doesn't seem to
-- mess with 'Integer', which is suspicious to me. Probably we *should* make 'BuiltinInteger'
-- opaque, but that's going to really mess with our users' code...
type BuiltinInteger = Integer

{-# NOINLINE addInteger #-}
addInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinInteger
addInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinInteger
addInteger = (BuiltinInteger -> BuiltinInteger -> BuiltinInteger)
-> BuiltinInteger -> BuiltinInteger -> BuiltinInteger
coerce (Num BuiltinInteger =>
BuiltinInteger -> BuiltinInteger -> BuiltinInteger
forall a. Num a => a -> a -> a
(+) @Integer)

{-# NOINLINE subtractInteger #-}
subtractInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinInteger
subtractInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinInteger
subtractInteger = (BuiltinInteger -> BuiltinInteger -> BuiltinInteger)
-> BuiltinInteger -> BuiltinInteger -> BuiltinInteger
coerce ((-) @Integer)

{-# NOINLINE multiplyInteger #-}
multiplyInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinInteger
multiplyInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinInteger
multiplyInteger = (BuiltinInteger -> BuiltinInteger -> BuiltinInteger)
-> BuiltinInteger -> BuiltinInteger -> BuiltinInteger
coerce (Num BuiltinInteger =>
BuiltinInteger -> BuiltinInteger -> BuiltinInteger
forall a. Num a => a -> a -> a
(*) @Integer)

{-# NOINLINE divideInteger #-}
divideInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinInteger
divideInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinInteger
divideInteger = (BuiltinInteger -> BuiltinInteger -> BuiltinInteger)
-> BuiltinInteger -> BuiltinInteger -> BuiltinInteger
coerce (Integral BuiltinInteger =>
BuiltinInteger -> BuiltinInteger -> BuiltinInteger
forall a. Integral a => a -> a -> a
div @Integer)

{-# NOINLINE modInteger #-}
modInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinInteger
modInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinInteger
modInteger = (BuiltinInteger -> BuiltinInteger -> BuiltinInteger)
-> BuiltinInteger -> BuiltinInteger -> BuiltinInteger
coerce (Integral BuiltinInteger =>
BuiltinInteger -> BuiltinInteger -> BuiltinInteger
forall a. Integral a => a -> a -> a
mod @Integer)

{-# NOINLINE quotientInteger #-}
quotientInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinInteger
quotientInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinInteger
quotientInteger = (BuiltinInteger -> BuiltinInteger -> BuiltinInteger)
-> BuiltinInteger -> BuiltinInteger -> BuiltinInteger
coerce (Integral BuiltinInteger =>
BuiltinInteger -> BuiltinInteger -> BuiltinInteger
forall a. Integral a => a -> a -> a
quot @Integer)

{-# NOINLINE remainderInteger #-}
remainderInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinInteger
remainderInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinInteger
remainderInteger = (BuiltinInteger -> BuiltinInteger -> BuiltinInteger)
-> BuiltinInteger -> BuiltinInteger -> BuiltinInteger
coerce (Integral BuiltinInteger =>
BuiltinInteger -> BuiltinInteger -> BuiltinInteger
forall a. Integral a => a -> a -> a
rem @Integer)

{-# NOINLINE lessThanInteger #-}
lessThanInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinBool
lessThanInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinBool
lessThanInteger BuiltinInteger
x BuiltinInteger
y = Bool -> BuiltinBool
BuiltinBool (Bool -> BuiltinBool) -> Bool -> BuiltinBool
forall a b. (a -> b) -> a -> b
$ (BuiltinInteger -> BuiltinInteger -> Bool)
-> BuiltinInteger -> BuiltinInteger -> Bool
coerce (Ord BuiltinInteger => BuiltinInteger -> BuiltinInteger -> Bool
forall a. Ord a => a -> a -> Bool
(<) @Integer) BuiltinInteger
x  BuiltinInteger
y

{-# NOINLINE lessThanEqualsInteger #-}
lessThanEqualsInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinBool
lessThanEqualsInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinBool
lessThanEqualsInteger BuiltinInteger
x BuiltinInteger
y = Bool -> BuiltinBool
BuiltinBool (Bool -> BuiltinBool) -> Bool -> BuiltinBool
forall a b. (a -> b) -> a -> b
$ (BuiltinInteger -> BuiltinInteger -> Bool)
-> BuiltinInteger -> BuiltinInteger -> Bool
coerce (Ord BuiltinInteger => BuiltinInteger -> BuiltinInteger -> Bool
forall a. Ord a => a -> a -> Bool
(<=) @Integer) BuiltinInteger
x BuiltinInteger
y

{-# NOINLINE equalsInteger #-}
equalsInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinBool
equalsInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinBool
equalsInteger BuiltinInteger
x BuiltinInteger
y = Bool -> BuiltinBool
BuiltinBool (Bool -> BuiltinBool) -> Bool -> BuiltinBool
forall a b. (a -> b) -> a -> b
$ (BuiltinInteger -> BuiltinInteger -> Bool)
-> BuiltinInteger -> BuiltinInteger -> Bool
coerce (Eq BuiltinInteger => BuiltinInteger -> BuiltinInteger -> Bool
forall a. Eq a => a -> a -> Bool
(==) @Integer) BuiltinInteger
x BuiltinInteger
y

{-
BYTESTRING
-}

-- See Note [Opaque builtin types]
-- | An opaque type representing Plutus Core ByteStrings.
data BuiltinByteString = BuiltinByteString ByteString deriving stock Typeable BuiltinByteString
DataType
Constr
Typeable BuiltinByteString
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g)
    -> BuiltinByteString
    -> c BuiltinByteString)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c BuiltinByteString)
-> (BuiltinByteString -> Constr)
-> (BuiltinByteString -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c BuiltinByteString))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c BuiltinByteString))
-> ((forall b. Data b => b -> b)
    -> BuiltinByteString -> BuiltinByteString)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> BuiltinByteString -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> BuiltinByteString -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> BuiltinByteString -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> BuiltinByteString -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> BuiltinByteString -> m BuiltinByteString)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> BuiltinByteString -> m BuiltinByteString)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> BuiltinByteString -> m BuiltinByteString)
-> Data BuiltinByteString
BuiltinByteString -> DataType
BuiltinByteString -> Constr
(forall b. Data b => b -> b)
-> BuiltinByteString -> BuiltinByteString
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinByteString -> c BuiltinByteString
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinByteString
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> BuiltinByteString -> u
forall u. (forall d. Data d => d -> u) -> BuiltinByteString -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinByteString -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinByteString -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> BuiltinByteString -> m BuiltinByteString
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> BuiltinByteString -> m BuiltinByteString
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinByteString
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinByteString -> c BuiltinByteString
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BuiltinByteString)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BuiltinByteString)
$cBuiltinByteString :: Constr
$tBuiltinByteString :: DataType
gmapMo :: (forall d. Data d => d -> m d)
-> BuiltinByteString -> m BuiltinByteString
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> BuiltinByteString -> m BuiltinByteString
gmapMp :: (forall d. Data d => d -> m d)
-> BuiltinByteString -> m BuiltinByteString
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> BuiltinByteString -> m BuiltinByteString
gmapM :: (forall d. Data d => d -> m d)
-> BuiltinByteString -> m BuiltinByteString
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> BuiltinByteString -> m BuiltinByteString
gmapQi :: Int -> (forall d. Data d => d -> u) -> BuiltinByteString -> u
$cgmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> BuiltinByteString -> u
gmapQ :: (forall d. Data d => d -> u) -> BuiltinByteString -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> BuiltinByteString -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinByteString -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinByteString -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinByteString -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinByteString -> r
gmapT :: (forall b. Data b => b -> b)
-> BuiltinByteString -> BuiltinByteString
$cgmapT :: (forall b. Data b => b -> b)
-> BuiltinByteString -> BuiltinByteString
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BuiltinByteString)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BuiltinByteString)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c BuiltinByteString)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BuiltinByteString)
dataTypeOf :: BuiltinByteString -> DataType
$cdataTypeOf :: BuiltinByteString -> DataType
toConstr :: BuiltinByteString -> Constr
$ctoConstr :: BuiltinByteString -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinByteString
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinByteString
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinByteString -> c BuiltinByteString
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinByteString -> c BuiltinByteString
$cp1Data :: Typeable BuiltinByteString
Data

instance Haskell.Show BuiltinByteString where
    show :: BuiltinByteString -> String
show (BuiltinByteString ByteString
bs) = ByteString -> String
forall a. Show a => a -> String
show ByteString
bs
instance Haskell.Eq BuiltinByteString where
    == :: BuiltinByteString -> BuiltinByteString -> Bool
(==) (BuiltinByteString ByteString
bs) (BuiltinByteString ByteString
bs') = ByteString -> ByteString -> Bool
forall a. Eq a => a -> a -> Bool
(==) ByteString
bs ByteString
bs'
instance Haskell.Ord BuiltinByteString where
    compare :: BuiltinByteString -> BuiltinByteString -> Ordering
compare (BuiltinByteString ByteString
bs) (BuiltinByteString ByteString
bs') = ByteString -> ByteString -> Ordering
forall a. Ord a => a -> a -> Ordering
compare ByteString
bs ByteString
bs'
instance Haskell.Semigroup BuiltinByteString where
    <> :: BuiltinByteString -> BuiltinByteString -> BuiltinByteString
(<>) (BuiltinByteString ByteString
bs) (BuiltinByteString ByteString
bs') = ByteString -> BuiltinByteString
BuiltinByteString (ByteString -> BuiltinByteString)
-> ByteString -> BuiltinByteString
forall a b. (a -> b) -> a -> b
$ ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
(<>) ByteString
bs ByteString
bs'
instance Haskell.Monoid BuiltinByteString where
    mempty :: BuiltinByteString
mempty = ByteString -> BuiltinByteString
BuiltinByteString ByteString
forall a. Monoid a => a
mempty
instance Hashable BuiltinByteString where
    hashWithSalt :: Int -> BuiltinByteString -> Int
hashWithSalt Int
s (BuiltinByteString ByteString
bs )= Int -> ByteString -> Int
forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
s ByteString
bs
instance Serialise BuiltinByteString where
    encode :: BuiltinByteString -> Encoding
encode (BuiltinByteString ByteString
bs) = ByteString -> Encoding
forall a. Serialise a => a -> Encoding
encode ByteString
bs
    decode :: Decoder s BuiltinByteString
decode = ByteString -> BuiltinByteString
BuiltinByteString (ByteString -> BuiltinByteString)
-> Decoder s ByteString -> Decoder s BuiltinByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s ByteString
forall a s. Serialise a => Decoder s a
decode
instance NFData BuiltinByteString where
    rnf :: BuiltinByteString -> ()
rnf (BuiltinByteString ByteString
bs) = ByteString -> ()
forall a. NFData a => a -> ()
rnf ByteString
bs
instance BA.ByteArrayAccess BuiltinByteString where
    length :: BuiltinByteString -> Int
length (BuiltinByteString ByteString
bs) = ByteString -> Int
forall ba. ByteArrayAccess ba => ba -> Int
BA.length ByteString
bs
    withByteArray :: BuiltinByteString -> (Ptr p -> IO a) -> IO a
withByteArray (BuiltinByteString ByteString
bs) = ByteString -> (Ptr p -> IO a) -> IO a
forall ba p a. ByteArrayAccess ba => ba -> (Ptr p -> IO a) -> IO a
BA.withByteArray ByteString
bs
instance BA.ByteArray BuiltinByteString where
    allocRet :: Int -> (Ptr p -> IO a) -> IO (a, BuiltinByteString)
allocRet Int
i Ptr p -> IO a
p = ((a, ByteString) -> (a, BuiltinByteString))
-> IO (a, ByteString) -> IO (a, BuiltinByteString)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((ByteString -> BuiltinByteString)
-> (a, ByteString) -> (a, BuiltinByteString)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> BuiltinByteString
BuiltinByteString) (IO (a, ByteString) -> IO (a, BuiltinByteString))
-> IO (a, ByteString) -> IO (a, BuiltinByteString)
forall a b. (a -> b) -> a -> b
$ Int -> (Ptr p -> IO a) -> IO (a, ByteString)
forall ba p a. ByteArray ba => Int -> (Ptr p -> IO a) -> IO (a, ba)
BA.allocRet Int
i Ptr p -> IO a
p

instance Pretty BuiltinByteString where
    pretty :: BuiltinByteString -> Doc ann
pretty = BuiltinByteString -> Doc ann
forall a ann. Show a => a -> Doc ann
viaShow

{-# NOINLINE appendByteString #-}
appendByteString :: BuiltinByteString -> BuiltinByteString -> BuiltinByteString
appendByteString :: BuiltinByteString -> BuiltinByteString -> BuiltinByteString
appendByteString (BuiltinByteString ByteString
b1) (BuiltinByteString ByteString
b2) = ByteString -> BuiltinByteString
BuiltinByteString (ByteString -> BuiltinByteString)
-> ByteString -> BuiltinByteString
forall a b. (a -> b) -> a -> b
$ ByteString -> ByteString -> ByteString
BS.append ByteString
b1 ByteString
b2

{-# NOINLINE consByteString #-}
consByteString :: BuiltinInteger -> BuiltinByteString -> BuiltinByteString
consByteString :: BuiltinInteger -> BuiltinByteString -> BuiltinByteString
consByteString BuiltinInteger
n (BuiltinByteString ByteString
b) = ByteString -> BuiltinByteString
BuiltinByteString (ByteString -> BuiltinByteString)
-> ByteString -> BuiltinByteString
forall a b. (a -> b) -> a -> b
$ Word8 -> ByteString -> ByteString
BS.cons (BuiltinInteger -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral BuiltinInteger
n) ByteString
b

{-# NOINLINE sliceByteString #-}
sliceByteString :: BuiltinInteger -> BuiltinInteger -> BuiltinByteString -> BuiltinByteString
sliceByteString :: BuiltinInteger
-> BuiltinInteger -> BuiltinByteString -> BuiltinByteString
sliceByteString BuiltinInteger
start BuiltinInteger
n (BuiltinByteString ByteString
b) = ByteString -> BuiltinByteString
BuiltinByteString (ByteString -> BuiltinByteString)
-> ByteString -> BuiltinByteString
forall a b. (a -> b) -> a -> b
$ Int -> ByteString -> ByteString
BS.take (BuiltinInteger -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral BuiltinInteger
n) (Int -> ByteString -> ByteString
BS.drop (BuiltinInteger -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral BuiltinInteger
start) ByteString
b)

{-# NOINLINE lengthOfByteString #-}
lengthOfByteString :: BuiltinByteString -> BuiltinInteger
lengthOfByteString :: BuiltinByteString -> BuiltinInteger
lengthOfByteString (BuiltinByteString ByteString
b) = Int -> BuiltinInteger
forall a. Integral a => a -> BuiltinInteger
toInteger (Int -> BuiltinInteger) -> Int -> BuiltinInteger
forall a b. (a -> b) -> a -> b
$ ByteString -> Int
BS.length ByteString
b

{-# NOINLINE indexByteString #-}
indexByteString :: BuiltinByteString -> BuiltinInteger -> BuiltinInteger
indexByteString :: BuiltinByteString -> BuiltinInteger -> BuiltinInteger
indexByteString (BuiltinByteString ByteString
b) BuiltinInteger
i = Word8 -> BuiltinInteger
forall a. Integral a => a -> BuiltinInteger
toInteger (Word8 -> BuiltinInteger) -> Word8 -> BuiltinInteger
forall a b. (a -> b) -> a -> b
$ ByteString -> Int -> Word8
BS.index ByteString
b (BuiltinInteger -> Int
forall a. Num a => BuiltinInteger -> a
fromInteger BuiltinInteger
i)

{-# NOINLINE emptyByteString #-}
emptyByteString :: BuiltinByteString
emptyByteString :: BuiltinByteString
emptyByteString = ByteString -> BuiltinByteString
BuiltinByteString ByteString
BS.empty

{-# NOINLINE sha2_256 #-}
sha2_256 :: BuiltinByteString -> BuiltinByteString
sha2_256 :: BuiltinByteString -> BuiltinByteString
sha2_256 (BuiltinByteString ByteString
b) = ByteString -> BuiltinByteString
BuiltinByteString (ByteString -> BuiltinByteString)
-> ByteString -> BuiltinByteString
forall a b. (a -> b) -> a -> b
$ ByteString -> ByteString
Hash.sha2_256 ByteString
b

{-# NOINLINE sha3_256 #-}
sha3_256 :: BuiltinByteString -> BuiltinByteString
sha3_256 :: BuiltinByteString -> BuiltinByteString
sha3_256 (BuiltinByteString ByteString
b) = ByteString -> BuiltinByteString
BuiltinByteString (ByteString -> BuiltinByteString)
-> ByteString -> BuiltinByteString
forall a b. (a -> b) -> a -> b
$ ByteString -> ByteString
Hash.sha3_256 ByteString
b

{-# NOINLINE blake2b_256 #-}
blake2b_256 :: BuiltinByteString -> BuiltinByteString
blake2b_256 :: BuiltinByteString -> BuiltinByteString
blake2b_256 (BuiltinByteString ByteString
b) = ByteString -> BuiltinByteString
BuiltinByteString (ByteString -> BuiltinByteString)
-> ByteString -> BuiltinByteString
forall a b. (a -> b) -> a -> b
$ ByteString -> ByteString
Hash.blake2b_256 ByteString
b

{-# NOINLINE verifyEd25519Signature #-}
verifyEd25519Signature :: BuiltinByteString -> BuiltinByteString -> BuiltinByteString -> BuiltinBool
verifyEd25519Signature :: BuiltinByteString
-> BuiltinByteString -> BuiltinByteString -> BuiltinBool
verifyEd25519Signature (BuiltinByteString ByteString
pubKey) (BuiltinByteString ByteString
message) (BuiltinByteString ByteString
signature) =
  Bool -> BuiltinBool
BuiltinBool (Bool -> Maybe Bool -> Bool
forall a. a -> Maybe a -> a
fromMaybe Bool
False (ByteString -> ByteString -> ByteString -> Maybe Bool
forall (f :: * -> *).
Alternative f =>
ByteString -> ByteString -> ByteString -> f Bool
Crypto.verifyEd25519Signature ByteString
pubKey ByteString
message ByteString
signature))

{-# NOINLINE verifyEcdsaSecp256k1Signature #-}
verifyEcdsaSecp256k1Signature ::
  BuiltinByteString ->
  BuiltinByteString ->
  BuiltinByteString ->
  BuiltinBool
verifyEcdsaSecp256k1Signature :: BuiltinByteString
-> BuiltinByteString -> BuiltinByteString -> BuiltinBool
verifyEcdsaSecp256k1Signature (BuiltinByteString ByteString
vk) (BuiltinByteString ByteString
msg) (BuiltinByteString ByteString
sig) =
  case ByteString
-> ByteString -> ByteString -> Emitter (EvaluationResult Bool)
Crypto.verifyEcdsaSecp256k1Signature ByteString
vk ByteString
msg ByteString
sig of
    Emitter Writer (DList Text) (EvaluationResult Bool)
f -> case Writer (DList Text) (EvaluationResult Bool)
-> (EvaluationResult Bool, DList Text)
forall w a. Writer w a -> (a, w)
runWriter Writer (DList Text) (EvaluationResult Bool)
f of
      (EvaluationResult Bool
res, DList Text
logs) -> DList Text -> BuiltinBool -> BuiltinBool
forall a (f :: * -> *). Foldable f => f Text -> a -> a
traceAll DList Text
logs (BuiltinBool -> BuiltinBool) -> BuiltinBool -> BuiltinBool
forall a b. (a -> b) -> a -> b
$ case EvaluationResult Bool
res of
        EvaluationResult Bool
EvaluationFailure   -> String -> BuiltinBool
forall a. String -> a
mustBeReplaced String
"ECDSA SECP256k1 signature verification errored."
        EvaluationSuccess Bool
b -> Bool -> BuiltinBool
BuiltinBool Bool
b

{-# NOINLINE verifySchnorrSecp256k1Signature #-}
verifySchnorrSecp256k1Signature ::
  BuiltinByteString ->
  BuiltinByteString ->
  BuiltinByteString ->
  BuiltinBool
verifySchnorrSecp256k1Signature :: BuiltinByteString
-> BuiltinByteString -> BuiltinByteString -> BuiltinBool
verifySchnorrSecp256k1Signature (BuiltinByteString ByteString
vk) (BuiltinByteString ByteString
msg) (BuiltinByteString ByteString
sig) =
  case ByteString
-> ByteString -> ByteString -> Emitter (EvaluationResult Bool)
Crypto.verifySchnorrSecp256k1Signature ByteString
vk ByteString
msg ByteString
sig of
    Emitter Writer (DList Text) (EvaluationResult Bool)
f -> case Writer (DList Text) (EvaluationResult Bool)
-> (EvaluationResult Bool, DList Text)
forall w a. Writer w a -> (a, w)
runWriter Writer (DList Text) (EvaluationResult Bool)
f of
      (EvaluationResult Bool
res, DList Text
logs) -> DList Text -> BuiltinBool -> BuiltinBool
forall a (f :: * -> *). Foldable f => f Text -> a -> a
traceAll DList Text
logs (BuiltinBool -> BuiltinBool) -> BuiltinBool -> BuiltinBool
forall a b. (a -> b) -> a -> b
$ case EvaluationResult Bool
res of
        EvaluationResult Bool
EvaluationFailure   -> String -> BuiltinBool
forall a. String -> a
mustBeReplaced String
"Schnorr SECP256k1 signature verification errored."
        EvaluationSuccess Bool
b -> Bool -> BuiltinBool
BuiltinBool Bool
b

traceAll :: forall (a :: Type) (f :: Type -> Type) .
  (Foldable f) => f Text -> a -> a
traceAll :: f Text -> a -> a
traceAll f Text
logs a
x = (a -> Text -> a) -> a -> f Text -> a
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
Foldable.foldl' (\a
acc Text
t -> BuiltinString -> a -> a
forall a. BuiltinString -> a -> a
trace (Text -> BuiltinString
BuiltinString Text
t) a
acc) a
x f Text
logs

{-# NOINLINE equalsByteString #-}
equalsByteString :: BuiltinByteString -> BuiltinByteString -> BuiltinBool
equalsByteString :: BuiltinByteString -> BuiltinByteString -> BuiltinBool
equalsByteString (BuiltinByteString ByteString
b1) (BuiltinByteString ByteString
b2) = Bool -> BuiltinBool
BuiltinBool (Bool -> BuiltinBool) -> Bool -> BuiltinBool
forall a b. (a -> b) -> a -> b
$ ByteString
b1 ByteString -> ByteString -> Bool
forall a. Eq a => a -> a -> Bool
== ByteString
b2

{-# NOINLINE lessThanByteString #-}
lessThanByteString :: BuiltinByteString -> BuiltinByteString -> BuiltinBool
lessThanByteString :: BuiltinByteString -> BuiltinByteString -> BuiltinBool
lessThanByteString (BuiltinByteString ByteString
b1) (BuiltinByteString ByteString
b2) = Bool -> BuiltinBool
BuiltinBool (Bool -> BuiltinBool) -> Bool -> BuiltinBool
forall a b. (a -> b) -> a -> b
$ ByteString
b1 ByteString -> ByteString -> Bool
forall a. Ord a => a -> a -> Bool
< ByteString
b2

{-# NOINLINE lessThanEqualsByteString #-}
lessThanEqualsByteString :: BuiltinByteString -> BuiltinByteString -> BuiltinBool
lessThanEqualsByteString :: BuiltinByteString -> BuiltinByteString -> BuiltinBool
lessThanEqualsByteString (BuiltinByteString ByteString
b1) (BuiltinByteString ByteString
b2) = Bool -> BuiltinBool
BuiltinBool (Bool -> BuiltinBool) -> Bool -> BuiltinBool
forall a b. (a -> b) -> a -> b
$ ByteString
b1 ByteString -> ByteString -> Bool
forall a. Ord a => a -> a -> Bool
<= ByteString
b2

{-# NOINLINE decodeUtf8 #-}
decodeUtf8 :: BuiltinByteString -> BuiltinString
decodeUtf8 :: BuiltinByteString -> BuiltinString
decodeUtf8 (BuiltinByteString ByteString
b) = Text -> BuiltinString
BuiltinString (Text -> BuiltinString) -> Text -> BuiltinString
forall a b. (a -> b) -> a -> b
$ ByteString -> Text
Text.decodeUtf8 ByteString
b

{-
STRING
-}

-- See Note [Opaque builtin types]
data BuiltinString = BuiltinString Text deriving stock Typeable BuiltinString
DataType
Constr
Typeable BuiltinString
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> BuiltinString -> c BuiltinString)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c BuiltinString)
-> (BuiltinString -> Constr)
-> (BuiltinString -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c BuiltinString))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c BuiltinString))
-> ((forall b. Data b => b -> b) -> BuiltinString -> BuiltinString)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> BuiltinString -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> BuiltinString -> r)
-> (forall u. (forall d. Data d => d -> u) -> BuiltinString -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> BuiltinString -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> BuiltinString -> m BuiltinString)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> BuiltinString -> m BuiltinString)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> BuiltinString -> m BuiltinString)
-> Data BuiltinString
BuiltinString -> DataType
BuiltinString -> Constr
(forall b. Data b => b -> b) -> BuiltinString -> BuiltinString
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinString -> c BuiltinString
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinString
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> BuiltinString -> u
forall u. (forall d. Data d => d -> u) -> BuiltinString -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinString -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinString -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BuiltinString -> m BuiltinString
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuiltinString -> m BuiltinString
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinString
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinString -> c BuiltinString
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BuiltinString)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BuiltinString)
$cBuiltinString :: Constr
$tBuiltinString :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> BuiltinString -> m BuiltinString
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuiltinString -> m BuiltinString
gmapMp :: (forall d. Data d => d -> m d) -> BuiltinString -> m BuiltinString
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuiltinString -> m BuiltinString
gmapM :: (forall d. Data d => d -> m d) -> BuiltinString -> m BuiltinString
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BuiltinString -> m BuiltinString
gmapQi :: Int -> (forall d. Data d => d -> u) -> BuiltinString -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> BuiltinString -> u
gmapQ :: (forall d. Data d => d -> u) -> BuiltinString -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> BuiltinString -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinString -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinString -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinString -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinString -> r
gmapT :: (forall b. Data b => b -> b) -> BuiltinString -> BuiltinString
$cgmapT :: (forall b. Data b => b -> b) -> BuiltinString -> BuiltinString
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BuiltinString)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BuiltinString)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c BuiltinString)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BuiltinString)
dataTypeOf :: BuiltinString -> DataType
$cdataTypeOf :: BuiltinString -> DataType
toConstr :: BuiltinString -> Constr
$ctoConstr :: BuiltinString -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinString
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinString
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinString -> c BuiltinString
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinString -> c BuiltinString
$cp1Data :: Typeable BuiltinString
Data

instance Haskell.Show BuiltinString where
    show :: BuiltinString -> String
show (BuiltinString Text
t) = Text -> String
forall a. Show a => a -> String
show Text
t
instance Haskell.Eq BuiltinString where
    == :: BuiltinString -> BuiltinString -> Bool
(==) (BuiltinString Text
t) (BuiltinString Text
t') = Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
(==) Text
t Text
t'
instance Haskell.Ord BuiltinString where
    compare :: BuiltinString -> BuiltinString -> Ordering
compare (BuiltinString Text
t) (BuiltinString Text
t') = Text -> Text -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Text
t Text
t'

{-# NOINLINE appendString #-}
appendString :: BuiltinString -> BuiltinString -> BuiltinString
appendString :: BuiltinString -> BuiltinString -> BuiltinString
appendString (BuiltinString Text
s1) (BuiltinString Text
s2) = Text -> BuiltinString
BuiltinString (Text
s1 Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
s2)

{-# NOINLINE emptyString #-}
emptyString :: BuiltinString
emptyString :: BuiltinString
emptyString = Text -> BuiltinString
BuiltinString Text
Text.empty

{-# NOINLINE equalsString #-}
equalsString :: BuiltinString -> BuiltinString -> BuiltinBool
equalsString :: BuiltinString -> BuiltinString -> BuiltinBool
equalsString (BuiltinString Text
s1) (BuiltinString Text
s2) = Bool -> BuiltinBool
BuiltinBool (Bool -> BuiltinBool) -> Bool -> BuiltinBool
forall a b. (a -> b) -> a -> b
$ Text
s1 Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
s2

{-# NOINLINE trace #-}
trace :: BuiltinString -> a -> a
trace :: BuiltinString -> a -> a
trace BuiltinString
_ a
x = a
x

{-# NOINLINE encodeUtf8 #-}
encodeUtf8 :: BuiltinString -> BuiltinByteString
encodeUtf8 :: BuiltinString -> BuiltinByteString
encodeUtf8 (BuiltinString Text
s) = ByteString -> BuiltinByteString
BuiltinByteString (ByteString -> BuiltinByteString)
-> ByteString -> BuiltinByteString
forall a b. (a -> b) -> a -> b
$ Text -> ByteString
Text.encodeUtf8 Text
s

{-
PAIR
-}

-- See Note [Opaque builtin types]
data BuiltinPair a b = BuiltinPair (a, b) deriving stock Typeable (BuiltinPair a b)
DataType
Constr
Typeable (BuiltinPair a b)
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> BuiltinPair a b -> c (BuiltinPair a b))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (BuiltinPair a b))
-> (BuiltinPair a b -> Constr)
-> (BuiltinPair a b -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (BuiltinPair a b)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (BuiltinPair a b)))
-> ((forall b. Data b => b -> b)
    -> BuiltinPair a b -> BuiltinPair a b)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> BuiltinPair a b -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> BuiltinPair a b -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> BuiltinPair a b -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> BuiltinPair a b -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> BuiltinPair a b -> m (BuiltinPair a b))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> BuiltinPair a b -> m (BuiltinPair a b))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> BuiltinPair a b -> m (BuiltinPair a b))
-> Data (BuiltinPair a b)
BuiltinPair a b -> DataType
BuiltinPair a b -> Constr
(forall b. Data b => b -> b) -> BuiltinPair a b -> BuiltinPair a b
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinPair a b -> c (BuiltinPair a b)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (BuiltinPair a b)
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (BuiltinPair a b))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> BuiltinPair a b -> u
forall u. (forall d. Data d => d -> u) -> BuiltinPair a b -> [u]
forall a b. (Data a, Data b) => Typeable (BuiltinPair a b)
forall a b. (Data a, Data b) => BuiltinPair a b -> DataType
forall a b. (Data a, Data b) => BuiltinPair a b -> Constr
forall a b.
(Data a, Data b) =>
(forall b. Data b => b -> b) -> BuiltinPair a b -> BuiltinPair a b
forall a b u.
(Data a, Data b) =>
Int -> (forall d. Data d => d -> u) -> BuiltinPair a b -> u
forall a b u.
(Data a, Data b) =>
(forall d. Data d => d -> u) -> BuiltinPair a b -> [u]
forall a b r r'.
(Data a, Data b) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinPair a b -> r
forall a b r r'.
(Data a, Data b) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinPair a b -> r
forall a b (m :: * -> *).
(Data a, Data b, Monad m) =>
(forall d. Data d => d -> m d)
-> BuiltinPair a b -> m (BuiltinPair a b)
forall a b (m :: * -> *).
(Data a, Data b, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> BuiltinPair a b -> m (BuiltinPair a b)
forall a b (c :: * -> *).
(Data a, Data b) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (BuiltinPair a b)
forall a b (c :: * -> *).
(Data a, Data b) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinPair a b -> c (BuiltinPair a b)
forall a b (t :: * -> *) (c :: * -> *).
(Data a, Data b, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (BuiltinPair a b))
forall a b (t :: * -> * -> *) (c :: * -> *).
(Data a, Data b, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (BuiltinPair a b))
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinPair a b -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinPair a b -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> BuiltinPair a b -> m (BuiltinPair a b)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> BuiltinPair a b -> m (BuiltinPair a b)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (BuiltinPair a b)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinPair a b -> c (BuiltinPair a b)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (BuiltinPair a b))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (BuiltinPair a b))
$cBuiltinPair :: Constr
$tBuiltinPair :: DataType
gmapMo :: (forall d. Data d => d -> m d)
-> BuiltinPair a b -> m (BuiltinPair a b)
$cgmapMo :: forall a b (m :: * -> *).
(Data a, Data b, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> BuiltinPair a b -> m (BuiltinPair a b)
gmapMp :: (forall d. Data d => d -> m d)
-> BuiltinPair a b -> m (BuiltinPair a b)
$cgmapMp :: forall a b (m :: * -> *).
(Data a, Data b, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> BuiltinPair a b -> m (BuiltinPair a b)
gmapM :: (forall d. Data d => d -> m d)
-> BuiltinPair a b -> m (BuiltinPair a b)
$cgmapM :: forall a b (m :: * -> *).
(Data a, Data b, Monad m) =>
(forall d. Data d => d -> m d)
-> BuiltinPair a b -> m (BuiltinPair a b)
gmapQi :: Int -> (forall d. Data d => d -> u) -> BuiltinPair a b -> u
$cgmapQi :: forall a b u.
(Data a, Data b) =>
Int -> (forall d. Data d => d -> u) -> BuiltinPair a b -> u
gmapQ :: (forall d. Data d => d -> u) -> BuiltinPair a b -> [u]
$cgmapQ :: forall a b u.
(Data a, Data b) =>
(forall d. Data d => d -> u) -> BuiltinPair a b -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinPair a b -> r
$cgmapQr :: forall a b r r'.
(Data a, Data b) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinPair a b -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinPair a b -> r
$cgmapQl :: forall a b r r'.
(Data a, Data b) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinPair a b -> r
gmapT :: (forall b. Data b => b -> b) -> BuiltinPair a b -> BuiltinPair a b
$cgmapT :: forall a b.
(Data a, Data b) =>
(forall b. Data b => b -> b) -> BuiltinPair a b -> BuiltinPair a b
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (BuiltinPair a b))
$cdataCast2 :: forall a b (t :: * -> * -> *) (c :: * -> *).
(Data a, Data b, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (BuiltinPair a b))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (BuiltinPair a b))
$cdataCast1 :: forall a b (t :: * -> *) (c :: * -> *).
(Data a, Data b, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (BuiltinPair a b))
dataTypeOf :: BuiltinPair a b -> DataType
$cdataTypeOf :: forall a b. (Data a, Data b) => BuiltinPair a b -> DataType
toConstr :: BuiltinPair a b -> Constr
$ctoConstr :: forall a b. (Data a, Data b) => BuiltinPair a b -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (BuiltinPair a b)
$cgunfold :: forall a b (c :: * -> *).
(Data a, Data b) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (BuiltinPair a b)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinPair a b -> c (BuiltinPair a b)
$cgfoldl :: forall a b (c :: * -> *).
(Data a, Data b) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinPair a b -> c (BuiltinPair a b)
$cp1Data :: forall a b. (Data a, Data b) => Typeable (BuiltinPair a b)
Data

instance (Haskell.Show a, Haskell.Show b) => Haskell.Show (BuiltinPair a b) where
    show :: BuiltinPair a b -> String
show (BuiltinPair (a, b)
p) = (a, b) -> String
forall a. Show a => a -> String
show (a, b)
p
instance (Haskell.Eq a, Haskell.Eq b) => Haskell.Eq (BuiltinPair a b) where
    == :: BuiltinPair a b -> BuiltinPair a b -> Bool
(==) (BuiltinPair (a, b)
p) (BuiltinPair (a, b)
p') = (a, b) -> (a, b) -> Bool
forall a. Eq a => a -> a -> Bool
(==) (a, b)
p (a, b)
p'
instance (Haskell.Ord a, Haskell.Ord b) => Haskell.Ord (BuiltinPair a b) where
    compare :: BuiltinPair a b -> BuiltinPair a b -> Ordering
compare (BuiltinPair (a, b)
p) (BuiltinPair (a, b)
p') = (a, b) -> (a, b) -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (a, b)
p (a, b)
p'

{-# NOINLINE fst #-}
fst :: BuiltinPair a b -> a
fst :: BuiltinPair a b -> a
fst (BuiltinPair (a
a, b
_)) = a
a

{-# NOINLINE snd #-}
snd :: BuiltinPair a b -> b
snd :: BuiltinPair a b -> b
snd (BuiltinPair (a
_, b
b)) = b
b

{-# NOINLINE mkPairData #-}
mkPairData :: BuiltinData -> BuiltinData -> BuiltinPair BuiltinData BuiltinData
mkPairData :: BuiltinData -> BuiltinData -> BuiltinPair BuiltinData BuiltinData
mkPairData BuiltinData
d1 BuiltinData
d2 = (BuiltinData, BuiltinData) -> BuiltinPair BuiltinData BuiltinData
forall a b. (a, b) -> BuiltinPair a b
BuiltinPair (BuiltinData
d1, BuiltinData
d2)

{-
LIST
-}

-- See Note [Opaque builtin types]
data BuiltinList a = BuiltinList [a] deriving stock Typeable (BuiltinList a)
DataType
Constr
Typeable (BuiltinList a)
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> BuiltinList a -> c (BuiltinList a))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (BuiltinList a))
-> (BuiltinList a -> Constr)
-> (BuiltinList a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (BuiltinList a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (BuiltinList a)))
-> ((forall b. Data b => b -> b) -> BuiltinList a -> BuiltinList a)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> BuiltinList a -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> BuiltinList a -> r)
-> (forall u. (forall d. Data d => d -> u) -> BuiltinList a -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> BuiltinList a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> BuiltinList a -> m (BuiltinList a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> BuiltinList a -> m (BuiltinList a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> BuiltinList a -> m (BuiltinList a))
-> Data (BuiltinList a)
BuiltinList a -> DataType
BuiltinList a -> Constr
(forall d. Data d => c (t d)) -> Maybe (c (BuiltinList a))
(forall b. Data b => b -> b) -> BuiltinList a -> BuiltinList a
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinList a -> c (BuiltinList a)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (BuiltinList a)
forall a. Data a => Typeable (BuiltinList a)
forall a. Data a => BuiltinList a -> DataType
forall a. Data a => BuiltinList a -> Constr
forall a.
Data a =>
(forall b. Data b => b -> b) -> BuiltinList a -> BuiltinList a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> BuiltinList a -> u
forall a u.
Data a =>
(forall d. Data d => d -> u) -> BuiltinList a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinList a -> r
forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinList a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d)
-> BuiltinList a -> m (BuiltinList a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> BuiltinList a -> m (BuiltinList a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (BuiltinList a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinList a -> c (BuiltinList a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (BuiltinList a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (BuiltinList a))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> BuiltinList a -> u
forall u. (forall d. Data d => d -> u) -> BuiltinList a -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinList a -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinList a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> BuiltinList a -> m (BuiltinList a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> BuiltinList a -> m (BuiltinList a)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (BuiltinList a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinList a -> c (BuiltinList a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (BuiltinList a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (BuiltinList a))
$cBuiltinList :: Constr
$tBuiltinList :: DataType
gmapMo :: (forall d. Data d => d -> m d)
-> BuiltinList a -> m (BuiltinList a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> BuiltinList a -> m (BuiltinList a)
gmapMp :: (forall d. Data d => d -> m d)
-> BuiltinList a -> m (BuiltinList a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> BuiltinList a -> m (BuiltinList a)
gmapM :: (forall d. Data d => d -> m d)
-> BuiltinList a -> m (BuiltinList a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d)
-> BuiltinList a -> m (BuiltinList a)
gmapQi :: Int -> (forall d. Data d => d -> u) -> BuiltinList a -> u
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> BuiltinList a -> u
gmapQ :: (forall d. Data d => d -> u) -> BuiltinList a -> [u]
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> BuiltinList a -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinList a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinList a -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinList a -> r
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinList a -> r
gmapT :: (forall b. Data b => b -> b) -> BuiltinList a -> BuiltinList a
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> BuiltinList a -> BuiltinList a
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (BuiltinList a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (BuiltinList a))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (BuiltinList a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (BuiltinList a))
dataTypeOf :: BuiltinList a -> DataType
$cdataTypeOf :: forall a. Data a => BuiltinList a -> DataType
toConstr :: BuiltinList a -> Constr
$ctoConstr :: forall a. Data a => BuiltinList a -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (BuiltinList a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (BuiltinList a)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinList a -> c (BuiltinList a)
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinList a -> c (BuiltinList a)
$cp1Data :: forall a. Data a => Typeable (BuiltinList a)
Data

instance Haskell.Show a => Haskell.Show (BuiltinList a) where
    show :: BuiltinList a -> String
show (BuiltinList [a]
l) = [a] -> String
forall a. Show a => a -> String
show [a]
l
instance Haskell.Eq a => Haskell.Eq (BuiltinList a) where
    == :: BuiltinList a -> BuiltinList a -> Bool
(==) (BuiltinList [a]
l) (BuiltinList [a]
l') = [a] -> [a] -> Bool
forall a. Eq a => a -> a -> Bool
(==) [a]
l [a]
l'
instance Haskell.Ord a => Haskell.Ord (BuiltinList a) where
    compare :: BuiltinList a -> BuiltinList a -> Ordering
compare (BuiltinList [a]
l) (BuiltinList [a]
l') = [a] -> [a] -> Ordering
forall a. Ord a => a -> a -> Ordering
compare [a]
l [a]
l'

{-# NOINLINE null #-}
null :: BuiltinList a -> BuiltinBool
null :: BuiltinList a -> BuiltinBool
null (BuiltinList (a
_:[a]
_)) = Bool -> BuiltinBool
BuiltinBool Bool
False
null (BuiltinList [])    = Bool -> BuiltinBool
BuiltinBool Bool
True

{-# NOINLINE head #-}
head :: BuiltinList a -> a
head :: BuiltinList a -> a
head (BuiltinList (a
x:[a]
_)) = a
x
head (BuiltinList [])    = String -> a
forall a. HasCallStack => String -> a
Haskell.error String
"empty list"

{-# NOINLINE tail #-}
tail :: BuiltinList a -> BuiltinList a
tail :: BuiltinList a -> BuiltinList a
tail (BuiltinList (a
_:[a]
xs)) = [a] -> BuiltinList a
forall a. [a] -> BuiltinList a
BuiltinList [a]
xs
tail (BuiltinList [])     = String -> BuiltinList a
forall a. HasCallStack => String -> a
Haskell.error String
"empty list"

{-# NOINLINE chooseList #-}
chooseList :: BuiltinList a -> b -> b-> b
chooseList :: BuiltinList a -> b -> b -> b
chooseList (BuiltinList [])    b
b1 b
_ = b
b1
chooseList (BuiltinList (a
_:[a]
_)) b
_ b
b2 = b
b2

{-# NOINLINE mkNilData #-}
mkNilData :: BuiltinUnit -> BuiltinList BuiltinData
mkNilData :: BuiltinUnit -> BuiltinList BuiltinData
mkNilData BuiltinUnit
_ = [BuiltinData] -> BuiltinList BuiltinData
forall a. [a] -> BuiltinList a
BuiltinList []

{-# NOINLINE mkNilPairData #-}
mkNilPairData :: BuiltinUnit -> BuiltinList (BuiltinPair BuiltinData BuiltinData)
mkNilPairData :: BuiltinUnit -> BuiltinList (BuiltinPair BuiltinData BuiltinData)
mkNilPairData BuiltinUnit
_ = [BuiltinPair BuiltinData BuiltinData]
-> BuiltinList (BuiltinPair BuiltinData BuiltinData)
forall a. [a] -> BuiltinList a
BuiltinList []

{-# NOINLINE mkCons #-}
mkCons :: a -> BuiltinList a -> BuiltinList a
mkCons :: a -> BuiltinList a -> BuiltinList a
mkCons a
a (BuiltinList [a]
as) = [a] -> BuiltinList a
forall a. [a] -> BuiltinList a
BuiltinList (a
aa -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
as)

{-
DATA
-}

{-|
A type corresponding to the Plutus Core builtin equivalent of 'PLC.Data'.

The point of this type is to be an opaque equivalent of 'PLC.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.
-}
data BuiltinData = BuiltinData PLC.Data deriving stock Typeable BuiltinData
DataType
Constr
Typeable BuiltinData
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> BuiltinData -> c BuiltinData)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c BuiltinData)
-> (BuiltinData -> Constr)
-> (BuiltinData -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c BuiltinData))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c BuiltinData))
-> ((forall b. Data b => b -> b) -> BuiltinData -> BuiltinData)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> BuiltinData -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> BuiltinData -> r)
-> (forall u. (forall d. Data d => d -> u) -> BuiltinData -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> BuiltinData -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> BuiltinData -> m BuiltinData)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> BuiltinData -> m BuiltinData)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> BuiltinData -> m BuiltinData)
-> Data BuiltinData
BuiltinData -> DataType
BuiltinData -> Constr
(forall b. Data b => b -> b) -> BuiltinData -> BuiltinData
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinData -> c BuiltinData
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinData
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> BuiltinData -> u
forall u. (forall d. Data d => d -> u) -> BuiltinData -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinData -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinData -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BuiltinData -> m BuiltinData
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuiltinData -> m BuiltinData
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinData
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinData -> c BuiltinData
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BuiltinData)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BuiltinData)
$cBuiltinData :: Constr
$tBuiltinData :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> BuiltinData -> m BuiltinData
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuiltinData -> m BuiltinData
gmapMp :: (forall d. Data d => d -> m d) -> BuiltinData -> m BuiltinData
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuiltinData -> m BuiltinData
gmapM :: (forall d. Data d => d -> m d) -> BuiltinData -> m BuiltinData
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BuiltinData -> m BuiltinData
gmapQi :: Int -> (forall d. Data d => d -> u) -> BuiltinData -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> BuiltinData -> u
gmapQ :: (forall d. Data d => d -> u) -> BuiltinData -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> BuiltinData -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinData -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinData -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinData -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinData -> r
gmapT :: (forall b. Data b => b -> b) -> BuiltinData -> BuiltinData
$cgmapT :: (forall b. Data b => b -> b) -> BuiltinData -> BuiltinData
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BuiltinData)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BuiltinData)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c BuiltinData)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BuiltinData)
dataTypeOf :: BuiltinData -> DataType
$cdataTypeOf :: BuiltinData -> DataType
toConstr :: BuiltinData -> Constr
$ctoConstr :: BuiltinData -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinData
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinData
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinData -> c BuiltinData
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinData -> c BuiltinData
$cp1Data :: Typeable BuiltinData
Data

instance Haskell.Show BuiltinData where
    show :: BuiltinData -> String
show (BuiltinData Data
d) = Data -> String
forall a. Show a => a -> String
show Data
d
instance Haskell.Eq BuiltinData where
    == :: BuiltinData -> BuiltinData -> Bool
(==) (BuiltinData Data
d) (BuiltinData Data
d') = Data -> Data -> Bool
forall a. Eq a => a -> a -> Bool
(==) Data
d Data
d'
instance Haskell.Ord BuiltinData where
    compare :: BuiltinData -> BuiltinData -> Ordering
compare (BuiltinData Data
d) (BuiltinData Data
d') = Data -> Data -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Data
d Data
d'
instance NFData BuiltinData where
    rnf :: BuiltinData -> ()
rnf (BuiltinData Data
d) = Data -> ()
forall a. NFData a => a -> ()
rnf Data
d
instance Pretty BuiltinData where
    pretty :: BuiltinData -> Doc ann
pretty (BuiltinData Data
d) = Data -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Data
d

-- NOT a builtin, only safe off-chain, hence the NOINLINE
{-# NOINLINE builtinDataToData #-}
-- | Convert a 'BuiltinData' into a 'PLC.Data'. Only works off-chain.
builtinDataToData :: BuiltinData -> PLC.Data
builtinDataToData :: BuiltinData -> Data
builtinDataToData (BuiltinData Data
d) = Data
d

-- NOT a builtin, only safe off-chain, hence the NOINLINE
{-# NOINLINE dataToBuiltinData #-}
-- | Convert a 'PLC.Data' into a 'BuiltinData'. Only works off-chain.
dataToBuiltinData :: PLC.Data -> BuiltinData
dataToBuiltinData :: Data -> BuiltinData
dataToBuiltinData = Data -> BuiltinData
BuiltinData

{-# NOINLINE chooseData #-}
chooseData :: forall a . BuiltinData -> a -> a -> a -> a -> a -> a
chooseData :: BuiltinData -> a -> a -> a -> a -> a -> a
chooseData (BuiltinData Data
d) a
constrCase a
mapCase a
listCase a
iCase a
bCase = case Data
d of
    PLC.Constr{} -> a
constrCase
    PLC.Map{}    -> a
mapCase
    PLC.List{}   -> a
listCase
    PLC.I{}      -> a
iCase
    PLC.B{}      -> a
bCase

{-# NOINLINE mkConstr #-}
mkConstr :: BuiltinInteger -> BuiltinList BuiltinData -> BuiltinData
mkConstr :: BuiltinInteger -> BuiltinList BuiltinData -> BuiltinData
mkConstr BuiltinInteger
i (BuiltinList [BuiltinData]
args) = Data -> BuiltinData
BuiltinData (BuiltinInteger -> [Data] -> Data
PLC.Constr BuiltinInteger
i ((BuiltinData -> Data) -> [BuiltinData] -> [Data]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap BuiltinData -> Data
builtinDataToData [BuiltinData]
args))

{-# NOINLINE mkMap #-}
mkMap :: BuiltinList (BuiltinPair BuiltinData BuiltinData) -> BuiltinData
mkMap :: BuiltinList (BuiltinPair BuiltinData BuiltinData) -> BuiltinData
mkMap (BuiltinList [BuiltinPair BuiltinData BuiltinData]
es) = Data -> BuiltinData
BuiltinData ([(Data, Data)] -> Data
PLC.Map ([(Data, Data)] -> Data) -> [(Data, Data)] -> Data
forall a b. (a -> b) -> a -> b
$ ((BuiltinPair BuiltinData BuiltinData -> (Data, Data))
-> [BuiltinPair BuiltinData BuiltinData] -> [(Data, Data)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap BuiltinPair BuiltinData BuiltinData -> (Data, Data)
p2p [BuiltinPair BuiltinData BuiltinData]
es))
  where
      p2p :: BuiltinPair BuiltinData BuiltinData -> (Data, Data)
p2p (BuiltinPair (BuiltinData
d, BuiltinData
d')) = (BuiltinData -> Data
builtinDataToData BuiltinData
d, BuiltinData -> Data
builtinDataToData BuiltinData
d')

{-# NOINLINE mkList #-}
mkList :: BuiltinList BuiltinData -> BuiltinData
mkList :: BuiltinList BuiltinData -> BuiltinData
mkList (BuiltinList [BuiltinData]
l) = Data -> BuiltinData
BuiltinData ([Data] -> Data
PLC.List ((BuiltinData -> Data) -> [BuiltinData] -> [Data]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap BuiltinData -> Data
builtinDataToData [BuiltinData]
l))

{-# NOINLINE mkI #-}
mkI :: BuiltinInteger -> BuiltinData
mkI :: BuiltinInteger -> BuiltinData
mkI BuiltinInteger
i = Data -> BuiltinData
BuiltinData (BuiltinInteger -> Data
PLC.I BuiltinInteger
i)

{-# NOINLINE mkB #-}
mkB :: BuiltinByteString -> BuiltinData
mkB :: BuiltinByteString -> BuiltinData
mkB (BuiltinByteString ByteString
b) = Data -> BuiltinData
BuiltinData (ByteString -> Data
PLC.B ByteString
b)

{-# NOINLINE unsafeDataAsConstr #-}
unsafeDataAsConstr :: BuiltinData -> BuiltinPair BuiltinInteger (BuiltinList BuiltinData)
unsafeDataAsConstr :: BuiltinData -> BuiltinPair BuiltinInteger (BuiltinList BuiltinData)
unsafeDataAsConstr (BuiltinData (PLC.Constr BuiltinInteger
i [Data]
args)) = (BuiltinInteger, BuiltinList BuiltinData)
-> BuiltinPair BuiltinInteger (BuiltinList BuiltinData)
forall a b. (a, b) -> BuiltinPair a b
BuiltinPair (BuiltinInteger
i, [BuiltinData] -> BuiltinList BuiltinData
forall a. [a] -> BuiltinList a
BuiltinList ([BuiltinData] -> BuiltinList BuiltinData)
-> [BuiltinData] -> BuiltinList BuiltinData
forall a b. (a -> b) -> a -> b
$ (Data -> BuiltinData) -> [Data] -> [BuiltinData]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Data -> BuiltinData
dataToBuiltinData [Data]
args)
unsafeDataAsConstr BuiltinData
_                                 = String -> BuiltinPair BuiltinInteger (BuiltinList BuiltinData)
forall a. HasCallStack => String -> a
Haskell.error String
"not a Constr"

{-# NOINLINE unsafeDataAsMap #-}
unsafeDataAsMap :: BuiltinData -> BuiltinList (BuiltinPair BuiltinData BuiltinData)
unsafeDataAsMap :: BuiltinData -> BuiltinList (BuiltinPair BuiltinData BuiltinData)
unsafeDataAsMap (BuiltinData (PLC.Map [(Data, Data)]
m)) = [BuiltinPair BuiltinData BuiltinData]
-> BuiltinList (BuiltinPair BuiltinData BuiltinData)
forall a. [a] -> BuiltinList a
BuiltinList (((Data, Data) -> BuiltinPair BuiltinData BuiltinData)
-> [(Data, Data)] -> [BuiltinPair BuiltinData BuiltinData]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Data, Data) -> BuiltinPair BuiltinData BuiltinData
p2p [(Data, Data)]
m)
  where
      p2p :: (Data, Data) -> BuiltinPair BuiltinData BuiltinData
p2p (Data
d, Data
d') = (BuiltinData, BuiltinData) -> BuiltinPair BuiltinData BuiltinData
forall a b. (a, b) -> BuiltinPair a b
BuiltinPair (Data -> BuiltinData
dataToBuiltinData Data
d, Data -> BuiltinData
dataToBuiltinData Data
d')
unsafeDataAsMap BuiltinData
_                         = String -> BuiltinList (BuiltinPair BuiltinData BuiltinData)
forall a. HasCallStack => String -> a
Haskell.error String
"not a Map"

{-# NOINLINE unsafeDataAsList #-}
unsafeDataAsList :: BuiltinData -> BuiltinList BuiltinData
unsafeDataAsList :: BuiltinData -> BuiltinList BuiltinData
unsafeDataAsList (BuiltinData (PLC.List [Data]
l)) = [BuiltinData] -> BuiltinList BuiltinData
forall a. [a] -> BuiltinList a
BuiltinList ((Data -> BuiltinData) -> [Data] -> [BuiltinData]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Data -> BuiltinData
dataToBuiltinData [Data]
l)
unsafeDataAsList BuiltinData
_                          = String -> BuiltinList BuiltinData
forall a. HasCallStack => String -> a
Haskell.error String
"not a List"

{-# NOINLINE unsafeDataAsI #-}
unsafeDataAsI :: BuiltinData -> BuiltinInteger
unsafeDataAsI :: BuiltinData -> BuiltinInteger
unsafeDataAsI (BuiltinData (PLC.I BuiltinInteger
i)) = BuiltinInteger
i
unsafeDataAsI BuiltinData
_                       = String -> BuiltinInteger
forall a. HasCallStack => String -> a
Haskell.error String
"not an I"

{-# NOINLINE unsafeDataAsB #-}
unsafeDataAsB :: BuiltinData -> BuiltinByteString
unsafeDataAsB :: BuiltinData -> BuiltinByteString
unsafeDataAsB (BuiltinData (PLC.B ByteString
b)) = ByteString -> BuiltinByteString
BuiltinByteString ByteString
b
unsafeDataAsB BuiltinData
_                       = String -> BuiltinByteString
forall a. HasCallStack => String -> a
Haskell.error String
"not a B"

{-# NOINLINE equalsData #-}
equalsData :: BuiltinData -> BuiltinData -> BuiltinBool
equalsData :: BuiltinData -> BuiltinData -> BuiltinBool
equalsData (BuiltinData Data
b1) (BuiltinData Data
b2) = Bool -> BuiltinBool
BuiltinBool (Bool -> BuiltinBool) -> Bool -> BuiltinBool
forall a b. (a -> b) -> a -> b
$ Data
b1 Data -> Data -> Bool
forall a. Eq a => a -> a -> Bool
Haskell.== Data
b2

{-# NOINLINE serialiseData #-}
serialiseData :: BuiltinData -> BuiltinByteString
serialiseData :: BuiltinData -> BuiltinByteString
serialiseData (BuiltinData Data
b) = ByteString -> BuiltinByteString
BuiltinByteString (ByteString -> BuiltinByteString)
-> ByteString -> BuiltinByteString
forall a b. (a -> b) -> a -> b
$ ByteString -> ByteString
BS.toStrict (ByteString -> ByteString) -> ByteString -> ByteString
forall a b. (a -> b) -> a -> b
$ Data -> ByteString
forall a. Serialise a => a -> ByteString
serialise Data
b