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

chore: add a few noop functions to builder #3659

Merged
merged 4 commits into from
Jul 7, 2023
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
45 changes: 43 additions & 2 deletions crates/rpc/rpc-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ use reth_rpc::{
NetApi, RPCApi, TraceApi, TracingCallGuard, TxPoolApi, Web3Api,
};
use reth_rpc_api::{servers::*, EngineApiServer};
use reth_tasks::TaskSpawner;
use reth_tasks::{TaskSpawner, TokioTaskExecutor};
use reth_transaction_pool::TransactionPool;
use serde::{Deserialize, Serialize, Serializer};
use std::{
Expand Down Expand Up @@ -158,6 +158,8 @@ pub mod constants;
pub use crate::eth::{EthConfig, EthHandlers};
pub use jsonrpsee::server::ServerBuilder;
pub use reth_ipc::server::{Builder as IpcServerBuilder, Endpoint};
use reth_network_api::noop::NoopNetwork;
use reth_transaction_pool::noop::NoopTransactionPool;

/// Convenience function for starting a server in one step.
pub async fn launch<Provider, Pool, Network, Tasks, Events>(
Expand Down Expand Up @@ -192,7 +194,7 @@ where

/// A builder type to configure the RPC module: See [RpcModule]
///
/// This is the main entrypoint for up RPC servers.
/// This is the main entrypoint and the easiest way to configure an RPC server.
#[derive(Debug, Clone)]
pub struct RpcModuleBuilder<Provider, Pool, Network, Tasks, Events> {
/// The Provider type to when creating all rpc handlers
Expand Down Expand Up @@ -241,6 +243,24 @@ impl<Provider, Pool, Network, Tasks, Events>
RpcModuleBuilder { provider, network, pool, executor, events }
}

/// Configure a [NoopTransactionPool] instance.
///
/// Caution: This will configure a pool API that does abosultely nothing.
/// This is only intended for allow easier setup of namespaces that depend on the [EthApi] which
/// requires a [TransactionPool] implementation.
pub fn with_noop_pool(
self,
) -> RpcModuleBuilder<Provider, NoopTransactionPool, Network, Tasks, Events> {
let Self { provider, executor, events, network, .. } = self;
RpcModuleBuilder {
provider,
executor,
events,
network,
pool: NoopTransactionPool::default(),
}
}

/// Configure the network instance.
pub fn with_network<N>(self, network: N) -> RpcModuleBuilder<Provider, Pool, N, Tasks, Events>
where
Expand All @@ -250,6 +270,16 @@ impl<Provider, Pool, Network, Tasks, Events>
RpcModuleBuilder { provider, network, pool, executor, events }
}

/// Configure a [NoopNetwork] instance.
///
/// Caution: This will configure a network API that does abosultely nothing.
/// This is only intended for allow easier setup of namespaces that depend on the [EthApi] which
/// requires a [NetworkInfo] implementation.
pub fn with_noop_network(self) -> RpcModuleBuilder<Provider, Pool, NoopNetwork, Tasks, Events> {
let Self { provider, pool, executor, events, .. } = self;
RpcModuleBuilder { provider, pool, executor, events, network: NoopNetwork::default() }
}

/// Configure the task executor to use for additional tasks.
pub fn with_executor<T>(
self,
Expand All @@ -262,6 +292,17 @@ impl<Provider, Pool, Network, Tasks, Events>
RpcModuleBuilder { provider, network, pool, executor, events }
}

/// Configure [TokioTaskExecutor] as the task executor to use for additional tasks.
///
/// This will spawn additional tasks directly via `tokio::task::spawn`, See
/// [TokioTaskExecutor].
pub fn with_tokio_executor(
self,
) -> RpcModuleBuilder<Provider, Pool, Network, TokioTaskExecutor, Events> {
let Self { pool, network, provider, events, .. } = self;
RpcModuleBuilder { provider, network, pool, events, executor: TokioTaskExecutor::default() }
}

/// Configure the event subscriber instance
pub fn with_events<E>(self, events: E) -> RpcModuleBuilder<Provider, Pool, Network, Tasks, E>
where
Expand Down