Skip to content

Commit

Permalink
feat: add AnyNode type (#9056)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Seitz <[email protected]>
  • Loading branch information
romanroibu and mattsse authored Jun 24, 2024
1 parent f540388 commit bc45619
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion crates/node/builder/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,6 +28,44 @@ pub trait Node<N: FullNodeTypes>: NodeTypes + Clone {
fn components_builder(self) -> Self::ComponentsBuilder;
}

/// A [`Node`] type builder
#[derive(Clone, Default, Debug)]
pub struct AnyNode<N = (), C = ()>(PhantomData<N>, C);

impl<N, C> AnyNode<N, C> {
/// Configures the types of the node.
pub fn types<T>(self) -> AnyNode<T, C> {
AnyNode::<T, C>(PhantomData::<T>, self.1)
}

/// Sets the node components builder.
pub fn components_builder<T>(self, value: T) -> AnyNode<N, T> {
AnyNode::<N, T>(PhantomData::<N>, value)
}
}

impl<N, C> NodeTypes for AnyNode<N, C>
where
N: FullNodeTypes,
C: NodeComponentsBuilder<N> + Sync + Unpin + 'static,
{
type Primitives = N::Primitives;

type Engine = N::Engine;
}

impl<N, C> Node<N> for AnyNode<N, C>
where
N: FullNodeTypes + Clone,
C: NodeComponentsBuilder<N> + 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.
Expand Down

0 comments on commit bc45619

Please sign in to comment.