From bc456194e0768d1d15f2079449a35dd0b23fbeee Mon Sep 17 00:00:00 2001 From: Roman Roibu Date: Mon, 24 Jun 2024 22:59:27 +0200 Subject: [PATCH] feat: add AnyNode type (#9056) Co-authored-by: Matthias Seitz --- crates/node/builder/src/node.rs | 40 ++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/crates/node/builder/src/node.rs b/crates/node/builder/src/node.rs index 76c2117552ee2..fe8d99ed60906 100644 --- a/crates/node/builder/src/node.rs +++ b/crates/node/builder/src/node.rs @@ -11,7 +11,7 @@ use reth_payload_builder::PayloadBuilderHandle; use reth_provider::ChainSpecProvider; use reth_rpc_builder::{auth::AuthServerHandle, RpcServerHandle}; use reth_tasks::TaskExecutor; -use std::sync::Arc; +use std::{marker::PhantomData, sync::Arc}; // re-export the node api types use crate::components::NodeComponentsBuilder; @@ -28,6 +28,44 @@ pub trait Node: NodeTypes + Clone { fn components_builder(self) -> Self::ComponentsBuilder; } +/// A [`Node`] type builder +#[derive(Clone, Default, Debug)] +pub struct AnyNode(PhantomData, C); + +impl AnyNode { + /// Configures the types of the node. + pub fn types(self) -> AnyNode { + AnyNode::(PhantomData::, self.1) + } + + /// Sets the node components builder. + pub fn components_builder(self, value: T) -> AnyNode { + AnyNode::(PhantomData::, value) + } +} + +impl NodeTypes for AnyNode +where + N: FullNodeTypes, + C: NodeComponentsBuilder + Sync + Unpin + 'static, +{ + type Primitives = N::Primitives; + + type Engine = N::Engine; +} + +impl Node for AnyNode +where + N: FullNodeTypes + Clone, + C: NodeComponentsBuilder + Clone + Sync + Unpin + 'static, +{ + type ComponentsBuilder = C; + + fn components_builder(self) -> Self::ComponentsBuilder { + self.1 + } +} + /// The launched node with all components including RPC handlers. /// /// This can be used to interact with the launched node.