forked from berachain/polaris-reth
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add network example (paradigmxyz#3753)
- Loading branch information
Showing
6 changed files
with
84 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//! Example of how to use the network as a standalone component | ||
//! | ||
//! Run with | ||
//! | ||
//! ```not_rust | ||
//! cargo run --example network | ||
//! ``` | ||
use futures::StreamExt; | ||
use reth_network::{config::rng_secret_key, NetworkConfig, NetworkManager}; | ||
use reth_provider::test_utils::NoopProvider; | ||
|
||
#[tokio::main] | ||
async fn main() -> eyre::Result<()> { | ||
// This block provider implementation is used for testing purposes. | ||
let client = NoopProvider::default(); | ||
|
||
// The key that's used for encrypting sessions and to identify our node. | ||
let local_key = rng_secret_key(); | ||
|
||
// Configure the network | ||
let config = | ||
NetworkConfig::<NoopProvider>::builder(local_key).mainnet_boot_nodes().build(client); | ||
|
||
// create the network instance | ||
let network = NetworkManager::new(config).await?; | ||
|
||
// get a handle to the network to interact with it | ||
let handle = network.handle().clone(); | ||
|
||
// spawn the network | ||
tokio::task::spawn(network); | ||
|
||
// interact with the network | ||
let mut events = handle.event_listener(); | ||
while let Some(event) = events.next().await { | ||
println!("Received event: {:?}", event); | ||
} | ||
|
||
Ok(()) | ||
} |