| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
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
- data MockChainBuiltin a
- type InterpMockChain = MockChainT List
- type MockChainTweak = UntypedTweak InterpMockChain
- type StagedMockChain = StagedLtl MockChainTweak MockChainBuiltin
- interpretAndRunWith :: (forall m. Monad m => MockChainT m a -> m res) -> StagedMockChain a -> [res]
- interpretAndRun :: StagedMockChain a -> [MockChainReturn a]
- type MonadModalBlockChain m = (MonadBlockChain m, MonadLtl MockChainTweak m)
- withTweak :: MonadModalBlockChain m => m a -> Tweak InterpMockChain b -> m a
- somewhere :: MonadModalBlockChain m => Tweak InterpMockChain b -> m a -> m a
- somewhere' :: MonadLtl mod m => Ltl mod -> m a -> m a
- everywhere :: MonadModalBlockChain m => Tweak InterpMockChain b -> m a -> m a
- everywhere' :: MonadLtl mod m => Ltl mod -> m a -> m a
- there :: MonadModalBlockChain m => Integer -> Tweak InterpMockChain b -> m a -> m a
- there' :: MonadLtl mod m => Integer -> Ltl mod -> m a -> m a
- nowhere :: MonadModalBlockChain m => Tweak InterpMockChain b -> m a -> m a
- nowhere' :: MonadLtl mod m => Ltl mod -> m a -> m a
- whenAble :: MonadModalBlockChain m => Tweak InterpMockChain b -> m a -> m a
- whenAble' :: MonadLtl mod m => Ltl mod -> m a -> m a
StagedMockChain: An AST of mockchain computations
data MockChainBuiltin a Source #
Abstract representation of all the builtin functions of a MonadBlockChain
Instances
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 #
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.