plutus-contract-0.1.0.0
Safe HaskellNone
LanguageHaskell2010

Plutus.Contract.Checkpoint

Contents

Synopsis

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.

data CheckpointError Source #

Constructors

JSONDecodeError Text 

Instances

Instances details
Eq CheckpointError Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Ord CheckpointError Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Show CheckpointError Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Generic CheckpointError Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Associated Types

type Rep CheckpointError :: Type -> Type Source #

ToJSON CheckpointError Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

FromJSON CheckpointError Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Pretty CheckpointError Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

AsCheckpointError CheckpointError Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

type Rep CheckpointError Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

type Rep CheckpointError = D1 ('MetaData "CheckpointError" "Plutus.Contract.Checkpoint" "plutus-contract-0.1.0.0-2DbvKQdtEvHK4UkDq1ndDW" 'False) (C1 ('MetaCons "JSONDecodeError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text)))

newtype CheckpointStore Source #

Instances

Instances details
Eq CheckpointStore Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Show CheckpointStore Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Generic CheckpointStore Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Associated Types

type Rep CheckpointStore :: Type -> Type Source #

Semigroup CheckpointStore Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Monoid CheckpointStore Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

ToJSON CheckpointStore Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

FromJSON CheckpointStore Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Pretty CheckpointStore Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

type Rep CheckpointStore Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

type Rep CheckpointStore = D1 ('MetaData "CheckpointStore" "Plutus.Contract.Checkpoint" "plutus-contract-0.1.0.0-2DbvKQdtEvHK4UkDq1ndDW" 'True) (C1 ('MetaCons "CheckpointStore" 'PrefixI 'True) (S1 ('MetaSel ('Just "unCheckpointStore") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Map CheckpointKey (CheckpointStoreItem Value)))))

data CheckpointStoreItem a Source #

Constructors

CheckpointStoreItem 

Fields

Instances

Instances details
Functor CheckpointStoreItem Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Foldable CheckpointStoreItem Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Methods

fold :: Monoid m => CheckpointStoreItem m -> m Source #

foldMap :: Monoid m => (a -> m) -> CheckpointStoreItem a -> m Source #

foldMap' :: Monoid m => (a -> m) -> CheckpointStoreItem a -> m Source #

foldr :: (a -> b -> b) -> b -> CheckpointStoreItem a -> b Source #

foldr' :: (a -> b -> b) -> b -> CheckpointStoreItem a -> b Source #

foldl :: (b -> a -> b) -> b -> CheckpointStoreItem a -> b Source #

foldl' :: (b -> a -> b) -> b -> CheckpointStoreItem a -> b Source #

foldr1 :: (a -> a -> a) -> CheckpointStoreItem a -> a Source #

foldl1 :: (a -> a -> a) -> CheckpointStoreItem a -> a Source #

toList :: CheckpointStoreItem a -> [a] Source #

null :: CheckpointStoreItem a -> Bool Source #

length :: CheckpointStoreItem a -> Int Source #

elem :: Eq a => a -> CheckpointStoreItem a -> Bool Source #

maximum :: Ord a => CheckpointStoreItem a -> a Source #

minimum :: Ord a => CheckpointStoreItem a -> a Source #

sum :: Num a => CheckpointStoreItem a -> a Source #

product :: Num a => CheckpointStoreItem a -> a Source #

Traversable CheckpointStoreItem Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Eq a => Eq (CheckpointStoreItem a) Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Ord a => Ord (CheckpointStoreItem a) Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Show a => Show (CheckpointStoreItem a) Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Generic (CheckpointStoreItem a) Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Associated Types

type Rep (CheckpointStoreItem a) :: Type -> Type Source #

ToJSON a => ToJSON (CheckpointStoreItem a) Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

FromJSON a => FromJSON (CheckpointStoreItem a) Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

type Rep (CheckpointStoreItem a) Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

type Rep (CheckpointStoreItem a) = D1 ('MetaData "CheckpointStoreItem" "Plutus.Contract.Checkpoint" "plutus-contract-0.1.0.0-2DbvKQdtEvHK4UkDq1ndDW" 'False) (C1 ('MetaCons "CheckpointStoreItem" 'PrefixI 'True) (S1 ('MetaSel ('Just "csValue") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Just "csNewKey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 CheckpointKey)))

data CheckpointKey Source #

Instances

Instances details
Enum CheckpointKey Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Eq CheckpointKey Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Num CheckpointKey Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Ord CheckpointKey Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Show CheckpointKey Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Generic CheckpointKey Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Associated Types

type Rep CheckpointKey :: Type -> Type Source #

ToJSON CheckpointKey Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

ToJSONKey CheckpointKey Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

FromJSON CheckpointKey Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

FromJSONKey CheckpointKey Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Pretty CheckpointKey Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

type Rep CheckpointKey Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

type Rep CheckpointKey = D1 ('MetaData "CheckpointKey" "Plutus.Contract.Checkpoint" "plutus-contract-0.1.0.0-2DbvKQdtEvHK4UkDq1ndDW" 'True) (C1 ('MetaCons "CheckpointKey" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Integer)))

data CheckpointLogMsg Source #

Instances

Instances details
Eq CheckpointLogMsg Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Ord CheckpointLogMsg Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Show CheckpointLogMsg Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Generic CheckpointLogMsg Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Associated Types

type Rep CheckpointLogMsg :: Type -> Type Source #

ToJSON CheckpointLogMsg Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

FromJSON CheckpointLogMsg Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Pretty CheckpointLogMsg Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

type Rep CheckpointLogMsg Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

type Rep CheckpointLogMsg = D1 ('MetaData "CheckpointLogMsg" "Plutus.Contract.Checkpoint" "plutus-contract-0.1.0.0-2DbvKQdtEvHK4UkDq1ndDW" 'False) (((C1 ('MetaCons "LogFoundValueRestoringKey" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 CheckpointKey)) :+: C1 ('MetaCons "LogDecodingErrorAtKey" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 CheckpointKey))) :+: (C1 ('MetaCons "LogNoValueForKey" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 CheckpointKey)) :+: C1 ('MetaCons "LogDoCheckpoint" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "LogAllocateKey" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "LogRetrieve" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 CheckpointKey))) :+: (C1 ('MetaCons "LogStore" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 CheckpointKey) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 CheckpointKey)) :+: C1 ('MetaCons "LogKeyUpdate" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 CheckpointKey) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 CheckpointKey)))))

jsonCheckpoint Source #

Arguments

:: forall err a effs. (Member Checkpoint effs, Member (Error err) effs, ToJSON a, FromJSON a, AsCheckpointError err) 
=> Eff effs a

The action that is checkpointed

-> Eff effs a 

Create a checkpoint for an action. handleCheckpoint (jsonCheckpoint action) will

  • Obtain a CheckpointKey that 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 action if there is a value at the key.

jsonCheckpointLoop Source #

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 Left. Only the accumulated result of the action will be stored.

-> 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