Skip to main content

ChainSynchronizationClient

Struct ChainSynchronizationClient 

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

Source

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

pub fn context(&self) -> &InteractionContext

Get a reference to the interaction context.

Source

pub fn is_running(&self) -> bool

Check if the client is currently running.

Source

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.

Source

pub async fn shutdown(&self) -> Result<()>

Shutdown the chain synchronization client.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more