feat: add ChainEventSubscriptions trait (#1338)

This commit is contained in:
Matthias Seitz
2023-02-14 15:49:56 +01:00
committed by GitHub
parent 091fbf6f8f
commit 8a0156fe4e
2 changed files with 34 additions and 11 deletions

View File

@ -0,0 +1,21 @@
use reth_primitives::{Header, H256};
use std::sync::Arc;
use tokio::sync::mpsc::UnboundedReceiver;
/// Type alias for a receiver that receives [NewBlockNotification]
pub type NewBlockNotifications = UnboundedReceiver<NewBlockNotification>;
/// A type that allows to register chain related event subscriptions.
pub trait ChainEventSubscriptions {
/// Get notified when a new block was imported.
fn subscribe_new_blocks(&self) -> NewBlockNotifications;
}
/// A notification that's emitted when a new block was imported.
#[derive(Clone, Debug)]
pub struct NewBlockNotification {
/// Hash of the block that was imported
pub hash: H256,
/// The block header of the new block
pub header: Arc<Header>,
}

View File

@ -7,29 +7,31 @@
//! Reth interface bindings
/// Block Execution traits.
pub mod executor;
/// Consensus traits.
pub mod consensus;
/// Provider error
pub mod provider;
/// Database error
pub mod db;
/// Block Execution traits.
pub mod executor;
/// Possible errors when interacting with the chain.
mod error;
pub use error::{Error, Result};
/// Traits for subscribing to events.
pub mod events;
/// P2P traits.
pub mod p2p;
/// Provider error
pub mod provider;
/// Syncing related traits.
pub mod sync;
/// Possible errors when interacting with the chain.
mod error;
pub use error::{Error, Result};
#[cfg(any(test, feature = "test-utils"))]
/// Common test helpers for mocking out Consensus, Downloaders and Header Clients.
pub mod test_utils;