use alloy::primitives::B256;
use alloy::rpc::types::Log;
use thiserror::Error;
use crate::storage::codec::decoder::DecodedEventWithHeader;
pub mod backfill;
pub mod config;
pub(crate) mod cursor;
pub mod error_tracking;
pub mod events;
pub mod heads;
pub mod progress;
pub mod provider;
pub mod stream;
#[derive(Debug, Clone, Error)]
pub enum RpcError {
#[error("Connection Error: {0}")]
ConnectionError(String),
#[error("Subscription Error: {0}")]
SubscriptionError(String),
#[error("Log Fetch Error: {0}")]
LogFetchError(String),
#[error("Transport Error: {0}")]
TransportError(String),
#[error("All Providers Suspended: {0}")]
AllProvidersSuspended(String),
#[error(
"Cursor past tip: refusing to advance to block {to_block}; provider reports tip {reported_tip}"
)]
CursorPastTip { to_block: u64, reported_tip: u64 },
#[error(
"provider stalled: tip {reported_tip} did not reach block {to_block} after {stalled_cycles} cycles"
)]
ProviderStalled {
to_block: u64,
reported_tip: u64,
stalled_cycles: u32,
},
#[error(
"all {providers_tried} provider(s) idle: no head within {idle_secs}s after a full rotation"
)]
AllProvidersIdle {
providers_tried: usize,
idle_secs: u64,
},
#[error("reorg: common ancestor at block {common_ancestor}")]
Reorg { common_ancestor: u64 },
#[error("reorg beyond ring: a recorded canonical hash disagrees with the chain we walked")]
ReorgBeyondRing,
#[error("gap: the live sequence did not extend cleanly")]
Gap,
#[error("Other Error: {0}")]
Other(String),
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct LogRange {
pub from_block: u64,
pub to_block: u64,
pub logs: Vec<Log>,
pub tip_hash: Option<B256>,
}
#[derive(Debug, Clone)]
pub struct DecodedEventRange {
pub from_block: u64,
pub to_block: u64,
pub events: Vec<DecodedEventWithHeader>,
pub tip_hash: Option<B256>,
}