use crate::{ExExContextDyn, ExExEvent, ExExNotifications, ExExNotificationsStream};
use reth_exex_types::ExExHead;
use reth_node_api::{FullNodeComponents, NodeTypes};
use reth_node_core::node_config::NodeConfig;
use reth_primitives::Head;
use reth_tasks::TaskExecutor;
use std::fmt::Debug;
use tokio::sync::mpsc::UnboundedSender;
pub struct ExExContext<Node: FullNodeComponents> {
pub head: Head,
pub config: NodeConfig<<Node::Types as NodeTypes>::ChainSpec>,
pub reth_config: reth_config::Config,
pub events: UnboundedSender<ExExEvent>,
pub notifications: ExExNotifications<Node::Provider, Node::Executor>,
pub components: Node,
}
impl<Node> Debug for ExExContext<Node>
where
Node: FullNodeComponents,
Node::Provider: Debug,
Node::Executor: Debug,
{
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", &self.notifications)
.field("components", &"...")
.finish()
}
}
impl<Node> ExExContext<Node>
where
Node: FullNodeComponents,
Node::Provider: Debug,
Node::Executor: Debug,
{
pub fn into_dyn(self) -> ExExContextDyn {
ExExContextDyn::from(self)
}
}
impl<Node> ExExContext<Node>
where
Node: FullNodeComponents,
{
pub fn pool(&self) -> &Node::Pool {
self.components.pool()
}
pub fn evm_config(&self) -> &Node::Evm {
self.components.evm_config()
}
pub fn block_executor(&self) -> &Node::Executor {
self.components.block_executor()
}
pub fn provider(&self) -> &Node::Provider {
self.components.provider()
}
pub fn network(&self) -> &Node::Network {
self.components.network()
}
pub fn payload_builder(&self) -> &Node::PayloadBuilder {
self.components.payload_builder()
}
pub fn task_executor(&self) -> &TaskExecutor {
self.components.task_executor()
}
pub fn set_notifications_without_head(&mut self) {
self.notifications.set_without_head();
}
pub fn set_notifications_with_head(&mut self, head: ExExHead) {
self.notifications.set_with_head(head);
}
}
#[cfg(test)]
mod tests {
use reth_exex_types::ExExHead;
use reth_node_api::FullNodeComponents;
use crate::ExExContext;
#[test]
const fn issue_12054() {
#[allow(dead_code)]
struct ExEx<Node: FullNodeComponents> {
ctx: ExExContext<Node>,
}
impl<Node: FullNodeComponents> ExEx<Node> {
async fn _test_bounds(mut self) -> eyre::Result<()> {
self.ctx.pool();
self.ctx.block_executor();
self.ctx.provider();
self.ctx.network();
self.ctx.payload_builder();
self.ctx.task_executor();
self.ctx.set_notifications_without_head();
self.ctx.set_notifications_with_head(ExExHead { block: Default::default() });
Ok(())
}
}
}
}