cooked-validators
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cooked.MockChain.Staged

Description

This module provides a staged implementation of our MonadBlockChain. The motivation is to be able to modify transactions with Tweaks deployed in time with Ltl while the computation gets interpreted, and before the transactions are sent for validation.

Synopsis

StagedMockChain: An AST of mockchain computations

data MockChainBuiltin a Source #

Abstract representation of all the builtin functions of a MonadBlockChain

Instances

Instances details
MonadFail StagedMockChain Source # 
Instance details

Defined in Cooked.MockChain.Staged

Methods

fail :: String -> StagedMockChain a #

Alternative StagedMockChain Source # 
Instance details

Defined in Cooked.MockChain.Staged

MonadPlus StagedMockChain Source # 
Instance details

Defined in Cooked.MockChain.Staged

MonadBlockChain StagedMockChain Source # 
Instance details

Defined in Cooked.MockChain.Staged

MonadBlockChainBalancing StagedMockChain Source # 
Instance details

Defined in Cooked.MockChain.Staged

MonadBlockChainWithoutValidation StagedMockChain Source # 
Instance details

Defined in Cooked.MockChain.Staged

MonadError MockChainError StagedMockChain Source # 
Instance details

Defined in Cooked.MockChain.Staged

ModInterpBuiltin MockChainTweak MockChainBuiltin InterpMockChain Source # 
Instance details

Defined in Cooked.MockChain.Staged

type InterpMockChain = MockChainT List Source #

The domain in which StagedMockChain gets interpreted

type MockChainTweak = UntypedTweak InterpMockChain Source #

Tweaks operating within the InterpMockChain domain

type StagedMockChain = StagedLtl MockChainTweak MockChainBuiltin Source #

A StagedMockChain is an AST of mockchain builtins wrapped into LtlOp to be subject to Ltl modifications.

Interpreting and running a StagedMockChain

interpretAndRunWith :: (forall m. Monad m => MockChainT m a -> m res) -> StagedMockChain a -> [res] Source #

Interprets the staged mockchain then runs the resulting computation with a custom function. This can be used, for example, to supply a custom InitialDistribution by providing runMockChainTFromInitDist.

interpretAndRun :: StagedMockChain a -> [MockChainReturn a] Source #

Same as interpretAndRunWith but using runMockChainT as the default way to run the computation.

Temporal modalities

type MonadModalBlockChain m = (MonadBlockChain m, MonadLtl MockChainTweak m) Source #

A modal mockchain is a mockchain that allows us to use LTL modifications with Tweaks

withTweak :: MonadModalBlockChain m => m a -> Tweak InterpMockChain b -> m a Source #

Apply a Tweak to the next transaction in the given trace. The order of arguments enables an idiom like

do ...
   endpoint arguments `withTweak` someModification
   ...

where endpoint builds and validates a single transaction depending on the given arguments. Then withTweak says "I want to modify the transaction returned by this endpoint in the following way".

somewhere :: MonadModalBlockChain m => Tweak InterpMockChain b -> m a -> m a Source #

Applies a Tweak to every step in a trace where it is applicable, branching at any such locations. The tweak must apply at least once.

somewhere' :: MonadLtl mod m => Ltl mod -> m a -> m a Source #

Applies an Ltl modification following the same rules as somewhere.

everywhere :: MonadModalBlockChain m => Tweak InterpMockChain b -> m a -> m a Source #

Applies a Tweak to every transaction in a given trace. Fails if the tweak fails anywhere in the trace.

everywhere' :: MonadLtl mod m => Ltl mod -> m a -> m a Source #

Applies a Ltl modification following the sames rules as everywhere.

there :: MonadModalBlockChain m => Integer -> Tweak InterpMockChain b -> m a -> m a Source #

Apply a Tweak to the (0-indexed) nth transaction in a given trace. Successful when this transaction exists and can be modified.

See also labelled to select transactions based on labels instead of their index.

there' :: MonadLtl mod m => Integer -> Ltl mod -> m a -> m a Source #

Apply an Ltl modification following the same rules as there.

nowhere :: MonadModalBlockChain m => Tweak InterpMockChain b -> m a -> m a Source #

Ensures a given Tweak can never successfully be applied in a computation, and leaves the computation unchanged.

nowhere' :: MonadLtl mod m => Ltl mod -> m a -> m a Source #

Ensures a given Ltl modifications follow the same rules as nowhere.

whenAble :: MonadModalBlockChain m => Tweak InterpMockChain b -> m a -> m a Source #

Apply a given Tweak at every location in a computation where it does not fail, which might never occur.

whenAble' :: MonadLtl mod m => Ltl mod -> m a -> m a Source #

Apply an Ltl modification following the same rules as whenAble.