use std::sync::Arc; use reth_provider::{CanonStateNotification, Chain}; /// Notifications sent to an `ExEx`. #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum ExExNotification { /// Chain got committed without a reorg, and only the new chain is returned. ChainCommitted { /// The new chain after commit. new: Arc, }, /// Chain got reorged, and both the old and the new chains are returned. ChainReorged { /// The old chain before reorg. old: Arc, /// The new chain after reorg. new: Arc, }, /// Chain got reverted, and only the old chain is returned. ChainReverted { /// The old chain before reversion. old: Arc, }, } impl ExExNotification { /// Returns the committed chain from the [`Self::ChainCommitted`] and [`Self::ChainReorged`] /// variants, if any. pub fn committed_chain(&self) -> Option> { match self { Self::ChainCommitted { new } | Self::ChainReorged { old: _, new } => Some(new.clone()), Self::ChainReverted { .. } => None, } } /// Returns the reverted chain from the [`Self::ChainReorged`] and [`Self::ChainReverted`] /// variants, if any. pub fn reverted_chain(&self) -> Option> { match self { Self::ChainReorged { old, new: _ } | Self::ChainReverted { old } => Some(old.clone()), Self::ChainCommitted { .. } => None, } } } impl From for ExExNotification { fn from(notification: CanonStateNotification) -> Self { match notification { CanonStateNotification::Commit { new } => Self::ChainCommitted { new }, CanonStateNotification::Reorg { old, new } => Self::ChainReorged { old, new }, } } }