{- |
Module      : Singular.State.Publication
Description : Publish the scripts of an application once and reuse the live copies
License     : Apache-2.0

A transaction that runs the state validator or the application's validator
carries its code from a reference output. The first registry of an application
publishes both scripts; a later registry finds the live copies and publishes
nothing. A copy is live when an output of the chain carries a reference script
whose hash, computed from the script itself, is the expected one; an output
that carries another script is never reused, whatever the provider claims.
-}
module Singular.State.Publication
    ( References (..)
    , Publication (..)
    , ReferenceDiscovery (..)
    , planReferences
    , planNextReference
    ) where

import Control.Exception (throwIO)
import Control.Monad.Except (ExceptT (..), runExceptT, throwError)
import Control.Monad.IO.Class (liftIO)
import Data.List (minimumBy, nubBy)
import Data.Maybe (catMaybes)
import Data.Ord (comparing)
import Lens.Micro ((&), (.~), (^.))

import Cardano.Ledger.Address (Addr)
import Cardano.Ledger.Api.Tx (bodyTxL, txIdTx)
import Cardano.Ledger.Api.Tx.Body (outputsTxBodyL)
import Cardano.Ledger.Api.Tx.Out
    ( coinTxOutL
    , getMinCoinTxOut
    , mkBasicTxOut
    , referenceScriptTxOutL
    )
import Cardano.Ledger.BaseTypes
    ( Inject (..)
    , StrictMaybe (..)
    , TxIx (..)
    )
import Cardano.Ledger.Coin (Coin (..))
import Cardano.Ledger.Core (PParams, Script, hashScript)
import Cardano.Ledger.Hashes (ScriptHash)
import Cardano.Ledger.TxIn (TxIn (..))
import Cardano.Tx.Build qualified as Tx
import Cardano.Tx.Ledger (ConwayTx)
import Data.Foldable (toList)

import Singular.Registry.Evidence (NoWitness)
import Singular.Registry.Ledger (ConwayEra, TxOut)
import Singular.Registry.LedgerProvider
    ( OutputQuery (..)
    , Session
    )
import Singular.Registry.SessionIO (parameters)
import Singular.State.Assemble
    ( Payer (..)
    , assembleTransaction
    , noUsableWindow
    , readOutputs
    , resolvePayerReserving
    , usualSpan
    , windowFromTip
    )
import Singular.State.Refusal (Refusal (..))

-- | The transaction that publishes the scripts no live output carries.
data Publication = Publication
    { Publication -> ConwayTx
publicationTx :: ConwayTx
    , Publication -> [(ScriptHash, TxIn)]
publicationOutputs :: [(ScriptHash, TxIn)]
    {- ^ Where each published script will sit once the transaction is on the
    chain
    -}
    }

-- | Where the scripts of an application can be read from.
data References = References
    { References -> [(ScriptHash, (TxIn, TxOut ConwayEra))]
referencesLive :: [(ScriptHash, (TxIn, TxOut ConwayEra))]
    -- ^ The live copies that are reused
    , References -> Maybe Publication
referencesPublication :: Maybe Publication
    -- ^ The publication of the others; nothing when every script is live
    , References -> [ReferenceDiscovery]
referencesDiscovery :: [ReferenceDiscovery]
    -- ^ Every candidate inspected for each requested script
    }

{- | Discovery evidence for a script. An empty list means that this provider
returned no live copy, without distinguishing a spent output from one that
never existed. A candidate carries its actual script hash, or no script.
-}
data ReferenceDiscovery = ReferenceDiscovery
    { ReferenceDiscovery -> ScriptHash
discoveryHash :: ScriptHash
    -- ^ The expected hash of the requested script
    , ReferenceDiscovery -> [(TxIn, Maybe ScriptHash)]
discoveryCandidates :: [(TxIn, Maybe ScriptHash)]
    -- ^ Output references and hashes computed from their carried scripts
    }
    deriving stock (ReferenceDiscovery -> ReferenceDiscovery -> Bool
(ReferenceDiscovery -> ReferenceDiscovery -> Bool)
-> (ReferenceDiscovery -> ReferenceDiscovery -> Bool)
-> Eq ReferenceDiscovery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ReferenceDiscovery -> ReferenceDiscovery -> Bool
== :: ReferenceDiscovery -> ReferenceDiscovery -> Bool
$c/= :: ReferenceDiscovery -> ReferenceDiscovery -> Bool
/= :: ReferenceDiscovery -> ReferenceDiscovery -> Bool
Eq, Int -> ReferenceDiscovery -> ShowS
[ReferenceDiscovery] -> ShowS
ReferenceDiscovery -> String
(Int -> ReferenceDiscovery -> ShowS)
-> (ReferenceDiscovery -> String)
-> ([ReferenceDiscovery] -> ShowS)
-> Show ReferenceDiscovery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ReferenceDiscovery -> ShowS
showsPrec :: Int -> ReferenceDiscovery -> ShowS
$cshow :: ReferenceDiscovery -> String
show :: ReferenceDiscovery -> String
$cshowList :: [ReferenceDiscovery] -> ShowS
showList :: [ReferenceDiscovery] -> ShowS
Show)

{- | Find the live copy of each script and plan the publication of the others,
at the payer's address: one transaction that holds every missing script in an
output of its own.
-}
planReferences
    :: Session NoWitness IO
    -> Addr
    -- ^ The payer: fee, collateral, change and the owner of the new outputs
    -> [Script ConwayEra]
    -> IO (Either Refusal References)
planReferences :: Session NoWitness IO
-> Addr -> [Script ConwayEra] -> IO (Either Refusal References)
planReferences = ([Script ConwayEra] -> [Script ConwayEra])
-> [TxIn]
-> Session NoWitness IO
-> Addr
-> [Script ConwayEra]
-> IO (Either Refusal References)
planPublications [AlonzoScript ConwayEra] -> [AlonzoScript ConwayEra]
[Script ConwayEra] -> [Script ConwayEra]
forall a. a -> a
id []

{- | Find every live copy and plan one missing script's publication, in the
order requested. Call again after that transaction is live, using the new
chain view. Each transaction is size-checked independently, and the reserved
wallet outputs are left unspent for the later creation.
-}
planNextReference
    :: [TxIn]
    -- ^ Wallet outputs reserved for the later transaction
    -> Session NoWitness IO
    -> Addr
    -> [Script ConwayEra]
    -> IO (Either Refusal References)
planNextReference :: [TxIn]
-> Session NoWitness IO
-> Addr
-> [Script ConwayEra]
-> IO (Either Refusal References)
planNextReference = ([Script ConwayEra] -> [Script ConwayEra])
-> [TxIn]
-> Session NoWitness IO
-> Addr
-> [Script ConwayEra]
-> IO (Either Refusal References)
planPublications (Int -> [AlonzoScript ConwayEra] -> [AlonzoScript ConwayEra]
forall a. Int -> [a] -> [a]
take Int
1)

-- | Share authenticated discovery between batch and sequential publication.
planPublications
    :: ([Script ConwayEra] -> [Script ConwayEra])
    -> [TxIn]
    -> Session NoWitness IO
    -> Addr
    -> [Script ConwayEra]
    -> IO (Either Refusal References)
planPublications :: ([Script ConwayEra] -> [Script ConwayEra])
-> [TxIn]
-> Session NoWitness IO
-> Addr
-> [Script ConwayEra]
-> IO (Either Refusal References)
planPublications [Script ConwayEra] -> [Script ConwayEra]
choose [TxIn]
reserved Session NoWitness IO
session Addr
payerAddress [Script ConwayEra]
requested = ExceptT Refusal IO References -> IO (Either Refusal References)
forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT (ExceptT Refusal IO References -> IO (Either Refusal References))
-> ExceptT Refusal IO References -> IO (Either Refusal References)
forall a b. (a -> b) -> a -> b
$ do
    found <-
        IO
  [(AlonzoScript ConwayEra,
    (Maybe (TxIn, BabbageTxOut ConwayEra), ReferenceDiscovery))]
-> ExceptT
     Refusal
     IO
     [(AlonzoScript ConwayEra,
       (Maybe (TxIn, BabbageTxOut ConwayEra), ReferenceDiscovery))]
forall a. IO a -> ExceptT Refusal IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
            ((AlonzoScript ConwayEra
 -> IO
      (AlonzoScript ConwayEra,
       (Maybe (TxIn, BabbageTxOut ConwayEra), ReferenceDiscovery)))
-> [AlonzoScript ConwayEra]
-> IO
     [(AlonzoScript ConwayEra,
       (Maybe (TxIn, BabbageTxOut ConwayEra), ReferenceDiscovery))]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (\AlonzoScript ConwayEra
script -> (,) AlonzoScript ConwayEra
script ((Maybe (TxIn, BabbageTxOut ConwayEra), ReferenceDiscovery)
 -> (AlonzoScript ConwayEra,
     (Maybe (TxIn, BabbageTxOut ConwayEra), ReferenceDiscovery)))
-> IO (Maybe (TxIn, BabbageTxOut ConwayEra), ReferenceDiscovery)
-> IO
     (AlonzoScript ConwayEra,
      (Maybe (TxIn, BabbageTxOut ConwayEra), ReferenceDiscovery))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Session NoWitness IO
-> Script ConwayEra
-> IO (Maybe (TxIn, TxOut ConwayEra), ReferenceDiscovery)
liveCopy Session NoWitness IO
session AlonzoScript ConwayEra
Script ConwayEra
script) [AlonzoScript ConwayEra]
scripts)
    let live = [(Script ConwayEra -> ScriptHash
forall era. EraScript era => Script era -> ScriptHash
hashScript AlonzoScript ConwayEra
Script ConwayEra
script, (TxIn, BabbageTxOut ConwayEra)
copy) | (AlonzoScript ConwayEra
script, (Just (TxIn, BabbageTxOut ConwayEra)
copy, ReferenceDiscovery
_)) <- [(AlonzoScript ConwayEra,
  (Maybe (TxIn, BabbageTxOut ConwayEra), ReferenceDiscovery))]
found]
        missing = [AlonzoScript ConwayEra
script | (AlonzoScript ConwayEra
script, (Maybe (TxIn, BabbageTxOut ConwayEra)
Nothing, ReferenceDiscovery
_)) <- [(AlonzoScript ConwayEra,
  (Maybe (TxIn, BabbageTxOut ConwayEra), ReferenceDiscovery))]
found]
    publication <-
        if null missing
            then pure Nothing
            else
                Just
                    <$> ExceptT (publish reserved session payerAddress (choose missing))
    pure (References live publication (map (snd . snd) found))
  where
    scripts :: [Script ConwayEra]
scripts = (Script ConwayEra -> Script ConwayEra -> Bool)
-> [Script ConwayEra] -> [Script ConwayEra]
forall a. (a -> a -> Bool) -> [a] -> [a]
nubBy (\Script ConwayEra
a Script ConwayEra
b -> Script ConwayEra -> ScriptHash
forall era. EraScript era => Script era -> ScriptHash
hashScript Script ConwayEra
a ScriptHash -> ScriptHash -> Bool
forall a. Eq a => a -> a -> Bool
== Script ConwayEra -> ScriptHash
forall era. EraScript era => Script era -> ScriptHash
hashScript Script ConwayEra
b) [Script ConwayEra]
requested

{- | The live output with the lowest reference that carries this script as a
reference script. The provider's answer to the query is a list of candidates:
each one is checked against the hash of the script.
-}
liveCopy
    :: Session NoWitness IO
    -> Script ConwayEra
    -> IO (Maybe (TxIn, TxOut ConwayEra), ReferenceDiscovery)
liveCopy :: Session NoWitness IO
-> Script ConwayEra
-> IO (Maybe (TxIn, TxOut ConwayEra), ReferenceDiscovery)
liveCopy Session NoWitness IO
session Script ConwayEra
script = do
    candidates <-
        Session NoWitness IO
-> OutputQuery -> IO (Either ReadFailure Outputs)
readOutputs Session NoWitness IO
session (ScriptHash -> OutputQuery
CarryingReferenceScript ScriptHash
hash)
            IO (Either ReadFailure [(TxIn, BabbageTxOut ConwayEra)])
-> (Either ReadFailure [(TxIn, BabbageTxOut ConwayEra)]
    -> IO [(TxIn, BabbageTxOut ConwayEra)])
-> IO [(TxIn, BabbageTxOut ConwayEra)]
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (ReadFailure -> IO [(TxIn, BabbageTxOut ConwayEra)])
-> ([(TxIn, BabbageTxOut ConwayEra)]
    -> IO [(TxIn, BabbageTxOut ConwayEra)])
-> Either ReadFailure [(TxIn, BabbageTxOut ConwayEra)]
-> IO [(TxIn, BabbageTxOut ConwayEra)]
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either ReadFailure -> IO [(TxIn, BabbageTxOut ConwayEra)]
forall e a. (HasCallStack, Exception e) => e -> IO a
throwIO [(TxIn, BabbageTxOut ConwayEra)]
-> IO [(TxIn, BabbageTxOut ConwayEra)]
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
    let inspected = [((TxIn, BabbageTxOut ConwayEra)
copy, TxOut ConwayEra -> Maybe ScriptHash
forall {era}.
(Assert
   (OrdCond
      (CmpNat (ProtVerLow era) (ProtVerHigh era)) 'True 'True 'False)
   (TypeError ...),
 Assert
   (OrdCond (CmpNat 0 (ProtVerLow era)) 'True 'True 'False)
   (TypeError ...),
 Assert
   (OrdCond (CmpNat 0 (ProtVerHigh era)) 'True 'True 'False)
   (TypeError ...),
 BabbageEraTxOut era) =>
TxOut era -> Maybe ScriptHash
carried TxOut ConwayEra
BabbageTxOut ConwayEra
output) | copy :: (TxIn, BabbageTxOut ConwayEra)
copy@(TxIn
_, BabbageTxOut ConwayEra
output) <- [(TxIn, BabbageTxOut ConwayEra)]
candidates]
        genuine = [(TxIn, BabbageTxOut ConwayEra)
copy | ((TxIn, BabbageTxOut ConwayEra)
copy, Just ScriptHash
actual) <- [((TxIn, BabbageTxOut ConwayEra), Maybe ScriptHash)]
inspected, ScriptHash
actual ScriptHash -> ScriptHash -> Bool
forall a. Eq a => a -> a -> Bool
== ScriptHash
hash]
        selected = case [(TxIn, BabbageTxOut ConwayEra)]
genuine of
            [] -> Maybe (TxIn, BabbageTxOut ConwayEra)
forall a. Maybe a
Nothing
            [(TxIn, BabbageTxOut ConwayEra)]
copies -> (TxIn, BabbageTxOut ConwayEra)
-> Maybe (TxIn, BabbageTxOut ConwayEra)
forall a. a -> Maybe a
Just (((TxIn, BabbageTxOut ConwayEra)
 -> (TxIn, BabbageTxOut ConwayEra) -> Ordering)
-> [(TxIn, BabbageTxOut ConwayEra)]
-> (TxIn, BabbageTxOut ConwayEra)
forall (t :: * -> *) a.
Foldable t =>
(a -> a -> Ordering) -> t a -> a
minimumBy (((TxIn, BabbageTxOut ConwayEra) -> TxIn)
-> (TxIn, BabbageTxOut ConwayEra)
-> (TxIn, BabbageTxOut ConwayEra)
-> Ordering
forall a b. Ord a => (b -> a) -> b -> b -> Ordering
comparing (TxIn, BabbageTxOut ConwayEra) -> TxIn
forall a b. (a, b) -> a
fst) [(TxIn, BabbageTxOut ConwayEra)]
copies)
    pure
        ( selected
        , ReferenceDiscovery
            hash
            [(ref, actual) | ((ref, _), actual) <- inspected]
        )
  where
    hash :: ScriptHash
hash = Script ConwayEra -> ScriptHash
forall era. EraScript era => Script era -> ScriptHash
hashScript Script ConwayEra
script
    carried :: TxOut era -> Maybe ScriptHash
carried TxOut era
output = case TxOut era
output TxOut era
-> Getting
     (StrictMaybe (Script era)) (TxOut era) (StrictMaybe (Script era))
-> StrictMaybe (Script era)
forall s a. s -> Getting a s a -> a
^. Getting
  (StrictMaybe (Script era)) (TxOut era) (StrictMaybe (Script era))
forall era.
BabbageEraTxOut era =>
Lens' (TxOut era) (StrictMaybe (Script era))
Lens' (TxOut era) (StrictMaybe (Script era))
referenceScriptTxOutL of
        SJust Script era
scriptFound -> ScriptHash -> Maybe ScriptHash
forall a. a -> Maybe a
Just (Script era -> ScriptHash
forall era. EraScript era => Script era -> ScriptHash
hashScript Script era
scriptFound)
        StrictMaybe (Script era)
SNothing -> Maybe ScriptHash
forall a. Maybe a
Nothing

-- | Publish these scripts, each in an output of the payer's address.
publish
    :: [TxIn]
    -> Session NoWitness IO
    -> Addr
    -> [Script ConwayEra]
    -> IO (Either Refusal Publication)
publish :: [TxIn]
-> Session NoWitness IO
-> Addr
-> [Script ConwayEra]
-> IO (Either Refusal Publication)
publish [TxIn]
reserved Session NoWitness IO
session Addr
payerAddress [Script ConwayEra]
missing = ExceptT Refusal IO Publication -> IO (Either Refusal Publication)
forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT (ExceptT Refusal IO Publication -> IO (Either Refusal Publication))
-> ExceptT Refusal IO Publication
-> IO (Either Refusal Publication)
forall a b. (a -> b) -> a -> b
$ do
    payer <- IO (Either Refusal Payer) -> ExceptT Refusal IO Payer
forall e (m :: * -> *) a. m (Either e a) -> ExceptT e m a
ExceptT ([TxIn] -> Session NoWitness IO -> Addr -> IO (Either Refusal Payer)
resolvePayerReserving [TxIn]
reserved Session NoWitness IO
session Addr
payerAddress)
    protocol <- liftIO (parameters session)
    upper <-
        liftIO (windowFromTip session usualSpan)
            >>= maybe (throwError (BuildFailed noUsableWindow)) (pure . snd)
    let holders = (AlonzoScript ConwayEra -> BabbageTxOut ConwayEra)
-> [AlonzoScript ConwayEra] -> [BabbageTxOut ConwayEra]
forall a b. (a -> b) -> [a] -> [b]
map (PParams ConwayEra -> Addr -> Script ConwayEra -> TxOut ConwayEra
holder PParams ConwayEra
protocol Addr
payerAddress) [AlonzoScript ConwayEra]
[Script ConwayEra]
missing
    tx <-
        ExceptT $
            assembleTransaction
                session
                [payerFunding payer]
                []
                payerAddress
                ( mapM_ Tx.output holders
                    >> Tx.validTo upper
                    >> Tx.checkTxSize protocol
                )
    pure (Publication tx (located tx))
  where
    located :: Tx l era -> [(ScriptHash, TxIn)]
located Tx l era
tx =
        [Maybe (ScriptHash, TxIn)] -> [(ScriptHash, TxIn)]
forall a. [Maybe a] -> [a]
catMaybes
            [ case TxOut era
out TxOut era
-> Getting
     (StrictMaybe (Script era)) (TxOut era) (StrictMaybe (Script era))
-> StrictMaybe (Script era)
forall s a. s -> Getting a s a -> a
^. Getting
  (StrictMaybe (Script era)) (TxOut era) (StrictMaybe (Script era))
forall era.
BabbageEraTxOut era =>
Lens' (TxOut era) (StrictMaybe (Script era))
Lens' (TxOut era) (StrictMaybe (Script era))
referenceScriptTxOutL of
                SJust Script era
carried ->
                    (ScriptHash, TxIn) -> Maybe (ScriptHash, TxIn)
forall a. a -> Maybe a
Just (Script era -> ScriptHash
forall era. EraScript era => Script era -> ScriptHash
hashScript Script era
carried, TxId -> TxIx -> TxIn
TxIn (Tx l era -> TxId
forall era (l :: TxLevel). EraTx era => Tx l era -> TxId
txIdTx Tx l era
tx) (Word16 -> TxIx
TxIx Word16
ix))
                StrictMaybe (Script era)
SNothing -> Maybe (ScriptHash, TxIn)
forall a. Maybe a
Nothing
            | (Word16
ix, TxOut era
out) <- [Word16] -> [TxOut era] -> [(Word16, TxOut era)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Word16
0 ..] (StrictSeq (TxOut era) -> [TxOut era]
forall a. StrictSeq a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (Tx l era
tx Tx l era
-> Getting
     (StrictSeq (TxOut era)) (Tx l era) (StrictSeq (TxOut era))
-> StrictSeq (TxOut era)
forall s a. s -> Getting a s a -> a
^. (TxBody l era -> Const (StrictSeq (TxOut era)) (TxBody l era))
-> Tx l era -> Const (StrictSeq (TxOut era)) (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody l era -> Const (StrictSeq (TxOut era)) (TxBody l era))
 -> Tx l era -> Const (StrictSeq (TxOut era)) (Tx l era))
-> ((StrictSeq (TxOut era)
     -> Const (StrictSeq (TxOut era)) (StrictSeq (TxOut era)))
    -> TxBody l era -> Const (StrictSeq (TxOut era)) (TxBody l era))
-> Getting
     (StrictSeq (TxOut era)) (Tx l era) (StrictSeq (TxOut era))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StrictSeq (TxOut era)
 -> Const (StrictSeq (TxOut era)) (StrictSeq (TxOut era)))
-> TxBody l era -> Const (StrictSeq (TxOut era)) (TxBody l era)
forall era (l :: TxLevel).
EraTxBody era =>
Lens' (TxBody l era) (StrictSeq (TxOut era))
forall (l :: TxLevel). Lens' (TxBody l era) (StrictSeq (TxOut era))
outputsTxBodyL))
            ]

{- | An output at the address that carries the script as a reference script,
holding the minimum ADA the ledger requires of it.
-}
holder
    :: PParams ConwayEra
    -> Addr
    -> Script ConwayEra
    -> TxOut ConwayEra
holder :: PParams ConwayEra -> Addr -> Script ConwayEra -> TxOut ConwayEra
holder PParams ConwayEra
protocol Addr
address Script ConwayEra
script =
    BabbageTxOut ConwayEra
probe BabbageTxOut ConwayEra
-> (BabbageTxOut ConwayEra -> BabbageTxOut ConwayEra)
-> BabbageTxOut ConwayEra
forall a b. a -> (a -> b) -> b
& (Coin -> Identity Coin)
-> TxOut ConwayEra -> Identity (TxOut ConwayEra)
(Coin -> Identity Coin)
-> BabbageTxOut ConwayEra -> Identity (BabbageTxOut ConwayEra)
forall era. (HasCallStack, EraTxOut era) => Lens' (TxOut era) Coin
Lens' (TxOut ConwayEra) Coin
coinTxOutL ((Coin -> Identity Coin)
 -> BabbageTxOut ConwayEra -> Identity (BabbageTxOut ConwayEra))
-> Coin -> BabbageTxOut ConwayEra -> BabbageTxOut ConwayEra
forall s t a b. ASetter s t a b -> b -> s -> t
.~ PParams ConwayEra -> TxOut ConwayEra -> Coin
forall era. EraTxOut era => PParams era -> TxOut era -> Coin
getMinCoinTxOut PParams ConwayEra
protocol TxOut ConwayEra
BabbageTxOut ConwayEra
probe
  where
    probe :: TxOut ConwayEra
probe =
        Addr -> Value ConwayEra -> TxOut ConwayEra
forall era.
(EraTxOut era, HasCallStack) =>
Addr -> Value era -> TxOut era
mkBasicTxOut Addr
address (Coin -> Value ConwayEra
forall t s. Inject t s => t -> s
inject (Integer -> Coin
Coin Integer
1_000_000_000))
            TxOut ConwayEra
-> (TxOut ConwayEra -> TxOut ConwayEra) -> TxOut ConwayEra
forall a b. a -> (a -> b) -> b
& (StrictMaybe (Script ConwayEra)
 -> Identity (StrictMaybe (Script ConwayEra)))
-> TxOut ConwayEra -> Identity (TxOut ConwayEra)
forall era.
BabbageEraTxOut era =>
Lens' (TxOut era) (StrictMaybe (Script era))
Lens' (TxOut ConwayEra) (StrictMaybe (Script ConwayEra))
referenceScriptTxOutL ((StrictMaybe (Script ConwayEra)
  -> Identity (StrictMaybe (Script ConwayEra)))
 -> TxOut ConwayEra -> Identity (TxOut ConwayEra))
-> StrictMaybe (Script ConwayEra)
-> TxOut ConwayEra
-> TxOut ConwayEra
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Script ConwayEra -> StrictMaybe (Script ConwayEra)
forall a. a -> StrictMaybe a
SJust Script ConwayEra
script