cooked-validators
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cooked.MockChain.UtxoSearch

Description

This module provides a convenient framework to look through UTxOs and search relevant ones based on predicates. For instance, it makes it very convenient to gather all UTxOs at a certain address.

Synopsis

Documentation

type UtxoSearch m a = ListT m (TxOutRef, a) Source #

If a UTxO is a TxOutRef with some additional information, this type captures a "stream" of UTxOs.

runUtxoSearch :: Monad m => UtxoSearch m a -> m [(TxOutRef, a)] Source #

Given a UTxO search, we can run it to obtain a list of UTxOs.

allUtxosSearch :: MonadBlockChain m => UtxoSearch m TxOut Source #

Search all currently known TxOutRefs together with their corresponding TxOut.

utxosAtSearch :: (MonadBlockChainBalancing m, ToAddress addr) => addr -> UtxoSearch m TxOut Source #

Search all TxOutRefs at a certain address, together with their TxOut.

utxosFromCardanoTxSearch :: Monad m => CardanoTx -> UtxoSearch m TxOut Source #

Search all TxOutRefs of a transaction, together with their TxOut.

txOutByRefSearch :: MonadBlockChainBalancing m => [TxOutRef] -> UtxoSearch m TxOut Source #

Search all TxOuts corresponding to given the list of TxOutRefs. Any TxOutRef that doesn't correspond to a known output will be filtered out.

filterWith :: Monad m => UtxoSearch m a -> (a -> m (Maybe b)) -> UtxoSearch m b Source #

Transform a UtxoSearch by applying a possibly partial monadic transformation on each output in the stream

filterWithPure :: Monad m => UtxoSearch m a -> (a -> Maybe b) -> UtxoSearch m b Source #

Same as filterWith but with a pure transformation

filterWithOptic :: (Is k An_AffineFold, Monad m) => UtxoSearch m a -> Optic' k is a b -> UtxoSearch m b Source #

Some as filterWithPure, but the transformation is taken from an optic

filterWithPred :: Monad m => UtxoSearch m a -> (a -> Bool) -> UtxoSearch m a Source #

Same as filterWithPure but the outputs are selected using a boolean predicate, and not modified

filterWithValuePred :: Monad m => UtxoSearch m TxOut -> (Value -> Bool) -> UtxoSearch m Value Source #

A specific version of filterWithPred where outputs must me of type TxOut and the predicate only relies on their value

filterWithOnlyAda :: Monad m => UtxoSearch m TxOut -> UtxoSearch m Value Source #

A specific version of filterWithValuePred when TxOuts are only kept when they contain only ADA

filterWithNotOnlyAda :: Monad m => UtxoSearch m TxOut -> UtxoSearch m Value Source #

A specific version of filterWithValuePred when TxOuts are only kept when they contain non-ADA assets

onlyValueOutputsAtSearch :: (MonadBlockChainBalancing m, ToAddress addr) => addr -> UtxoSearch m (ConcreteOutput Credential () Value ScriptHash) Source #

Search for UTxOs at a specific address, which only carry address and value information (no datum, staking credential, or reference script).

vanillaOutputsAtSearch :: (MonadBlockChainBalancing m, ToAddress addr) => addr -> UtxoSearch m (ConcreteOutput Credential () Lovelace ScriptHash) Source #

Same as onlyValueOutputsAtSearch, but also ensures the returned outputs do not contain non-ADA assets. These "vanilla" outputs are perfect candidates to be used for balancing transaction and attaching collaterals.

filterWithAlways :: Monad m => UtxoSearch m a -> (a -> b) -> UtxoSearch m b Source #

Some as filterWithPure but with a total transformation

scriptOutputsSearch :: (MonadBlockChain m, ToScriptHash s) => s -> UtxoSearch m (ConcreteOutput s OutputDatum Value ScriptHash) Source #

Searches for all outputs belonging to a given script

referenceScriptOutputsSearch :: (MonadBlockChain m, ToScriptHash s) => s -> UtxoSearch m (ConcreteOutput Credential OutputDatum Value ScriptHash) Source #

Searches for all outputs containing a given script as reference script