hydra-node-0.19.0: The Hydra node
Safe HaskellSafe-Inferred
LanguageGHC2021

Hydra.Events.FileBased

Description

A file-based event source and sink using JSON encoding.

This serves as an example of how to create an EventSource and EventSink.

Synopsis

Documentation

eventPairFromPersistenceIncremental :: (IsChainState tx, MonadSTM m) => PersistenceIncremental (PersistedStateChange tx) m -> m (EventSource (StateEvent tx) m, EventSink (StateEvent tx) m) Source #

A basic file based event source and sink defined using an PersistenceIncremental handle.

The complexity in this implementation mostly stems from the fact that we want to be backward-compatible with the old, plain format of storing StateChanged items directly to disk using PersistenceIncremental.

If any 'Legacy StateChanged' items are discovered, a running index is used for the $sel:eventId:StateEvent, while the 'New StateEvent' values are just stored as is.

A new implementation for an EventSource with a compatible EventSink could be defined more generically with constraints:

(ToJSON e, FromJSON e, HasEventId) e => (EventSource e m, EventSink e m)

data PersistedStateChange tx Source #

Internal data type used by createJSONFileEventSourceAndSink to be compatible with plain usage of PersistenceIncrementa using plain StateChanged items to the new StateEvent persisted items.

Constructors

Legacy (StateChanged tx) 
New (StateEvent tx) 

Instances

Instances details
IsChainState tx => FromJSON (PersistedStateChange tx) Source # 
Instance details

Defined in Hydra.Events.FileBased

Methods

parseJSON :: Value -> Parser (PersistedStateChange tx)

parseJSONList :: Value -> Parser [PersistedStateChange tx]

omittedField :: Maybe (PersistedStateChange tx)

IsChainState tx => ToJSON (PersistedStateChange tx) Source # 
Instance details

Defined in Hydra.Events.FileBased

Generic (PersistedStateChange tx) Source # 
Instance details

Defined in Hydra.Events.FileBased

Associated Types

type Rep (PersistedStateChange tx) :: Type -> Type Source #

IsChainState tx => Show (PersistedStateChange tx) Source # 
Instance details

Defined in Hydra.Events.FileBased

IsChainState tx => Eq (PersistedStateChange tx) Source # 
Instance details

Defined in Hydra.Events.FileBased

type Rep (PersistedStateChange tx) Source # 
Instance details

Defined in Hydra.Events.FileBased

type Rep (PersistedStateChange tx) = D1 ('MetaData "PersistedStateChange" "Hydra.Events.FileBased" "hydra-node-0.19.0-6Z4E5vp1s1XJuLOmmEVMTw" 'False) (C1 ('MetaCons "Legacy" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (StateChanged tx))) :+: C1 ('MetaCons "New" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (StateEvent tx))))