Skip to content

Commit

Permalink
chore: simplify builder fn (paradigmxyz#4284)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Aug 20, 2023
1 parent 6512603 commit 9ebeca3
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
14 changes: 8 additions & 6 deletions crates/net/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,18 @@ pub struct NetworkConfig<C> {

// === impl NetworkConfig ===

impl<C> NetworkConfig<C> {
/// Create a new instance with all mandatory fields set, rest is field with defaults.
pub fn new(client: C, secret_key: SecretKey) -> Self {
Self::builder(secret_key).build(client)
}

impl NetworkConfig<()> {
/// Convenience method for creating the corresponding builder type
pub fn builder(secret_key: SecretKey) -> NetworkConfigBuilder {
NetworkConfigBuilder::new(secret_key)
}
}

impl<C> NetworkConfig<C> {
/// Create a new instance with all mandatory fields set, rest is field with defaults.
pub fn new(client: C, secret_key: SecretKey) -> Self {
NetworkConfig::builder(secret_key).build(client)
}

/// Sets the config to use for the discovery v4 protocol.
pub fn set_discovery_v4(mut self, discovery_config: Discv4Config) -> Self {
Expand Down
4 changes: 2 additions & 2 deletions crates/net/network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
//! // The key that's used for encrypting sessions and to identify our node.
//! let local_key = rng_secret_key();
//!
//! let config = NetworkConfig::<NoopProvider>::builder(local_key).boot_nodes(
//! let config = NetworkConfig::builder(local_key).boot_nodes(
//! mainnet_nodes()
//! ).build(client);
//!
Expand Down Expand Up @@ -101,7 +101,7 @@
//! let local_key = rng_secret_key();
//!
//! let config =
//! NetworkConfig::<NoopProvider>::builder(local_key).boot_nodes(mainnet_nodes()).build(client.clone());
//! NetworkConfig::builder(local_key).boot_nodes(mainnet_nodes()).build(client.clone());
//!
//! // create the network instance
//! let (handle, network, transactions, request_handler) = NetworkManager::builder(config)
Expand Down
2 changes: 1 addition & 1 deletion crates/net/network/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ where
/// let local_key = rng_secret_key();
///
/// let config =
/// NetworkConfig::<NoopProvider>::builder(local_key).boot_nodes(mainnet_nodes()).build(client.clone());
/// NetworkConfig::builder(local_key).boot_nodes(mainnet_nodes()).build(client.clone());
///
/// // create the network instance
/// let (handle, network, transactions, request_handler) = NetworkManager::builder(config)
Expand Down
2 changes: 1 addition & 1 deletion crates/net/network/tests/it/geth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async fn can_peer_with_geth() {
"setting up reth networking stack in keepalive test"
);

let config = NetworkConfig::<Arc<NoopProvider>>::builder(secret_key)
let config = NetworkConfig::builder(secret_key)
.listener_addr(reth_p2p)
.discovery_addr(reth_disc)
.chain_spec(chainspec)
Expand Down
3 changes: 1 addition & 2 deletions examples/network-txpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ async fn main() -> eyre::Result<()> {
let local_key = rng_secret_key();

// Configure the network
let config =
NetworkConfig::<NoopProvider>::builder(local_key).mainnet_boot_nodes().build(client);
let config = NetworkConfig::builder(local_key).mainnet_boot_nodes().build(client);

// create the network instance
let (_handle, network, txpool, _) =
Expand Down
3 changes: 1 addition & 2 deletions examples/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ async fn main() -> eyre::Result<()> {
let local_key = rng_secret_key();

// Configure the network
let config =
NetworkConfig::<NoopProvider>::builder(local_key).mainnet_boot_nodes().build(client);
let config = NetworkConfig::builder(local_key).mainnet_boot_nodes().build(client);

// create the network instance
let network = NetworkManager::new(config).await?;
Expand Down

0 comments on commit 9ebeca3

Please sign in to comment.