-- | This module provide abstractions around the notion of outputs. The idea is
-- to use types to carry additional information on which data is carried by
-- various kinds of concrete outputs used in cooked specifically or in Plutus as
-- a whole, such as @TxSkelOut@ or @TxOut@.
module Cooked.Output
  ( IsAbstractOutput,
    OwnerType,
    DatumType,
    ValueType,
    ReferenceScriptType,
    outputOwnerL,
    outputStakingCredentialL,
    outputDatumL,
    outputValueL,
    outputReferenceScriptL,
    IsTxInfoOutput,
    outputAddress,
    outputOutputDatum,
    outputValue,
    outputReferenceScriptHash,
    outputTxOut,
    ConcreteOutput (..),
    toOutputWithReferenceScriptHash,
    isOutputWithoutDatum,
    isOutputWithInlineDatum,
    isOutputWithDatumHash,
    isOutputWithInlineDatumOfType,
    isScriptOutputFrom,
    isPKOutputFrom,
    isOnlyAdaOutput,
    fromAbstractOutput,
    isReferenceScriptOutputFrom,
    isStakingCredentialOutputFrom,
    isEmptyStakingCredentialOutput,
    isPKOutput,
    isScriptOutput,
  )
where

import Cooked.Conversion.ToCredential
import Cooked.Conversion.ToOutputDatum
import Cooked.Conversion.ToScriptHash
import Cooked.Conversion.ToValue
import Optics.Core
import Plutus.Script.Utils.Ada qualified as Script
import Plutus.Script.Utils.Value qualified as Script
import PlutusLedgerApi.V2.Tx qualified as Api
import PlutusLedgerApi.V3 qualified as Api

-- | A generalisation of 'Api.TxOut': With the four type families, we can lift
-- some information about
--
-- - who owns the output (a public key, a script...?)
--
-- - what kind of datum is there (do we have an inline datum, a datum hash,
--   nothing...?)
--
-- - what kind of value does the output hold (pure Ada ...?)
--
-- - what information do we have on the reference script (only a hash, a
--   complete script, a typed validator...?)
--
-- to the type level.
class IsAbstractOutput o where
  type OwnerType o
  type DatumType o
  type ValueType o
  type ReferenceScriptType o
  outputOwnerL :: Lens' o (OwnerType o)
  outputStakingCredentialL :: Lens' o (Maybe Api.StakingCredential)
  outputDatumL :: Lens' o (DatumType o)
  outputValueL :: Lens' o (ValueType o)
  outputReferenceScriptL :: Lens' o (Maybe (ReferenceScriptType o))

-- | An output that can be translated into its script-perspective (as seen on
-- the 'TxInfo') representation
type IsTxInfoOutput o =
  ( IsAbstractOutput o,
    ToCredential (OwnerType o),
    ToOutputDatum (DatumType o),
    ToValue (ValueType o),
    ToScriptHash (ReferenceScriptType o)
  )

outputAddress :: (IsAbstractOutput o, ToCredential (OwnerType o)) => o -> Api.Address
outputAddress :: forall o.
(IsAbstractOutput o, ToCredential (OwnerType o)) =>
o -> Address
outputAddress o
out = Credential -> Maybe StakingCredential -> Address
Api.Address (OwnerType o -> Credential
forall a. ToCredential a => a -> Credential
toCredential (o
out o -> Optic' A_Lens NoIx o (OwnerType o) -> OwnerType o
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx o (OwnerType o)
forall o. IsAbstractOutput o => Lens' o (OwnerType o)
outputOwnerL)) (o
out o
-> Optic' A_Lens NoIx o (Maybe StakingCredential)
-> Maybe StakingCredential
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx o (Maybe StakingCredential)
forall o. IsAbstractOutput o => Lens' o (Maybe StakingCredential)
outputStakingCredentialL)

outputOutputDatum :: (IsAbstractOutput o, ToOutputDatum (DatumType o)) => o -> Api.OutputDatum
outputOutputDatum :: forall o.
(IsAbstractOutput o, ToOutputDatum (DatumType o)) =>
o -> OutputDatum
outputOutputDatum = DatumType o -> OutputDatum
forall a. ToOutputDatum a => a -> OutputDatum
toOutputDatum (DatumType o -> OutputDatum)
-> (o -> DatumType o) -> o -> OutputDatum
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (o -> Optic' A_Lens NoIx o (DatumType o) -> DatumType o
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx o (DatumType o)
forall o. IsAbstractOutput o => Lens' o (DatumType o)
outputDatumL)

outputValue :: (IsAbstractOutput o, ToValue (ValueType o)) => o -> Api.Value
outputValue :: forall o. (IsAbstractOutput o, ToValue (ValueType o)) => o -> Value
outputValue = ValueType o -> Value
forall a. ToValue a => a -> Value
toValue (ValueType o -> Value) -> (o -> ValueType o) -> o -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (o -> Optic' A_Lens NoIx o (ValueType o) -> ValueType o
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx o (ValueType o)
forall o. IsAbstractOutput o => Lens' o (ValueType o)
outputValueL)

outputReferenceScriptHash :: (IsAbstractOutput o, ToScriptHash (ReferenceScriptType o)) => o -> Maybe Api.ScriptHash
outputReferenceScriptHash :: forall o.
(IsAbstractOutput o, ToScriptHash (ReferenceScriptType o)) =>
o -> Maybe ScriptHash
outputReferenceScriptHash = (ReferenceScriptType o -> ScriptHash
forall a. ToScriptHash a => a -> ScriptHash
toScriptHash (ReferenceScriptType o -> ScriptHash)
-> Maybe (ReferenceScriptType o) -> Maybe ScriptHash
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>) (Maybe (ReferenceScriptType o) -> Maybe ScriptHash)
-> (o -> Maybe (ReferenceScriptType o)) -> o -> Maybe ScriptHash
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (o
-> Optic' A_Lens NoIx o (Maybe (ReferenceScriptType o))
-> Maybe (ReferenceScriptType o)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx o (Maybe (ReferenceScriptType o))
forall o.
IsAbstractOutput o =>
Lens' o (Maybe (ReferenceScriptType o))
outputReferenceScriptL)

-- | Return the output as it is seen by a validator on the 'TxInfo'.
outputTxOut :: (IsTxInfoOutput o) => o -> Api.TxOut
outputTxOut :: forall o. IsTxInfoOutput o => o -> TxOut
outputTxOut o
o = Address -> Value -> OutputDatum -> Maybe ScriptHash -> TxOut
Api.TxOut (o -> Address
forall o.
(IsAbstractOutput o, ToCredential (OwnerType o)) =>
o -> Address
outputAddress o
o) (o -> Value
forall o. (IsAbstractOutput o, ToValue (ValueType o)) => o -> Value
outputValue o
o) (o -> OutputDatum
forall o.
(IsAbstractOutput o, ToOutputDatum (DatumType o)) =>
o -> OutputDatum
outputOutputDatum o
o) (o -> Maybe ScriptHash
forall o.
(IsAbstractOutput o, ToScriptHash (ReferenceScriptType o)) =>
o -> Maybe ScriptHash
outputReferenceScriptHash o
o)

-- * 'Api.TxOut's are outputs

instance IsAbstractOutput Api.TxOut where
  type OwnerType Api.TxOut = Api.Credential
  type DatumType Api.TxOut = Api.OutputDatum
  type ValueType Api.TxOut = Api.Value
  type ReferenceScriptType Api.TxOut = Api.ScriptHash
  outputOwnerL :: Lens' TxOut (OwnerType TxOut)
outputOwnerL =
    LensVL TxOut TxOut Address Address
-> Lens TxOut TxOut Address Address
forall s t a b. LensVL s t a b -> Lens s t a b
lensVL (Address -> f Address) -> TxOut -> f TxOut
LensVL TxOut TxOut Address Address
Api.outAddress
      Lens TxOut TxOut Address Address
-> Optic A_Lens NoIx Address Address Credential Credential
-> Optic A_Lens NoIx TxOut TxOut Credential Credential
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% (Address -> Credential)
-> (Address -> Credential -> Address)
-> Optic A_Lens NoIx Address Address Credential Credential
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens
        Address -> Credential
Api.addressCredential
        (\Address
addr Credential
cred -> Address
addr {Api.addressCredential = cred})
  outputDatumL :: Lens' TxOut (DatumType TxOut)
outputDatumL = LensVL TxOut TxOut OutputDatum OutputDatum
-> Lens TxOut TxOut OutputDatum OutputDatum
forall s t a b. LensVL s t a b -> Lens s t a b
lensVL (OutputDatum -> f OutputDatum) -> TxOut -> f TxOut
LensVL TxOut TxOut OutputDatum OutputDatum
Api.outDatum
  outputStakingCredentialL :: Lens' TxOut (Maybe StakingCredential)
outputStakingCredentialL =
    (TxOut -> Maybe StakingCredential)
-> (TxOut -> Maybe StakingCredential -> TxOut)
-> Lens' TxOut (Maybe StakingCredential)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens
      (Address -> Maybe StakingCredential
Api.addressStakingCredential (Address -> Maybe StakingCredential)
-> (TxOut -> Address) -> TxOut -> Maybe StakingCredential
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TxOut -> Address
Api.txOutAddress)
      ( \TxOut
out Maybe StakingCredential
mStCred ->
          TxOut
out {Api.txOutAddress = (Api.txOutAddress out) {Api.addressStakingCredential = mStCred}}
      )
  outputValueL :: Lens' TxOut (ValueType TxOut)
outputValueL = LensVL TxOut TxOut Value Value -> Lens TxOut TxOut Value Value
forall s t a b. LensVL s t a b -> Lens s t a b
lensVL (Value -> f Value) -> TxOut -> f TxOut
LensVL TxOut TxOut Value Value
Api.outValue
  outputReferenceScriptL :: Lens' TxOut (Maybe (ReferenceScriptType TxOut))
outputReferenceScriptL = LensVL TxOut TxOut (Maybe ScriptHash) (Maybe ScriptHash)
-> Lens TxOut TxOut (Maybe ScriptHash) (Maybe ScriptHash)
forall s t a b. LensVL s t a b -> Lens s t a b
lensVL (Maybe ScriptHash -> f (Maybe ScriptHash)) -> TxOut -> f TxOut
LensVL TxOut TxOut (Maybe ScriptHash) (Maybe ScriptHash)
Api.outReferenceScript

-- * A concrete type for outputs

-- | A type constructed to be the most general instance of 'IsAbstractOutput'.
data ConcreteOutput ownerType datumType valueType referenceScriptType where
  ConcreteOutput ::
    { forall ownerType datumType valueType referenceScriptType.
ConcreteOutput ownerType datumType valueType referenceScriptType
-> ownerType
concreteOutputOwner :: ownerType,
      forall ownerType datumType valueType referenceScriptType.
ConcreteOutput ownerType datumType valueType referenceScriptType
-> Maybe StakingCredential
concreteOutputStakingCredential :: Maybe Api.StakingCredential,
      forall ownerType datumType valueType referenceScriptType.
ConcreteOutput ownerType datumType valueType referenceScriptType
-> datumType
concreteOutputDatum :: datumType,
      forall ownerType datumType valueType referenceScriptType.
ConcreteOutput ownerType datumType valueType referenceScriptType
-> valueType
concreteOutputValue :: valueType,
      forall ownerType datumType valueType referenceScriptType.
ConcreteOutput ownerType datumType valueType referenceScriptType
-> Maybe referenceScriptType
concreteOutputReferenceScript :: Maybe referenceScriptType
    } ->
    ConcreteOutput ownerType datumType valueType referenceScriptType

deriving instance (Show ownerType, Show datumType, Show valueType, Show referenceScriptType) => Show (ConcreteOutput ownerType datumType valueType referenceScriptType)

deriving instance (Eq ownerType, Eq datumType, Eq valueType, Eq referenceScriptType) => Eq (ConcreteOutput ownerType datumType valueType referenceScriptType)

instance IsAbstractOutput (ConcreteOutput ownerType datumType valueType referenceScriptType) where
  type OwnerType (ConcreteOutput ownerType _ _ _) = ownerType
  type DatumType (ConcreteOutput _ datumType _ _) = datumType
  type ValueType (ConcreteOutput _ _ valueType _) = valueType
  type ReferenceScriptType (ConcreteOutput _ _ _ referenceScriptType) = referenceScriptType
  outputOwnerL :: Lens'
  (ConcreteOutput ownerType datumType valueType referenceScriptType)
  (OwnerType
     (ConcreteOutput ownerType datumType valueType referenceScriptType))
outputOwnerL = (ConcreteOutput ownerType datumType valueType referenceScriptType
 -> ownerType)
-> (ConcreteOutput
      ownerType datumType valueType referenceScriptType
    -> ownerType
    -> ConcreteOutput
         ownerType datumType valueType referenceScriptType)
-> Lens
     (ConcreteOutput ownerType datumType valueType referenceScriptType)
     (ConcreteOutput ownerType datumType valueType referenceScriptType)
     ownerType
     ownerType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens ConcreteOutput ownerType datumType valueType referenceScriptType
-> ownerType
forall ownerType datumType valueType referenceScriptType.
ConcreteOutput ownerType datumType valueType referenceScriptType
-> ownerType
concreteOutputOwner (\ConcreteOutput ownerType datumType valueType referenceScriptType
out ownerType
owner -> ConcreteOutput ownerType datumType valueType referenceScriptType
out {concreteOutputOwner = owner})
  outputStakingCredentialL :: Lens'
  (ConcreteOutput ownerType datumType valueType referenceScriptType)
  (Maybe StakingCredential)
outputStakingCredentialL = (ConcreteOutput ownerType datumType valueType referenceScriptType
 -> Maybe StakingCredential)
-> (ConcreteOutput
      ownerType datumType valueType referenceScriptType
    -> Maybe StakingCredential
    -> ConcreteOutput
         ownerType datumType valueType referenceScriptType)
-> Lens'
     (ConcreteOutput ownerType datumType valueType referenceScriptType)
     (Maybe StakingCredential)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens ConcreteOutput ownerType datumType valueType referenceScriptType
-> Maybe StakingCredential
forall ownerType datumType valueType referenceScriptType.
ConcreteOutput ownerType datumType valueType referenceScriptType
-> Maybe StakingCredential
concreteOutputStakingCredential (\ConcreteOutput ownerType datumType valueType referenceScriptType
out Maybe StakingCredential
mStCred -> ConcreteOutput ownerType datumType valueType referenceScriptType
out {concreteOutputStakingCredential = mStCred})
  outputDatumL :: Lens'
  (ConcreteOutput ownerType datumType valueType referenceScriptType)
  (DatumType
     (ConcreteOutput ownerType datumType valueType referenceScriptType))
outputDatumL = (ConcreteOutput ownerType datumType valueType referenceScriptType
 -> datumType)
-> (ConcreteOutput
      ownerType datumType valueType referenceScriptType
    -> datumType
    -> ConcreteOutput
         ownerType datumType valueType referenceScriptType)
-> Lens
     (ConcreteOutput ownerType datumType valueType referenceScriptType)
     (ConcreteOutput ownerType datumType valueType referenceScriptType)
     datumType
     datumType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens ConcreteOutput ownerType datumType valueType referenceScriptType
-> datumType
forall ownerType datumType valueType referenceScriptType.
ConcreteOutput ownerType datumType valueType referenceScriptType
-> datumType
concreteOutputDatum (\ConcreteOutput ownerType datumType valueType referenceScriptType
out datumType
datum -> ConcreteOutput ownerType datumType valueType referenceScriptType
out {concreteOutputDatum = datum})
  outputValueL :: Lens'
  (ConcreteOutput ownerType datumType valueType referenceScriptType)
  (ValueType
     (ConcreteOutput ownerType datumType valueType referenceScriptType))
outputValueL = (ConcreteOutput ownerType datumType valueType referenceScriptType
 -> valueType)
-> (ConcreteOutput
      ownerType datumType valueType referenceScriptType
    -> valueType
    -> ConcreteOutput
         ownerType datumType valueType referenceScriptType)
-> Lens
     (ConcreteOutput ownerType datumType valueType referenceScriptType)
     (ConcreteOutput ownerType datumType valueType referenceScriptType)
     valueType
     valueType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens ConcreteOutput ownerType datumType valueType referenceScriptType
-> valueType
forall ownerType datumType valueType referenceScriptType.
ConcreteOutput ownerType datumType valueType referenceScriptType
-> valueType
concreteOutputValue (\ConcreteOutput ownerType datumType valueType referenceScriptType
out valueType
value -> ConcreteOutput ownerType datumType valueType referenceScriptType
out {concreteOutputValue = value})
  outputReferenceScriptL :: Lens'
  (ConcreteOutput ownerType datumType valueType referenceScriptType)
  (Maybe
     (ReferenceScriptType
        (ConcreteOutput
           ownerType datumType valueType referenceScriptType)))
outputReferenceScriptL = (ConcreteOutput ownerType datumType valueType referenceScriptType
 -> Maybe referenceScriptType)
-> (ConcreteOutput
      ownerType datumType valueType referenceScriptType
    -> Maybe referenceScriptType
    -> ConcreteOutput
         ownerType datumType valueType referenceScriptType)
-> Lens
     (ConcreteOutput ownerType datumType valueType referenceScriptType)
     (ConcreteOutput ownerType datumType valueType referenceScriptType)
     (Maybe referenceScriptType)
     (Maybe referenceScriptType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens ConcreteOutput ownerType datumType valueType referenceScriptType
-> Maybe referenceScriptType
forall ownerType datumType valueType referenceScriptType.
ConcreteOutput ownerType datumType valueType referenceScriptType
-> Maybe referenceScriptType
concreteOutputReferenceScript (\ConcreteOutput ownerType datumType valueType referenceScriptType
out Maybe referenceScriptType
mRefScript -> ConcreteOutput ownerType datumType valueType referenceScriptType
out {concreteOutputReferenceScript = mRefScript})

-- | Creates a generic concrete instance of any kind of abstract output
fromAbstractOutput :: (IsAbstractOutput out) => out -> ConcreteOutput (OwnerType out) (DatumType out) (ValueType out) (ReferenceScriptType out)
fromAbstractOutput :: forall out.
IsAbstractOutput out =>
out
-> ConcreteOutput
     (OwnerType out)
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out)
fromAbstractOutput out
o = OwnerType out
-> Maybe StakingCredential
-> DatumType out
-> ValueType out
-> Maybe (ReferenceScriptType out)
-> ConcreteOutput
     (OwnerType out)
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out)
forall ownerType datumType valueType referenceScriptType.
ownerType
-> Maybe StakingCredential
-> datumType
-> valueType
-> Maybe referenceScriptType
-> ConcreteOutput ownerType datumType valueType referenceScriptType
ConcreteOutput (out
o out -> Optic' A_Lens NoIx out (OwnerType out) -> OwnerType out
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx out (OwnerType out)
forall o. IsAbstractOutput o => Lens' o (OwnerType o)
outputOwnerL) (out
o out
-> Optic' A_Lens NoIx out (Maybe StakingCredential)
-> Maybe StakingCredential
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx out (Maybe StakingCredential)
forall o. IsAbstractOutput o => Lens' o (Maybe StakingCredential)
outputStakingCredentialL) (out
o out -> Optic' A_Lens NoIx out (DatumType out) -> DatumType out
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx out (DatumType out)
forall o. IsAbstractOutput o => Lens' o (DatumType o)
outputDatumL) (out
o out -> Optic' A_Lens NoIx out (ValueType out) -> ValueType out
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx out (ValueType out)
forall o. IsAbstractOutput o => Lens' o (ValueType o)
outputValueL) (out
o out
-> Optic' A_Lens NoIx out (Maybe (ReferenceScriptType out))
-> Maybe (ReferenceScriptType out)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx out (Maybe (ReferenceScriptType out))
forall o.
IsAbstractOutput o =>
Lens' o (Maybe (ReferenceScriptType o))
outputReferenceScriptL)

-- * Functions to translate between different output types

-- ** Filtering on the datum

-- | Test if there is no datum on an output.
isOutputWithoutDatum :: (IsTxInfoOutput out) => out -> Maybe (ConcreteOutput (OwnerType out) () (ValueType out) (ReferenceScriptType out))
isOutputWithoutDatum :: forall out.
IsTxInfoOutput out =>
out
-> Maybe
     (ConcreteOutput
        (OwnerType out) () (ValueType out) (ReferenceScriptType out))
isOutputWithoutDatum out
out | OutputDatum
Api.NoOutputDatum <- out -> OutputDatum
forall o.
(IsAbstractOutput o, ToOutputDatum (DatumType o)) =>
o -> OutputDatum
outputOutputDatum out
out = ConcreteOutput
  (OwnerType out) () (ValueType out) (ReferenceScriptType out)
-> Maybe
     (ConcreteOutput
        (OwnerType out) () (ValueType out) (ReferenceScriptType out))
forall a. a -> Maybe a
Just (ConcreteOutput
   (OwnerType out) () (ValueType out) (ReferenceScriptType out)
 -> Maybe
      (ConcreteOutput
         (OwnerType out) () (ValueType out) (ReferenceScriptType out)))
-> ConcreteOutput
     (OwnerType out) () (ValueType out) (ReferenceScriptType out)
-> Maybe
     (ConcreteOutput
        (OwnerType out) () (ValueType out) (ReferenceScriptType out))
forall a b. (a -> b) -> a -> b
$ (out
-> ConcreteOutput
     (OwnerType out)
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out)
forall out.
IsAbstractOutput out =>
out
-> ConcreteOutput
     (OwnerType out)
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out)
fromAbstractOutput out
out) {concreteOutputDatum = ()}
isOutputWithoutDatum out
_ = Maybe
  (ConcreteOutput
     (OwnerType out) () (ValueType out) (ReferenceScriptType out))
forall a. Maybe a
Nothing

-- | Test if the output carries some inlined datum.
isOutputWithInlineDatum :: (IsTxInfoOutput out) => out -> Maybe (ConcreteOutput (OwnerType out) Api.Datum (ValueType out) (ReferenceScriptType out))
isOutputWithInlineDatum :: forall out.
IsTxInfoOutput out =>
out
-> Maybe
     (ConcreteOutput
        (OwnerType out) Datum (ValueType out) (ReferenceScriptType out))
isOutputWithInlineDatum out
out | Api.OutputDatum datum :: Datum
datum@(Api.Datum BuiltinData
_) <- out -> OutputDatum
forall o.
(IsAbstractOutput o, ToOutputDatum (DatumType o)) =>
o -> OutputDatum
outputOutputDatum out
out = ConcreteOutput
  (OwnerType out) Datum (ValueType out) (ReferenceScriptType out)
-> Maybe
     (ConcreteOutput
        (OwnerType out) Datum (ValueType out) (ReferenceScriptType out))
forall a. a -> Maybe a
Just (ConcreteOutput
   (OwnerType out) Datum (ValueType out) (ReferenceScriptType out)
 -> Maybe
      (ConcreteOutput
         (OwnerType out) Datum (ValueType out) (ReferenceScriptType out)))
-> ConcreteOutput
     (OwnerType out) Datum (ValueType out) (ReferenceScriptType out)
-> Maybe
     (ConcreteOutput
        (OwnerType out) Datum (ValueType out) (ReferenceScriptType out))
forall a b. (a -> b) -> a -> b
$ (out
-> ConcreteOutput
     (OwnerType out)
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out)
forall out.
IsAbstractOutput out =>
out
-> ConcreteOutput
     (OwnerType out)
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out)
fromAbstractOutput out
out) {concreteOutputDatum = datum}
isOutputWithInlineDatum out
_ = Maybe
  (ConcreteOutput
     (OwnerType out) Datum (ValueType out) (ReferenceScriptType out))
forall a. Maybe a
Nothing

-- | Test if the output carries some inlined datum that can be parsed from
-- builtin data on to something of a specific type.
isOutputWithInlineDatumOfType :: (Api.FromData a, IsTxInfoOutput out) => out -> Maybe (ConcreteOutput (OwnerType out) a (ValueType out) (ReferenceScriptType out))
isOutputWithInlineDatumOfType :: forall a out.
(FromData a, IsTxInfoOutput out) =>
out
-> Maybe
     (ConcreteOutput
        (OwnerType out) a (ValueType out) (ReferenceScriptType out))
isOutputWithInlineDatumOfType out
out | Api.OutputDatum (Api.Datum BuiltinData
datum) <- out -> OutputDatum
forall o.
(IsAbstractOutput o, ToOutputDatum (DatumType o)) =>
o -> OutputDatum
outputOutputDatum out
out = (\a
x -> (out
-> ConcreteOutput
     (OwnerType out)
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out)
forall out.
IsAbstractOutput out =>
out
-> ConcreteOutput
     (OwnerType out)
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out)
fromAbstractOutput out
out) {concreteOutputDatum = x}) (a
 -> ConcreteOutput
      (OwnerType out) a (ValueType out) (ReferenceScriptType out))
-> Maybe a
-> Maybe
     (ConcreteOutput
        (OwnerType out) a (ValueType out) (ReferenceScriptType out))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> BuiltinData -> Maybe a
forall a. FromData a => BuiltinData -> Maybe a
Api.fromBuiltinData BuiltinData
datum
isOutputWithInlineDatumOfType out
_ = Maybe
  (ConcreteOutput
     (OwnerType out) a (ValueType out) (ReferenceScriptType out))
forall a. Maybe a
Nothing

-- | Test if the output carries some datum hash.
isOutputWithDatumHash :: (IsTxInfoOutput out) => out -> Maybe (ConcreteOutput (OwnerType out) Api.DatumHash (ValueType out) (ReferenceScriptType out))
isOutputWithDatumHash :: forall out.
IsTxInfoOutput out =>
out
-> Maybe
     (ConcreteOutput
        (OwnerType out)
        DatumHash
        (ValueType out)
        (ReferenceScriptType out))
isOutputWithDatumHash out
out | Api.OutputDatumHash DatumHash
hash <- out -> OutputDatum
forall o.
(IsAbstractOutput o, ToOutputDatum (DatumType o)) =>
o -> OutputDatum
outputOutputDatum out
out = ConcreteOutput
  (OwnerType out) DatumHash (ValueType out) (ReferenceScriptType out)
-> Maybe
     (ConcreteOutput
        (OwnerType out)
        DatumHash
        (ValueType out)
        (ReferenceScriptType out))
forall a. a -> Maybe a
Just (ConcreteOutput
   (OwnerType out) DatumHash (ValueType out) (ReferenceScriptType out)
 -> Maybe
      (ConcreteOutput
         (OwnerType out)
         DatumHash
         (ValueType out)
         (ReferenceScriptType out)))
-> ConcreteOutput
     (OwnerType out) DatumHash (ValueType out) (ReferenceScriptType out)
-> Maybe
     (ConcreteOutput
        (OwnerType out)
        DatumHash
        (ValueType out)
        (ReferenceScriptType out))
forall a b. (a -> b) -> a -> b
$ (out
-> ConcreteOutput
     (OwnerType out)
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out)
forall out.
IsAbstractOutput out =>
out
-> ConcreteOutput
     (OwnerType out)
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out)
fromAbstractOutput out
out) {concreteOutputDatum = hash}
isOutputWithDatumHash out
_ = Maybe
  (ConcreteOutput
     (OwnerType out)
     DatumHash
     (ValueType out)
     (ReferenceScriptType out))
forall a. Maybe a
Nothing

-- ** Filtering on the owner

-- | Test if the owner of an output is a script
isScriptOutput :: (IsTxInfoOutput out) => out -> Maybe (ConcreteOutput Api.ScriptHash (DatumType out) (ValueType out) (ReferenceScriptType out))
isScriptOutput :: forall out.
IsTxInfoOutput out =>
out
-> Maybe
     (ConcreteOutput
        ScriptHash
        (DatumType out)
        (ValueType out)
        (ReferenceScriptType out))
isScriptOutput out
out | Api.Address (Api.ScriptCredential ScriptHash
scriptHash) Maybe StakingCredential
_ <- out -> Address
forall o.
(IsAbstractOutput o, ToCredential (OwnerType o)) =>
o -> Address
outputAddress out
out = ConcreteOutput
  ScriptHash
  (DatumType out)
  (ValueType out)
  (ReferenceScriptType out)
-> Maybe
     (ConcreteOutput
        ScriptHash
        (DatumType out)
        (ValueType out)
        (ReferenceScriptType out))
forall a. a -> Maybe a
Just (ConcreteOutput
   ScriptHash
   (DatumType out)
   (ValueType out)
   (ReferenceScriptType out)
 -> Maybe
      (ConcreteOutput
         ScriptHash
         (DatumType out)
         (ValueType out)
         (ReferenceScriptType out)))
-> ConcreteOutput
     ScriptHash
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out)
-> Maybe
     (ConcreteOutput
        ScriptHash
        (DatumType out)
        (ValueType out)
        (ReferenceScriptType out))
forall a b. (a -> b) -> a -> b
$ (out
-> ConcreteOutput
     (OwnerType out)
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out)
forall out.
IsAbstractOutput out =>
out
-> ConcreteOutput
     (OwnerType out)
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out)
fromAbstractOutput out
out) {concreteOutputOwner = scriptHash}
isScriptOutput out
_ = Maybe
  (ConcreteOutput
     ScriptHash
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out))
forall a. Maybe a
Nothing

-- | Test if the owner of an output is a specific script
isScriptOutputFrom :: (IsTxInfoOutput out, ToScriptHash s) => s -> out -> Maybe (ConcreteOutput s (DatumType out) (ValueType out) (ReferenceScriptType out))
isScriptOutputFrom :: forall out s.
(IsTxInfoOutput out, ToScriptHash s) =>
s
-> out
-> Maybe
     (ConcreteOutput
        s (DatumType out) (ValueType out) (ReferenceScriptType out))
isScriptOutputFrom s
validator out
out = do
  ConcreteOutput
  ScriptHash
  (DatumType out)
  (ValueType out)
  (ReferenceScriptType out)
x <- out
-> Maybe
     (ConcreteOutput
        ScriptHash
        (DatumType out)
        (ValueType out)
        (ReferenceScriptType out))
forall out.
IsTxInfoOutput out =>
out
-> Maybe
     (ConcreteOutput
        ScriptHash
        (DatumType out)
        (ValueType out)
        (ReferenceScriptType out))
isScriptOutput out
out
  if s -> ScriptHash
forall a. ToScriptHash a => a -> ScriptHash
toScriptHash s
validator ScriptHash -> ScriptHash -> Bool
forall a. Eq a => a -> a -> Bool
== ConcreteOutput
  ScriptHash
  (DatumType out)
  (ValueType out)
  (ReferenceScriptType out)
x ConcreteOutput
  ScriptHash
  (DatumType out)
  (ValueType out)
  (ReferenceScriptType out)
-> Optic'
     A_Lens
     NoIx
     (ConcreteOutput
        ScriptHash
        (DatumType out)
        (ValueType out)
        (ReferenceScriptType out))
     ScriptHash
-> ScriptHash
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (ConcreteOutput
     ScriptHash
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out))
  ScriptHash
Lens'
  (ConcreteOutput
     ScriptHash
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out))
  (OwnerType
     (ConcreteOutput
        ScriptHash
        (DatumType out)
        (ValueType out)
        (ReferenceScriptType out)))
forall o. IsAbstractOutput o => Lens' o (OwnerType o)
outputOwnerL
    then ConcreteOutput
  s (DatumType out) (ValueType out) (ReferenceScriptType out)
-> Maybe
     (ConcreteOutput
        s (DatumType out) (ValueType out) (ReferenceScriptType out))
forall a. a -> Maybe a
Just (ConcreteOutput
  ScriptHash
  (DatumType out)
  (ValueType out)
  (ReferenceScriptType out)
x {concreteOutputOwner = validator})
    else Maybe
  (ConcreteOutput
     s (DatumType out) (ValueType out) (ReferenceScriptType out))
forall a. Maybe a
Nothing

-- Test if the owner of an output is a public key
isPKOutput :: (IsTxInfoOutput out) => out -> Maybe (ConcreteOutput Api.PubKeyHash (DatumType out) (ValueType out) (ReferenceScriptType out))
isPKOutput :: forall out.
IsTxInfoOutput out =>
out
-> Maybe
     (ConcreteOutput
        PubKeyHash
        (DatumType out)
        (ValueType out)
        (ReferenceScriptType out))
isPKOutput out
out | Api.Address (Api.PubKeyCredential PubKeyHash
pkh) Maybe StakingCredential
_ <- out -> Address
forall o.
(IsAbstractOutput o, ToCredential (OwnerType o)) =>
o -> Address
outputAddress out
out = ConcreteOutput
  PubKeyHash
  (DatumType out)
  (ValueType out)
  (ReferenceScriptType out)
-> Maybe
     (ConcreteOutput
        PubKeyHash
        (DatumType out)
        (ValueType out)
        (ReferenceScriptType out))
forall a. a -> Maybe a
Just (ConcreteOutput
   PubKeyHash
   (DatumType out)
   (ValueType out)
   (ReferenceScriptType out)
 -> Maybe
      (ConcreteOutput
         PubKeyHash
         (DatumType out)
         (ValueType out)
         (ReferenceScriptType out)))
-> ConcreteOutput
     PubKeyHash
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out)
-> Maybe
     (ConcreteOutput
        PubKeyHash
        (DatumType out)
        (ValueType out)
        (ReferenceScriptType out))
forall a b. (a -> b) -> a -> b
$ (out
-> ConcreteOutput
     (OwnerType out)
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out)
forall out.
IsAbstractOutput out =>
out
-> ConcreteOutput
     (OwnerType out)
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out)
fromAbstractOutput out
out) {concreteOutputOwner = pkh}
isPKOutput out
_ = Maybe
  (ConcreteOutput
     PubKeyHash
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out))
forall a. Maybe a
Nothing

-- | Test if the owner of an output is a specific public key
isPKOutputFrom :: (IsTxInfoOutput out) => Api.PubKeyHash -> out -> Maybe (ConcreteOutput Api.PubKeyHash (DatumType out) (ValueType out) (ReferenceScriptType out))
isPKOutputFrom :: forall out.
IsTxInfoOutput out =>
PubKeyHash
-> out
-> Maybe
     (ConcreteOutput
        PubKeyHash
        (DatumType out)
        (ValueType out)
        (ReferenceScriptType out))
isPKOutputFrom PubKeyHash
pkh out
out = do
  ConcreteOutput
  PubKeyHash
  (DatumType out)
  (ValueType out)
  (ReferenceScriptType out)
x <- out
-> Maybe
     (ConcreteOutput
        PubKeyHash
        (DatumType out)
        (ValueType out)
        (ReferenceScriptType out))
forall out.
IsTxInfoOutput out =>
out
-> Maybe
     (ConcreteOutput
        PubKeyHash
        (DatumType out)
        (ValueType out)
        (ReferenceScriptType out))
isPKOutput out
out
  if PubKeyHash
pkh PubKeyHash -> PubKeyHash -> Bool
forall a. Eq a => a -> a -> Bool
== ConcreteOutput
  PubKeyHash
  (DatumType out)
  (ValueType out)
  (ReferenceScriptType out)
x ConcreteOutput
  PubKeyHash
  (DatumType out)
  (ValueType out)
  (ReferenceScriptType out)
-> Optic'
     A_Lens
     NoIx
     (ConcreteOutput
        PubKeyHash
        (DatumType out)
        (ValueType out)
        (ReferenceScriptType out))
     PubKeyHash
-> PubKeyHash
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (ConcreteOutput
     PubKeyHash
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out))
  PubKeyHash
Lens'
  (ConcreteOutput
     PubKeyHash
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out))
  (OwnerType
     (ConcreteOutput
        PubKeyHash
        (DatumType out)
        (ValueType out)
        (ReferenceScriptType out)))
forall o. IsAbstractOutput o => Lens' o (OwnerType o)
outputOwnerL
    then ConcreteOutput
  PubKeyHash
  (DatumType out)
  (ValueType out)
  (ReferenceScriptType out)
-> Maybe
     (ConcreteOutput
        PubKeyHash
        (DatumType out)
        (ValueType out)
        (ReferenceScriptType out))
forall a. a -> Maybe a
Just ConcreteOutput
  PubKeyHash
  (DatumType out)
  (ValueType out)
  (ReferenceScriptType out)
x
    else Maybe
  (ConcreteOutput
     PubKeyHash
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out))
forall a. Maybe a
Nothing

-- ** Filtering on the staking credential

-- | Test if the given output possesses a certain staking credential
isStakingCredentialOutputFrom :: (IsTxInfoOutput out, ToCredential cred) => cred -> out -> Maybe (ConcreteOutput (OwnerType out) (DatumType out) (ValueType out) (ReferenceScriptType out))
isStakingCredentialOutputFrom :: forall out cred.
(IsTxInfoOutput out, ToCredential cred) =>
cred
-> out
-> Maybe
     (ConcreteOutput
        (OwnerType out)
        (DatumType out)
        (ValueType out)
        (ReferenceScriptType out))
isStakingCredentialOutputFrom cred
cred out
out | Just (Api.StakingHash Credential
cred') <- out
out out
-> Optic' A_Lens NoIx out (Maybe StakingCredential)
-> Maybe StakingCredential
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx out (Maybe StakingCredential)
forall o. IsAbstractOutput o => Lens' o (Maybe StakingCredential)
outputStakingCredentialL, cred -> Credential
forall a. ToCredential a => a -> Credential
toCredential cred
cred Credential -> Credential -> Bool
forall a. Eq a => a -> a -> Bool
== Credential
cred' = ConcreteOutput
  (OwnerType out)
  (DatumType out)
  (ValueType out)
  (ReferenceScriptType out)
-> Maybe
     (ConcreteOutput
        (OwnerType out)
        (DatumType out)
        (ValueType out)
        (ReferenceScriptType out))
forall a. a -> Maybe a
Just (ConcreteOutput
   (OwnerType out)
   (DatumType out)
   (ValueType out)
   (ReferenceScriptType out)
 -> Maybe
      (ConcreteOutput
         (OwnerType out)
         (DatumType out)
         (ValueType out)
         (ReferenceScriptType out)))
-> ConcreteOutput
     (OwnerType out)
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out)
-> Maybe
     (ConcreteOutput
        (OwnerType out)
        (DatumType out)
        (ValueType out)
        (ReferenceScriptType out))
forall a b. (a -> b) -> a -> b
$ out
-> ConcreteOutput
     (OwnerType out)
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out)
forall out.
IsAbstractOutput out =>
out
-> ConcreteOutput
     (OwnerType out)
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out)
fromAbstractOutput out
out
isStakingCredentialOutputFrom cred
_ out
_ = Maybe
  (ConcreteOutput
     (OwnerType out)
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out))
forall a. Maybe a
Nothing

-- | Test if the give output does not possess any staking credential
isEmptyStakingCredentialOutput :: (IsTxInfoOutput out) => out -> Maybe (ConcreteOutput (OwnerType out) (DatumType out) (ValueType out) (ReferenceScriptType out))
isEmptyStakingCredentialOutput :: forall out.
IsTxInfoOutput out =>
out
-> Maybe
     (ConcreteOutput
        (OwnerType out)
        (DatumType out)
        (ValueType out)
        (ReferenceScriptType out))
isEmptyStakingCredentialOutput out
out | Maybe StakingCredential
Nothing <- out
out out
-> Optic' A_Lens NoIx out (Maybe StakingCredential)
-> Maybe StakingCredential
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx out (Maybe StakingCredential)
forall o. IsAbstractOutput o => Lens' o (Maybe StakingCredential)
outputStakingCredentialL = ConcreteOutput
  (OwnerType out)
  (DatumType out)
  (ValueType out)
  (ReferenceScriptType out)
-> Maybe
     (ConcreteOutput
        (OwnerType out)
        (DatumType out)
        (ValueType out)
        (ReferenceScriptType out))
forall a. a -> Maybe a
Just (ConcreteOutput
   (OwnerType out)
   (DatumType out)
   (ValueType out)
   (ReferenceScriptType out)
 -> Maybe
      (ConcreteOutput
         (OwnerType out)
         (DatumType out)
         (ValueType out)
         (ReferenceScriptType out)))
-> ConcreteOutput
     (OwnerType out)
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out)
-> Maybe
     (ConcreteOutput
        (OwnerType out)
        (DatumType out)
        (ValueType out)
        (ReferenceScriptType out))
forall a b. (a -> b) -> a -> b
$ out
-> ConcreteOutput
     (OwnerType out)
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out)
forall out.
IsAbstractOutput out =>
out
-> ConcreteOutput
     (OwnerType out)
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out)
fromAbstractOutput out
out
isEmptyStakingCredentialOutput out
_ = Maybe
  (ConcreteOutput
     (OwnerType out)
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out))
forall a. Maybe a
Nothing

-- ** Filtering on the value

-- | Test if the value on an output contains only Ada.
isOnlyAdaOutput :: (IsTxInfoOutput out) => out -> Maybe (ConcreteOutput (OwnerType out) (DatumType out) Script.Ada (ReferenceScriptType out))
isOnlyAdaOutput :: forall out.
IsTxInfoOutput out =>
out
-> Maybe
     (ConcreteOutput
        (OwnerType out) (DatumType out) Ada (ReferenceScriptType out))
isOnlyAdaOutput out
out | Value -> Bool
Script.isAdaOnlyValue (out -> Value
forall o. (IsAbstractOutput o, ToValue (ValueType o)) => o -> Value
outputValue out
out) = ConcreteOutput
  (OwnerType out) (DatumType out) Ada (ReferenceScriptType out)
-> Maybe
     (ConcreteOutput
        (OwnerType out) (DatumType out) Ada (ReferenceScriptType out))
forall a. a -> Maybe a
Just (ConcreteOutput
   (OwnerType out) (DatumType out) Ada (ReferenceScriptType out)
 -> Maybe
      (ConcreteOutput
         (OwnerType out) (DatumType out) Ada (ReferenceScriptType out)))
-> ConcreteOutput
     (OwnerType out) (DatumType out) Ada (ReferenceScriptType out)
-> Maybe
     (ConcreteOutput
        (OwnerType out) (DatumType out) Ada (ReferenceScriptType out))
forall a b. (a -> b) -> a -> b
$ (out
-> ConcreteOutput
     (OwnerType out)
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out)
forall out.
IsAbstractOutput out =>
out
-> ConcreteOutput
     (OwnerType out)
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out)
fromAbstractOutput out
out) {concreteOutputValue = Script.fromValue $ outputValue out}
isOnlyAdaOutput out
_ = Maybe
  (ConcreteOutput
     (OwnerType out) (DatumType out) Ada (ReferenceScriptType out))
forall a. Maybe a
Nothing

-- ** Filtering on the reference script

-- | Convert the reference script type on the output to 'Api.ScriptHash'.
toOutputWithReferenceScriptHash :: (IsTxInfoOutput out) => out -> ConcreteOutput (OwnerType out) (DatumType out) (ValueType out) Api.ScriptHash
toOutputWithReferenceScriptHash :: forall out.
IsTxInfoOutput out =>
out
-> ConcreteOutput
     (OwnerType out) (DatumType out) (ValueType out) ScriptHash
toOutputWithReferenceScriptHash out
out = (out
-> ConcreteOutput
     (OwnerType out)
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out)
forall out.
IsAbstractOutput out =>
out
-> ConcreteOutput
     (OwnerType out)
     (DatumType out)
     (ValueType out)
     (ReferenceScriptType out)
fromAbstractOutput out
out) {concreteOutputReferenceScript = toScriptHash <$> out ^. outputReferenceScriptL}

-- | Test if the reference script in an output is a specific script
isReferenceScriptOutputFrom :: (IsTxInfoOutput out, ToScriptHash s) => s -> out -> Maybe (ConcreteOutput (OwnerType out) (DatumType out) (ValueType out) Api.ScriptHash)
isReferenceScriptOutputFrom :: forall out s.
(IsTxInfoOutput out, ToScriptHash s) =>
s
-> out
-> Maybe
     (ConcreteOutput
        (OwnerType out) (DatumType out) (ValueType out) ScriptHash)
isReferenceScriptOutputFrom s
script out
out | Just ReferenceScriptType out
x <- out
out out
-> Optic' A_Lens NoIx out (Maybe (ReferenceScriptType out))
-> Maybe (ReferenceScriptType out)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx out (Maybe (ReferenceScriptType out))
forall o.
IsAbstractOutput o =>
Lens' o (Maybe (ReferenceScriptType o))
outputReferenceScriptL, ReferenceScriptType out -> ScriptHash
forall a. ToScriptHash a => a -> ScriptHash
toScriptHash ReferenceScriptType out
x ScriptHash -> ScriptHash -> Bool
forall a. Eq a => a -> a -> Bool
== s -> ScriptHash
forall a. ToScriptHash a => a -> ScriptHash
toScriptHash s
script = ConcreteOutput
  (OwnerType out) (DatumType out) (ValueType out) ScriptHash
-> Maybe
     (ConcreteOutput
        (OwnerType out) (DatumType out) (ValueType out) ScriptHash)
forall a. a -> Maybe a
Just (ConcreteOutput
   (OwnerType out) (DatumType out) (ValueType out) ScriptHash
 -> Maybe
      (ConcreteOutput
         (OwnerType out) (DatumType out) (ValueType out) ScriptHash))
-> ConcreteOutput
     (OwnerType out) (DatumType out) (ValueType out) ScriptHash
-> Maybe
     (ConcreteOutput
        (OwnerType out) (DatumType out) (ValueType out) ScriptHash)
forall a b. (a -> b) -> a -> b
$ out
-> ConcreteOutput
     (OwnerType out) (DatumType out) (ValueType out) ScriptHash
forall out.
IsTxInfoOutput out =>
out
-> ConcreteOutput
     (OwnerType out) (DatumType out) (ValueType out) ScriptHash
toOutputWithReferenceScriptHash out
out
isReferenceScriptOutputFrom s
_ out
_ = Maybe
  (ConcreteOutput
     (OwnerType out) (DatumType out) (ValueType out) ScriptHash)
forall a. Maybe a
Nothing