use std::fmt::Debug;
use reth_chainspec::{EthChainSpec, Head};
use reth_node_api::{FullNodeComponents, HeaderTy, NodePrimitives, NodeTypes};
use reth_node_core::node_config::NodeConfig;
use reth_primitives::EthPrimitives;
use reth_provider::BlockReader;
use tokio::sync::mpsc;
use crate::{ExExContext, ExExEvent, ExExNotificationsStream};
pub struct ExExContextDyn<N: NodePrimitives = EthPrimitives> {
pub head: Head,
pub config: NodeConfig<Box<dyn EthChainSpec<Header = N::BlockHeader> + 'static>>,
pub reth_config: reth_config::Config,
pub events: mpsc::UnboundedSender<ExExEvent>,
pub notifications: Box<dyn ExExNotificationsStream<N>>,
}
impl<N: NodePrimitives> Debug for ExExContextDyn<N> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ExExContext")
.field("head", &self.head)
.field("config", &self.config)
.field("reth_config", &self.reth_config)
.field("events", &self.events)
.field("notifications", &"...")
.finish()
}
}
impl<Node> From<ExExContext<Node>> for ExExContextDyn<<Node::Types as NodeTypes>::Primitives>
where
Node: FullNodeComponents<Types: NodeTypes<Primitives: NodePrimitives>>,
Node::Provider: Debug + BlockReader,
Node::Executor: Debug,
{
fn from(ctx: ExExContext<Node>) -> Self {
let config = ctx.config.map_chainspec(|chainspec| {
Box::new(chainspec) as Box<dyn EthChainSpec<Header = HeaderTy<Node::Types>>>
});
let notifications = Box::new(ctx.notifications) as Box<_>;
Self {
head: ctx.head,
config,
reth_config: ctx.reth_config,
events: ctx.events,
notifications,
}
}
}