chaincodec_stream/listener.rs
1//! `BlockListener` trait — abstraction over RPC/WS block polling.
2//!
3//! Each chain implementation provides a `BlockListener` that produces
4//! `RawEvent` items. The stream engine manages one listener per chain.
5
6use async_trait::async_trait;
7use chaincodec_core::{error::StreamError, event::RawEvent};
8use futures::Stream;
9use std::pin::Pin;
10
11/// A stream of raw events from a single chain.
12pub type RawEventStream = Pin<Box<dyn Stream<Item = Result<RawEvent, StreamError>> + Send>>;
13
14/// Abstracts over different chain RPC backends.
15#[async_trait]
16pub trait BlockListener: Send + Sync {
17 /// Chain slug this listener covers.
18 fn chain_slug(&self) -> &str;
19
20 /// Connect and start streaming raw events.
21 /// Returns a pinned async stream of `RawEvent` items.
22 async fn subscribe(&self) -> Result<RawEventStream, StreamError>;
23
24 /// Returns `true` if this listener is currently connected.
25 fn is_connected(&self) -> bool;
26}