cooked-validators
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cooked.Tweak.Guard

Description

This module exposes tweaks revolving around parts of a TxSkel satisfying given conditions. The only parameter these tweaks take is an optic, and the guards ensure that at least one focus is targeted by it. This might look insufficient, but thanks to filtered which turns a predicate into an optic, this is actually sufficiently expressive. For example, if you have an optic o targeting an element of type a, and a predicate p and would like to ensure the targeted elements satisfy p, use o % filtered p.

Synopsis

Standard guarding tweaks

assertTweak :: (Member Tweak effs, Is k A_Fold) => Optic' k is TxSkel a -> Sem effs Bool Source #

Asserts whether a given optic targets at least one focus

guardTweak :: (Members '[Tweak, NonDet] effs, Is k A_Fold) => Optic' k is TxSkel a -> Sem effs () Source #

Ensures a given optic targets at least one focus, failing otherwise

condTweak :: (Members '[Tweak, NonDet] effs, Is k A_Fold) => Optic' k is TxSkel a -> Sem effs b -> Sem effs b Source #

Only executes the given computation provided the given optic targets at least one focus, failing otherwise.

Custom guarding tweaks

labelled :: (LabelConstrs lbl, Members '[Tweak, NonDet] effs) => lbl -> Sem effs a -> Sem effs a Source #

Apply a tweak to a given transaction if it has a specific label. Fails if it does not.

someEndpoint = do
  ...
  validateTxSkel' txSkelTemplate
     { txSkelLabels =
        [ TxSkelLabel "InitialMinting"
        , TxSkelLabel "AuctionWorkflow"
        , TxSkelLabel SomeLabelType]
     }

someTest = someEndpoint & everywhere (labelled SomeLabelType someTweak)
anotherTest = someEndpoint & somewhere (labelled SomeLabelType someTweak)

labelled' :: Members '[Tweak, NonDet] effs => Text -> Sem effs a -> Sem effs a Source #

labelled specialised to Text labels

someEndpoint = do
  ...
  validateTxSkel' txSkelTemplate
     { txSkelLabels =
        [ TxSkelLabel "InitialMinting"
        , TxSkelLabel "AuctionWorkflow"
        , TxSkelLabel "Spending"
        , TxSkelLabel SomeLabelType]
     }

someTest = someEndpoint & somewhere (labelled' "Spending" someTweak)