use std::sync::Arc;
use reth_provider::{CanonStateNotification, Chain};
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum ExExNotification {
ChainCommitted {
new: Arc<Chain>,
},
ChainReorged {
old: Arc<Chain>,
new: Arc<Chain>,
},
ChainReverted {
old: Arc<Chain>,
},
}
impl ExExNotification {
pub fn committed_chain(&self) -> Option<Arc<Chain>> {
match self {
Self::ChainCommitted { new } | Self::ChainReorged { old: _, new } => Some(new.clone()),
Self::ChainReverted { .. } => None,
}
}
pub fn reverted_chain(&self) -> Option<Arc<Chain>> {
match self {
Self::ChainReorged { old, new: _ } | Self::ChainReverted { old } => Some(old.clone()),
Self::ChainCommitted { .. } => None,
}
}
}
impl From<CanonStateNotification> for ExExNotification {
fn from(notification: CanonStateNotification) -> Self {
match notification {
CanonStateNotification::Commit { new } => Self::ChainCommitted { new },
CanonStateNotification::Reorg { old, new } => Self::ChainReorged { old, new },
}
}
}