Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add AnyNode type #9056

Merged
merged 5 commits into from
Jun 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);

Comment on lines +33 to +34
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we also need two functions

  1. set N
  2. set 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
Loading