View Source Xogmios.ChainSync behaviour (xogmios v0.8.0)
This module interfaces with the Chain Synchronization protocol.
Summary
Callbacks
Invoked when a new block is emitted. This callback is required.
Invoked upon connecting to the server. This callback is optional.
Invoked upon disconnecting from the server. This callback is optional.
Invoked when a message is sent to the process. This callback is optional.
Invoked when a rollback event is emitted. This callback is optional.
Functions
Sends a message to the ChainSync process.
This function is useful to send messages to the ChainSync process from outside
of the ChainSync module. The message should be handled by a matching handle_info/2
callback.
Starts a new Chain Sync process linked to the current process.
Callbacks
@callback handle_block(block :: map(), state) :: {:ok, :next_block, new_state} | {:ok, new_state} | {:close, new_state} when state: term(), new_state: term()
Invoked when a new block is emitted. This callback is required.
Receives block information as argument and the current state of the handler.
Returning {:ok, :next_block, new_state}
will request the next block once
it's made available.
Returning {:ok, new_state}
will not request anymore blocks.
Returning {:close, new_state}
will close the connection to the server.
Invoked upon connecting to the server. This callback is optional.
@callback handle_disconnect(reason, state) :: {:reconnect, interval_in_ms :: non_neg_integer(), new_state} | {:close, reason, new_state} | {:ok, new_state} when reason: String.t(), state: term(), new_state: term()
Invoked upon disconnecting from the server. This callback is optional.
Returning {:reconnect, interval_in_ms, new_state}
will attempt a reconnection
after interval_in_ms
.
Returning {:close, reason, new_state}
will allow the connection to close and
shut the process down cleanly.
Returning {:ok, new_state}
will allow the connection to close but keeps
process alive.
@callback handle_info(message :: term(), state) :: {:ok, :next_block, new_state} | {:ok, new_state} | {:close, new_state} when state: term(), new_state: term()
Invoked when a message is sent to the process. This callback is optional.
Return type is the same as handle_block/2
and handle_rollback/2
.
@callback handle_rollback(point :: map(), state) :: {:ok, :next_block, new_state} | {:ok, new_state} | {:close, new_state} when state: term(), new_state: term()
Invoked when a rollback event is emitted. This callback is optional.
Receives as argument a point and the state of the handler. The point is a
map with keys for id
(block id) and a slot
. This information can then
be used by the handler module to perform the necessary corrections.
For example, resetting all current known state past this point and then
rewriting it from future invokations of handle_block/2
Returning {:ok, :next_block, new_state}
will request the next block once
it's made available.
Returning {:ok, new_state}
will not request anymore blocks.
Returning {:close, new_state}
will close the connection to the server.
Functions
Sends a message to the ChainSync process.
This function is useful to send messages to the ChainSync process from outside
of the ChainSync module. The message should be handled by a matching handle_info/2
callback.
Starts a new Chain Sync process linked to the current process.
This function should not be called directly, but rather via Xogmios.start_chain_sync_link/2