module Plutus.Script.Utils.V1.Tx
    ( scriptTxOut
    , scriptAddressTxOut
    ) where

import Plutus.Script.Utils.Scripts (datumHash)
import Plutus.Script.Utils.V1.Address (mkValidatorAddress)
import Plutus.V1.Ledger.Api (Address, Datum, TxOut (TxOut), Validator, Value)

-- | Create a transaction output locked by a validator script and attach the given data
-- script.
scriptTxOut :: Validator -> Value -> Datum -> TxOut
scriptTxOut :: Validator -> Value -> Datum -> TxOut
scriptTxOut Validator
validator = Address -> Value -> Datum -> TxOut
scriptAddressTxOut (Validator -> Address
mkValidatorAddress Validator
validator)

-- | Create a transaction output locked by a validator script hash with the given data
-- script attached.
scriptAddressTxOut :: Address -> Value -> Datum -> TxOut
scriptAddressTxOut :: Address -> Value -> Datum -> TxOut
scriptAddressTxOut Address
address Value
val Datum
datum = Address -> Value -> Maybe DatumHash -> TxOut
TxOut Address
address Value
val (DatumHash -> Maybe DatumHash
forall a. a -> Maybe a
Just (Datum -> DatumHash
datumHash Datum
datum))