cooked-validators
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cooked.MockChain.UtxoSearch

Description

This module provides a convenient framework to look through UTxOs and: - filter them in a convenient manner - extract pieces of information from them

Synopsis

UTxO searches

type UtxoSearch effs elems = Sem effs (UtxoSearchResult elems) Source #

A UtxoSearch is a computation that returns a list of UTxOs alongside their TxSkelOut counterpart and a list of other elements retrieved from the output. The idea is to begin with a simple search and refine the search with filters while appending new elements to the list.

beginSearch :: Sem effs Utxos -> UtxoSearch effs '[] Source #

Wraps up a computation returning a Utxos into a UtxoSearch

beginSearchP :: Utxos -> UtxoSearch effs '[] Source #

Same as beginSearch with a pure input

Processing search result

type UtxoSearchResult elems = [(TxOutRef, HList (TxSkelOut ': elems))] Source #

Raw result of a UtxoSearch. We store the TxOutRef of the output, alongside an heterogeneous list starting with the output in question, followed by any element that was extracted during the search.

getOutputs :: Sem effs (UtxoSearchResult elems) -> Sem effs [TxSkelOut] Source #

Retrieves the TxSkelOuts from a UtxoSearchResult

getOutputsAndExtracts :: Sem effs (UtxoSearchResult elems) -> Sem effs [(TxSkelOut, HList elems)] Source #

Retrieves the TxSkelOuts from a UtxoSearchResult alongside the extracted elements

getExtracts :: Sem effs (UtxoSearchResult elems) -> Sem effs [HList elems] Source #

Retrieves the extracted elements from a UtxoSearchResult

getTxOutRefs :: Sem effs (UtxoSearchResult elems) -> Sem effs [TxOutRef] Source #

Retrieves the TxOutRefs from a UtxoSearchResult

getTxOutRefsAndOutputs :: Sem effs (UtxoSearchResult elems) -> Sem effs Utxos Source #

Retrieves both the TxOutRefs and TxSkelOuts from a UtxoSearchResult

Basic UTxO searches

utxosAtSearch :: (Member MockChainRead effs, ToCredential pkh) => pkh -> (UtxoSearch effs '[] -> UtxoSearch effs els) -> UtxoSearch effs els Source #

Searches for utxos at a given address with a given filter

allUtxosSearch :: Member MockChainRead effs => (UtxoSearch effs '[] -> UtxoSearch effs els) -> UtxoSearch effs els Source #

Searches for all the known utxos with a given filter

txSkelOutByRefSearch :: Member MockChainRead effs => [TxOutRef] -> (UtxoSearch effs '[] -> UtxoSearch effs els) -> UtxoSearch effs els Source #

Searches for utxos belonging to a given list with a given filter

txSkelOutByRefSearch' :: Member MockChainRead effs => [TxOutRef] -> UtxoSearch effs '[] Source #

Searches for utxos belonging to a given list with no filter

Extracting new information from UTxOs

extract :: (TxSkelOut -> Sem effs (Maybe b)) -> UtxoSearch effs els -> UtxoSearch effs (b ': els) Source #

Extracts a new element from the currently selected outputs, filtering in the process out utxos for which this element is not available

extractPure :: (TxSkelOut -> Maybe b) -> UtxoSearch effs els -> UtxoSearch effs (b ': els) Source #

Same as extract, but with a pure extraction function

extractAFold :: Is k An_AffineFold => Optic' k is TxSkelOut b -> UtxoSearch effs els -> UtxoSearch effs (b ': els) Source #

Same as extractPure, using an affine fold to extract the element

extractTotal :: (TxSkelOut -> Sem effs b) -> UtxoSearch effs els -> UtxoSearch effs (b ': els) Source #

Same as extract, but with a total extraction function

extractPureTotal :: (TxSkelOut -> b) -> UtxoSearch effs els -> UtxoSearch effs (b ': els) Source #

Same as extract, but with a pure and total extraction function

extractGetter :: Is k A_Getter => Optic' k is TxSkelOut b -> UtxoSearch effs els -> UtxoSearch effs (b ': els) Source #

Same as extractPureTotal, using a getter to extract the element

Filtering some UTxOs out

ensure :: (TxSkelOut -> Sem effs Bool) -> UtxoSearch effs els -> UtxoSearch effs els Source #

Ensures the outputs resulting from the search satisfy the given predicate

ensurePure :: (TxSkelOut -> Bool) -> UtxoSearch effs els -> UtxoSearch effs els Source #

Same as ensure, but with a pure predicate

ensureAFoldIs :: Is k An_AffineFold => Optic' k is TxSkelOut b -> UtxoSearch effs els -> UtxoSearch effs els Source #

Ensures the outputs resulting from the search contain the focus of the given affine fold

ensureAFoldIsn't :: Is k An_AffineFold => Optic' k is TxSkelOut b -> UtxoSearch effs els -> UtxoSearch effs els Source #

Ensures the outputs resulting from the search do not contain the focus of the given affine fold

Cooked filters

ensureOnlyValueOutputs :: UtxoSearch effs els -> UtxoSearch effs els Source #

Ensures the outputs resulting from the search do not have a reference script, nor a staking credential, nor a datum

ensureVanillaOutputs :: UtxoSearch effs els -> UtxoSearch effs els Source #

Same as ensureOnlyValueOutputs, but also ensures the searched outputs do not contain non-ADA assets.

ensureProperReferenceScript :: ToScriptHash s => s -> UtxoSearch effs els -> UtxoSearch effs els Source #

Ensures the outputs resulting from the search have the given script as a reference script