| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Plutus.Contract.Checkpoint
Contents
Synopsis
- data Checkpoint r where
- DoCheckpoint :: Checkpoint ()
- AllocateKey :: Checkpoint CheckpointKey
- Store :: ToJSON a => CheckpointKey -> CheckpointKey -> a -> Checkpoint ()
- Retrieve :: FromJSON a => CheckpointKey -> Checkpoint (Either CheckpointError (Maybe a))
- data CheckpointError = JSONDecodeError Text
- class AsCheckpointError r where
- _CheckpointError :: Prism' r CheckpointError
- _JSONDecodeError :: Prism' r Text
- newtype CheckpointStore = CheckpointStore {
- unCheckpointStore :: Map CheckpointKey (CheckpointStoreItem Value)
- data CheckpointStoreItem a = CheckpointStoreItem {
- csValue :: a
- csNewKey :: CheckpointKey
- data CheckpointKey
- data CheckpointLogMsg
- jsonCheckpoint :: forall err a effs. (Member Checkpoint effs, Member (Error err) effs, ToJSON a, FromJSON a, AsCheckpointError err) => Eff effs a -> Eff effs a
- jsonCheckpointLoop :: forall err a b effs. (Member Checkpoint effs, Member (Error err) effs, ToJSON a, FromJSON a, ToJSON b, FromJSON b, AsCheckpointError err) => (a -> Eff effs (Either b a)) -> a -> Eff effs b
- handleCheckpoint :: forall effs. (Member (State CheckpointStore) effs, Member (State CheckpointKey) effs, Member (LogMsg CheckpointLogMsg) effs) => Eff (Checkpoint ': effs) ~> Eff effs
- completedIntervals :: CheckpointStore -> IntervalSet (Interval CheckpointKey)
- maxKey :: CheckpointStore -> Maybe CheckpointKey
Checkpoints
This module contains a checkpoints mechanism that can be used to store
intermediate results of Eff programs as JSON values
inside a CheckpointStore. It works similar to the short-circuiting behavior
of Error: Before we execute an action
Eff effs a whose result should be checkpointed, we check if the there is
already a value of a for this checkpoint it in the store. If there is, we
return it instead of running the action. If there isn't, we run the action
a and then store the result.
- To create a checkpoint use
jsonCheckpoint. - To handle the checkpoint effect use
handleCheckpoint.
data Checkpoint r where Source #
Constructors
| DoCheckpoint :: Checkpoint () | |
| AllocateKey :: Checkpoint CheckpointKey | |
| Store :: ToJSON a => CheckpointKey -> CheckpointKey -> a -> Checkpoint () | |
| Retrieve :: FromJSON a => CheckpointKey -> Checkpoint (Either CheckpointError (Maybe a)) |
data CheckpointError Source #
Constructors
| JSONDecodeError Text |
Instances
class AsCheckpointError r where Source #
Minimal complete definition
Methods
_CheckpointError :: Prism' r CheckpointError Source #
_JSONDecodeError :: Prism' r Text Source #
Instances
| AsCheckpointError CheckpointError Source # | |
Defined in Plutus.Contract.Checkpoint Methods _CheckpointError :: Prism' CheckpointError CheckpointError Source # _JSONDecodeError :: Prism' CheckpointError Text Source # | |
| AsCheckpointError ContractError Source # | |
Defined in Plutus.Contract.Error Methods _CheckpointError :: Prism' ContractError CheckpointError Source # _JSONDecodeError :: Prism' ContractError Text Source # | |
newtype CheckpointStore Source #
Constructors
| CheckpointStore | |
Fields
| |
Instances
data CheckpointStoreItem a Source #
Constructors
| CheckpointStoreItem | |
Fields
| |
Instances
data CheckpointKey Source #
Instances
data CheckpointLogMsg Source #
Constructors
Instances
Arguments
| :: forall err a effs. (Member Checkpoint effs, Member (Error err) effs, ToJSON a, FromJSON a, AsCheckpointError err) | |
| => Eff effs a | The |
| -> Eff effs a |
Create a checkpoint for an action.
handleCheckpoint (jsonCheckpoint action) will
- Obtain a
CheckpointKeythat identifies the position of the current checkpoint in the program - Run
action, convert its result to JSON and store it in the checkpoint store if there is no value at the key - Retrieve the result as a JSON value from the store, parse it, and return
it *instead* of running
actionif there is a value at the key.
Arguments
| :: forall err a b effs. (Member Checkpoint effs, Member (Error err) effs, ToJSON a, FromJSON a, ToJSON b, FromJSON b, AsCheckpointError err) | |
| => (a -> Eff effs (Either b a)) | The action that is repeated until it returns a |
| -> a | Initial value |
| -> Eff effs b |
handleCheckpoint :: forall effs. (Member (State CheckpointStore) effs, Member (State CheckpointKey) effs, Member (LogMsg CheckpointLogMsg) effs) => Eff (Checkpoint ': effs) ~> Eff effs Source #
Handle the Checkpoint effect in terms of CheckpointStore and
CheckpointKey states.
completedIntervals :: CheckpointStore -> IntervalSet (Interval CheckpointKey) Source #
Intervals of checkpoint keys that are completely covered by the checkpoint store.
maxKey :: CheckpointStore -> Maybe CheckpointKey Source #
The maximum key that is present in the store