Files
reth/examples/node-event-hooks/src/main.rs
2025-04-24 18:30:07 +00:00

42 lines
1.2 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! Example for how hook into the node via the CLI extension mechanism without registering
//! additional arguments
//!
//! Run with
//!
//! ```sh
//! cargo run -p node-event-hooks -- node
//! ```
//!
//! This launches a regular reth node and also print:
//! > "All components initialized" once all components have been initialized
//! > "Node started" once the node has been started.
#![warn(unused_crate_dependencies)]
use reth_ethereum::{cli::interface::Cli, node::EthereumNode};
fn main() {
Cli::parse_args()
.run(|builder, _| async move {
let handle = builder
.node(EthereumNode::default())
.on_node_started(|_ctx| {
println!("Node started");
Ok(())
})
.on_rpc_started(|_ctx, _handles| {
println!("RPC started");
Ok(())
})
.on_component_initialized(|_ctx| {
println!("All components initialized");
Ok(())
})
.launch()
.await?;
handle.wait_for_node_exit().await
})
.unwrap();
}