pub struct ChainSynchronizationClient<H: ChainSynchronizationMessageHandlers> { /* private fields */ }Expand description
A chain synchronization client for following the Cardano blockchain.
This client implements the Ouroboros chain-sync mini-protocol, allowing you to follow the blockchain from a specific point and receive notifications about new blocks and rollbacks.
§Example
use ogmios_client::chain_synchronization::{
ChainSynchronizationClient,
ChainSynchronizationMessageHandlers,
};
use ogmios_client::connection::{ConnectionConfig, create_interaction_context, InteractionContextOptions, InteractionType};
use ogmios_client::schema::{Block, Point, Tip};
use ogmios_client::error::Result;
struct MyHandler;
impl ChainSynchronizationMessageHandlers for MyHandler {
fn on_roll_forward(&mut self, block: Block, tip: Tip) -> Result<()> {
println!("New block at slot {}", block.slot());
Ok(())
}
fn on_roll_backward(&mut self, point: Point, tip: Tip) -> Result<()> {
println!("Rollback to {:?}", point);
Ok(())
}
}
let context = create_interaction_context(InteractionContextOptions {
connection: ConnectionConfig::default(),
interaction_type: InteractionType::LongRunning,
..Default::default()
}).await?;
let client = ChainSynchronizationClient::new(context, MyHandler, Default::default()).await?;
// Start syncing from origin
let intersection = client.resume(Some(vec![Point::origin()]), None).await?;
println!("Started at {:?}", intersection.point);Implementations§
Source§impl<H: ChainSynchronizationMessageHandlers + 'static> ChainSynchronizationClient<H>
impl<H: ChainSynchronizationMessageHandlers + 'static> ChainSynchronizationClient<H>
Sourcepub async fn new(
context: InteractionContext,
handlers: H,
options: ChainSynchronizationClientOptions,
) -> Result<Self>
pub async fn new( context: InteractionContext, handlers: H, options: ChainSynchronizationClientOptions, ) -> Result<Self>
Create a new chain synchronization client.
§Arguments
context- The interaction context.handlers- Message handlers for block events.options- Client options.
Sourcepub fn context(&self) -> &InteractionContext
pub fn context(&self) -> &InteractionContext
Get a reference to the interaction context.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Check if the client is currently running.
Sourcepub async fn resume(
&self,
points: Option<Vec<Point>>,
_in_flight: Option<u32>,
) -> Result<Intersection>
pub async fn resume( &self, points: Option<Vec<Point>>, _in_flight: Option<u32>, ) -> Result<Intersection>
Resume chain synchronization from given points.
This function finds an intersection with the provided points and starts synchronizing from that point.
§Arguments
points- Optional list of points to try to intersect with. If not provided, starts from the origin.in_flight- Optional number of blocks to request in parallel.
§Returns
The intersection point that was found.
Auto Trait Implementations§
impl<H> !RefUnwindSafe for ChainSynchronizationClient<H>
impl<H> !UnwindSafe for ChainSynchronizationClient<H>
impl<H> Freeze for ChainSynchronizationClient<H>
impl<H> Send for ChainSynchronizationClient<H>
impl<H> Sync for ChainSynchronizationClient<H>
impl<H> Unpin for ChainSynchronizationClient<H>
impl<H> UnsafeUnpin for ChainSynchronizationClient<H>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more