{-# LANGUAGE DeriveAnyClass    #-}
{-# LANGUAGE DerivingVia       #-}
{-# LANGUAGE LambdaCase        #-}
{-# LANGUAGE NamedFieldPuns    #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms   #-}
{-# LANGUAGE TemplateHaskell   #-}
{-# LANGUAGE ViewPatterns      #-}
{-# OPTIONS_GHC -fno-omit-interface-pragmas #-}
{-# OPTIONS_GHC -fno-specialise #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

module PlutusLedgerApi.V1.Data.Tx (
  -- * Transactions
  TxId (..),
  ScriptTag (..),
  RedeemerPtr (..),
  Redeemers,

  -- * Transaction outputs
  TxOut,
  pattern TxOut,
  txOutAddress,
  txOutValue,
  txOutDatumHash,
  TxOutRef,
  pattern TxOutRef,
  txOutRefId,
  txOutRefIdx,
  isPubKeyOut,
  isPayToScriptOut,
  outAddress,
  outValue,
  txOutPubKey,
  txOutDatum,
  pubKeyHashTxOut,
) where

import Control.DeepSeq (NFData)
import Control.Lens
import Data.Map (Map)
import Data.Maybe (isJust)
import Data.String (IsString)
import GHC.Generics (Generic)
import Prettyprinter

import PlutusTx qualified
import PlutusTx.AsData qualified as PlutusTx
import PlutusTx.Bool qualified as PlutusTx
import PlutusTx.Builtins qualified as PlutusTx
import PlutusTx.Eq qualified as PlutusTx
import PlutusTx.Ord qualified as PlutusTx

import PlutusLedgerApi.V1.Bytes
import PlutusLedgerApi.V1.Crypto
import PlutusLedgerApi.V1.Data.Address
import PlutusLedgerApi.V1.Data.Value
import PlutusLedgerApi.V1.Scripts

{-| A transaction ID, i.e. the hash of a transaction. Hashed with BLAKE2b-256. 32 byte.

This is a simple type without any validation, __use with caution__.
You may want to add checks for its invariants. See the
 [Shelley ledger specification](https://github.com/IntersectMBO/cardano-ledger/releases/download/cardano-ledger-spec-2023-04-03/shelley-ledger.pdf). -- editorconfig-checker-disable-file
-}
newtype TxId = TxId {TxId -> BuiltinByteString
getTxId :: PlutusTx.BuiltinByteString}
  deriving stock (TxId -> TxId -> Bool
(TxId -> TxId -> Bool) -> (TxId -> TxId -> Bool) -> Eq TxId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TxId -> TxId -> Bool
== :: TxId -> TxId -> Bool
$c/= :: TxId -> TxId -> Bool
/= :: TxId -> TxId -> Bool
Eq, Eq TxId
Eq TxId =>
(TxId -> TxId -> Ordering)
-> (TxId -> TxId -> Bool)
-> (TxId -> TxId -> Bool)
-> (TxId -> TxId -> Bool)
-> (TxId -> TxId -> Bool)
-> (TxId -> TxId -> TxId)
-> (TxId -> TxId -> TxId)
-> Ord TxId
TxId -> TxId -> Bool
TxId -> TxId -> Ordering
TxId -> TxId -> TxId
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: TxId -> TxId -> Ordering
compare :: TxId -> TxId -> Ordering
$c< :: TxId -> TxId -> Bool
< :: TxId -> TxId -> Bool
$c<= :: TxId -> TxId -> Bool
<= :: TxId -> TxId -> Bool
$c> :: TxId -> TxId -> Bool
> :: TxId -> TxId -> Bool
$c>= :: TxId -> TxId -> Bool
>= :: TxId -> TxId -> Bool
$cmax :: TxId -> TxId -> TxId
max :: TxId -> TxId -> TxId
$cmin :: TxId -> TxId -> TxId
min :: TxId -> TxId -> TxId
Ord, (forall x. TxId -> Rep TxId x)
-> (forall x. Rep TxId x -> TxId) -> Generic TxId
forall x. Rep TxId x -> TxId
forall x. TxId -> Rep TxId x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. TxId -> Rep TxId x
from :: forall x. TxId -> Rep TxId x
$cto :: forall x. Rep TxId x -> TxId
to :: forall x. Rep TxId x -> TxId
Generic)
  deriving anyclass (TxId -> ()
(TxId -> ()) -> NFData TxId
forall a. (a -> ()) -> NFData a
$crnf :: TxId -> ()
rnf :: TxId -> ()
NFData)
  deriving newtype (TxId -> TxId -> Bool
(TxId -> TxId -> Bool) -> Eq TxId
forall a. (a -> a -> Bool) -> Eq a
$c== :: TxId -> TxId -> Bool
== :: TxId -> TxId -> Bool
PlutusTx.Eq, Eq TxId
Eq TxId =>
(TxId -> TxId -> Ordering)
-> (TxId -> TxId -> Bool)
-> (TxId -> TxId -> Bool)
-> (TxId -> TxId -> Bool)
-> (TxId -> TxId -> Bool)
-> (TxId -> TxId -> TxId)
-> (TxId -> TxId -> TxId)
-> Ord TxId
TxId -> TxId -> Bool
TxId -> TxId -> Ordering
TxId -> TxId -> TxId
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: TxId -> TxId -> Ordering
compare :: TxId -> TxId -> Ordering
$c< :: TxId -> TxId -> Bool
< :: TxId -> TxId -> Bool
$c<= :: TxId -> TxId -> Bool
<= :: TxId -> TxId -> Bool
$c> :: TxId -> TxId -> Bool
> :: TxId -> TxId -> Bool
$c>= :: TxId -> TxId -> Bool
>= :: TxId -> TxId -> Bool
$cmax :: TxId -> TxId -> TxId
max :: TxId -> TxId -> TxId
$cmin :: TxId -> TxId -> TxId
min :: TxId -> TxId -> TxId
PlutusTx.Ord)
  deriving
    ( String -> TxId
(String -> TxId) -> IsString TxId
forall a. (String -> a) -> IsString a
$cfromString :: String -> TxId
fromString :: String -> TxId
IsString
      -- ^ from hex encoding
    , Int -> TxId -> ShowS
[TxId] -> ShowS
TxId -> String
(Int -> TxId -> ShowS)
-> (TxId -> String) -> ([TxId] -> ShowS) -> Show TxId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TxId -> ShowS
showsPrec :: Int -> TxId -> ShowS
$cshow :: TxId -> String
show :: TxId -> String
$cshowList :: [TxId] -> ShowS
showList :: [TxId] -> ShowS
Show
      -- ^ using hex encoding
    , (forall ann. TxId -> Doc ann)
-> (forall ann. [TxId] -> Doc ann) -> Pretty TxId
forall ann. [TxId] -> Doc ann
forall ann. TxId -> Doc ann
forall a.
(forall ann. a -> Doc ann)
-> (forall ann. [a] -> Doc ann) -> Pretty a
$cpretty :: forall ann. TxId -> Doc ann
pretty :: forall ann. TxId -> Doc ann
$cprettyList :: forall ann. [TxId] -> Doc ann
prettyList :: forall ann. [TxId] -> Doc ann
Pretty
      -- ^ using hex encoding
    )
    via LedgerBytes

PlutusTx.makeLift ''TxId
PlutusTx.makeIsDataIndexed ''TxId [('TxId, 0)]

{-| A tag indicating the type of script that we are pointing to.

See also 'PlutusLedgerApi.V1.ScriptPurpose'
-}
data ScriptTag = Spend | Mint | Cert | Reward
  deriving stock (Int -> ScriptTag -> ShowS
[ScriptTag] -> ShowS
ScriptTag -> String
(Int -> ScriptTag -> ShowS)
-> (ScriptTag -> String)
-> ([ScriptTag] -> ShowS)
-> Show ScriptTag
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ScriptTag -> ShowS
showsPrec :: Int -> ScriptTag -> ShowS
$cshow :: ScriptTag -> String
show :: ScriptTag -> String
$cshowList :: [ScriptTag] -> ShowS
showList :: [ScriptTag] -> ShowS
Show, ScriptTag -> ScriptTag -> Bool
(ScriptTag -> ScriptTag -> Bool)
-> (ScriptTag -> ScriptTag -> Bool) -> Eq ScriptTag
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ScriptTag -> ScriptTag -> Bool
== :: ScriptTag -> ScriptTag -> Bool
$c/= :: ScriptTag -> ScriptTag -> Bool
/= :: ScriptTag -> ScriptTag -> Bool
Eq, Eq ScriptTag
Eq ScriptTag =>
(ScriptTag -> ScriptTag -> Ordering)
-> (ScriptTag -> ScriptTag -> Bool)
-> (ScriptTag -> ScriptTag -> Bool)
-> (ScriptTag -> ScriptTag -> Bool)
-> (ScriptTag -> ScriptTag -> Bool)
-> (ScriptTag -> ScriptTag -> ScriptTag)
-> (ScriptTag -> ScriptTag -> ScriptTag)
-> Ord ScriptTag
ScriptTag -> ScriptTag -> Bool
ScriptTag -> ScriptTag -> Ordering
ScriptTag -> ScriptTag -> ScriptTag
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ScriptTag -> ScriptTag -> Ordering
compare :: ScriptTag -> ScriptTag -> Ordering
$c< :: ScriptTag -> ScriptTag -> Bool
< :: ScriptTag -> ScriptTag -> Bool
$c<= :: ScriptTag -> ScriptTag -> Bool
<= :: ScriptTag -> ScriptTag -> Bool
$c> :: ScriptTag -> ScriptTag -> Bool
> :: ScriptTag -> ScriptTag -> Bool
$c>= :: ScriptTag -> ScriptTag -> Bool
>= :: ScriptTag -> ScriptTag -> Bool
$cmax :: ScriptTag -> ScriptTag -> ScriptTag
max :: ScriptTag -> ScriptTag -> ScriptTag
$cmin :: ScriptTag -> ScriptTag -> ScriptTag
min :: ScriptTag -> ScriptTag -> ScriptTag
Ord, (forall x. ScriptTag -> Rep ScriptTag x)
-> (forall x. Rep ScriptTag x -> ScriptTag) -> Generic ScriptTag
forall x. Rep ScriptTag x -> ScriptTag
forall x. ScriptTag -> Rep ScriptTag x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ScriptTag -> Rep ScriptTag x
from :: forall x. ScriptTag -> Rep ScriptTag x
$cto :: forall x. Rep ScriptTag x -> ScriptTag
to :: forall x. Rep ScriptTag x -> ScriptTag
Generic)
  deriving anyclass (ScriptTag -> ()
(ScriptTag -> ()) -> NFData ScriptTag
forall a. (a -> ()) -> NFData a
$crnf :: ScriptTag -> ()
rnf :: ScriptTag -> ()
NFData)

{-| A redeemer pointer is a pair of a script type tag ('ScriptTag') `t` and an index `i`,
picking out the i-th script of type `t` in the transaction.
-}
data RedeemerPtr = RedeemerPtr ScriptTag Integer
  deriving stock (Int -> RedeemerPtr -> ShowS
[RedeemerPtr] -> ShowS
RedeemerPtr -> String
(Int -> RedeemerPtr -> ShowS)
-> (RedeemerPtr -> String)
-> ([RedeemerPtr] -> ShowS)
-> Show RedeemerPtr
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RedeemerPtr -> ShowS
showsPrec :: Int -> RedeemerPtr -> ShowS
$cshow :: RedeemerPtr -> String
show :: RedeemerPtr -> String
$cshowList :: [RedeemerPtr] -> ShowS
showList :: [RedeemerPtr] -> ShowS
Show, RedeemerPtr -> RedeemerPtr -> Bool
(RedeemerPtr -> RedeemerPtr -> Bool)
-> (RedeemerPtr -> RedeemerPtr -> Bool) -> Eq RedeemerPtr
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RedeemerPtr -> RedeemerPtr -> Bool
== :: RedeemerPtr -> RedeemerPtr -> Bool
$c/= :: RedeemerPtr -> RedeemerPtr -> Bool
/= :: RedeemerPtr -> RedeemerPtr -> Bool
Eq, Eq RedeemerPtr
Eq RedeemerPtr =>
(RedeemerPtr -> RedeemerPtr -> Ordering)
-> (RedeemerPtr -> RedeemerPtr -> Bool)
-> (RedeemerPtr -> RedeemerPtr -> Bool)
-> (RedeemerPtr -> RedeemerPtr -> Bool)
-> (RedeemerPtr -> RedeemerPtr -> Bool)
-> (RedeemerPtr -> RedeemerPtr -> RedeemerPtr)
-> (RedeemerPtr -> RedeemerPtr -> RedeemerPtr)
-> Ord RedeemerPtr
RedeemerPtr -> RedeemerPtr -> Bool
RedeemerPtr -> RedeemerPtr -> Ordering
RedeemerPtr -> RedeemerPtr -> RedeemerPtr
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: RedeemerPtr -> RedeemerPtr -> Ordering
compare :: RedeemerPtr -> RedeemerPtr -> Ordering
$c< :: RedeemerPtr -> RedeemerPtr -> Bool
< :: RedeemerPtr -> RedeemerPtr -> Bool
$c<= :: RedeemerPtr -> RedeemerPtr -> Bool
<= :: RedeemerPtr -> RedeemerPtr -> Bool
$c> :: RedeemerPtr -> RedeemerPtr -> Bool
> :: RedeemerPtr -> RedeemerPtr -> Bool
$c>= :: RedeemerPtr -> RedeemerPtr -> Bool
>= :: RedeemerPtr -> RedeemerPtr -> Bool
$cmax :: RedeemerPtr -> RedeemerPtr -> RedeemerPtr
max :: RedeemerPtr -> RedeemerPtr -> RedeemerPtr
$cmin :: RedeemerPtr -> RedeemerPtr -> RedeemerPtr
min :: RedeemerPtr -> RedeemerPtr -> RedeemerPtr
Ord, (forall x. RedeemerPtr -> Rep RedeemerPtr x)
-> (forall x. Rep RedeemerPtr x -> RedeemerPtr)
-> Generic RedeemerPtr
forall x. Rep RedeemerPtr x -> RedeemerPtr
forall x. RedeemerPtr -> Rep RedeemerPtr x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. RedeemerPtr -> Rep RedeemerPtr x
from :: forall x. RedeemerPtr -> Rep RedeemerPtr x
$cto :: forall x. Rep RedeemerPtr x -> RedeemerPtr
to :: forall x. Rep RedeemerPtr x -> RedeemerPtr
Generic)
  deriving anyclass (RedeemerPtr -> ()
(RedeemerPtr -> ()) -> NFData RedeemerPtr
forall a. (a -> ()) -> NFData a
$crnf :: RedeemerPtr -> ()
rnf :: RedeemerPtr -> ()
NFData)

-- | Redeemers is a `Map` of redeemer pointer ('RedeemerPtr') and its 'Redeemer'.
type Redeemers = Map RedeemerPtr Redeemer

{-| A reference to a transaction output. This is a
pair of a transaction ID (`TxId`), and an index indicating which of the outputs
of that transaction we are referring to.
-}
PlutusTx.asData
  [d|
    data TxOutRef = TxOutRef
      { txOutRefId  :: TxId
      -- ^ The transaction ID.
      , txOutRefIdx :: Integer
      -- ^ Index into the referenced transaction's outputs
      }
      deriving stock (Show, Eq, Ord, Generic)
      deriving newtype (PlutusTx.FromData, PlutusTx.UnsafeFromData, PlutusTx.ToData)
      deriving anyclass (NFData)
  |]

instance Pretty TxOutRef where
  pretty :: forall ann. TxOutRef -> Doc ann
pretty TxOutRef{TxId
txOutRefId :: TxOutRef -> TxId
txOutRefId :: TxId
txOutRefId, Integer
txOutRefIdx :: TxOutRef -> Integer
txOutRefIdx :: Integer
txOutRefIdx} = TxId -> Doc ann
forall a ann. Pretty a => a -> Doc ann
forall ann. TxId -> Doc ann
pretty TxId
txOutRefId Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann
"!" Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Integer -> Doc ann
forall ann. Integer -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Integer
txOutRefIdx

instance PlutusTx.Eq TxOutRef where
  {-# INLINEABLE (==) #-}
  TxOutRef
l == :: TxOutRef -> TxOutRef -> Bool
== TxOutRef
r =
    TxOutRef -> TxId
txOutRefId TxOutRef
l
      TxId -> TxId -> Bool
forall a. Eq a => a -> a -> Bool
PlutusTx.== TxOutRef -> TxId
txOutRefId TxOutRef
r
      Bool -> Bool -> Bool
PlutusTx.&& TxOutRef -> Integer
txOutRefIdx TxOutRef
l
      Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
PlutusTx.== TxOutRef -> Integer
txOutRefIdx TxOutRef
r

{-| A transaction output, consisting of a target address ('Address'), a value ('Value'),
and optionally a datum hash ('DatumHash').
-}
PlutusTx.asData
  [d|
    data TxOut = TxOut
      { txOutAddress   :: Address
      , txOutValue     :: Value
      , txOutDatumHash :: Maybe DatumHash
      }
      deriving stock (Show, Eq, Generic)
      deriving newtype (PlutusTx.FromData, PlutusTx.UnsafeFromData, PlutusTx.ToData)
  |]

instance Pretty TxOut where
  pretty :: forall ann. TxOut -> Doc ann
pretty TxOut{Address
txOutAddress :: TxOut -> Address
txOutAddress :: Address
txOutAddress, Value
txOutValue :: TxOut -> Value
txOutValue :: Value
txOutValue} =
    Int -> Doc ann -> Doc ann
forall ann. Int -> Doc ann -> Doc ann
hang Int
2 (Doc ann -> Doc ann) -> Doc ann -> Doc ann
forall a b. (a -> b) -> a -> b
$ [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
vsep [Doc ann
"-" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Value -> Doc ann
forall a ann. Pretty a => a -> Doc ann
forall ann. Value -> Doc ann
pretty Value
txOutValue Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc ann
"addressed to", Address -> Doc ann
forall ann. Address -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Address
txOutAddress]

instance PlutusTx.Eq TxOut where
  {-# INLINEABLE (==) #-}
  TxOut
l == :: TxOut -> TxOut -> Bool
== TxOut
r =
    TxOut -> Address
txOutAddress TxOut
l
      Address -> Address -> Bool
forall a. Eq a => a -> a -> Bool
PlutusTx.== TxOut -> Address
txOutAddress TxOut
r
      Bool -> Bool -> Bool
PlutusTx.&& TxOut -> Value
txOutValue TxOut
l
      Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
PlutusTx.== TxOut -> Value
txOutValue TxOut
r
      Bool -> Bool -> Bool
PlutusTx.&& TxOut -> Maybe DatumHash
txOutDatumHash TxOut
l
      Maybe DatumHash -> Maybe DatumHash -> Bool
forall a. Eq a => a -> a -> Bool
PlutusTx.== TxOut -> Maybe DatumHash
txOutDatumHash TxOut
r

-- | The datum attached to a 'TxOut', if there is one.
txOutDatum :: TxOut -> Maybe DatumHash
txOutDatum :: TxOut -> Maybe DatumHash
txOutDatum TxOut{Maybe DatumHash
txOutDatumHash :: TxOut -> Maybe DatumHash
txOutDatumHash :: Maybe DatumHash
txOutDatumHash} = Maybe DatumHash
txOutDatumHash

-- | The public key attached to a 'TxOut', if there is one.
txOutPubKey :: TxOut -> Maybe PubKeyHash
txOutPubKey :: TxOut -> Maybe PubKeyHash
txOutPubKey TxOut{Address
txOutAddress :: TxOut -> Address
txOutAddress :: Address
txOutAddress} = Address -> Maybe PubKeyHash
toPubKeyHash Address
txOutAddress

-- | The validator hash attached to a 'TxOut', if there is one.
txOutScriptHash :: TxOut -> Maybe ScriptHash
txOutScriptHash :: TxOut -> Maybe ScriptHash
txOutScriptHash TxOut{Address
txOutAddress :: TxOut -> Address
txOutAddress :: Address
txOutAddress} = Address -> Maybe ScriptHash
toScriptHash Address
txOutAddress

-- | The address of a transaction output.
outAddress :: Lens' TxOut Address
outAddress :: Lens' TxOut Address
outAddress = (TxOut -> Address)
-> (TxOut -> Address -> TxOut) -> Lens' TxOut Address
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens TxOut -> Address
txOutAddress TxOut -> Address -> TxOut
s
 where
  s :: TxOut -> Address -> TxOut
s TxOut
tx Address
a = TxOut
tx{txOutAddress = a}

{-| The value of a transaction output.
| TODO: Compute address again
-}
outValue :: Lens' TxOut Value
outValue :: Lens' TxOut Value
outValue = (TxOut -> Value) -> (TxOut -> Value -> TxOut) -> Lens' TxOut Value
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens TxOut -> Value
txOutValue TxOut -> Value -> TxOut
s
 where
  s :: TxOut -> Value -> TxOut
s TxOut
tx Value
v = TxOut
tx{txOutValue = v}

-- | Whether the output is a pay-to-pubkey output.
isPubKeyOut :: TxOut -> Bool
isPubKeyOut :: TxOut -> Bool
isPubKeyOut = Maybe PubKeyHash -> Bool
forall a. Maybe a -> Bool
isJust (Maybe PubKeyHash -> Bool)
-> (TxOut -> Maybe PubKeyHash) -> TxOut -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TxOut -> Maybe PubKeyHash
txOutPubKey

-- | Whether the output is a pay-to-script output.
isPayToScriptOut :: TxOut -> Bool
isPayToScriptOut :: TxOut -> Bool
isPayToScriptOut = Maybe ScriptHash -> Bool
forall a. Maybe a -> Bool
isJust (Maybe ScriptHash -> Bool)
-> (TxOut -> Maybe ScriptHash) -> TxOut -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TxOut -> Maybe ScriptHash
txOutScriptHash

-- | Create a transaction output locked by a public key.
pubKeyHashTxOut :: Value -> PubKeyHash -> TxOut
pubKeyHashTxOut :: Value -> PubKeyHash -> TxOut
pubKeyHashTxOut Value
v PubKeyHash
pkh = Address -> Value -> Maybe DatumHash -> TxOut
TxOut (PubKeyHash -> Address
pubKeyHashAddress PubKeyHash
pkh) Value
v Maybe DatumHash
forall a. Maybe a
Nothing


PlutusTx.makeLift ''TxOut

PlutusTx.makeLift ''TxOutRef