diff --git a/Cargo.lock b/Cargo.lock index ba865e6d03..0e8f028501 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3343,10 +3343,12 @@ dependencies = [ name = "example-exex-hello-world" version = "0.0.0" dependencies = [ + "clap", "eyre", "futures", "reth", "reth-ethereum", + "reth-op", "reth-tracing", ] @@ -8625,6 +8627,7 @@ dependencies = [ "reth-network", "reth-node-api", "reth-optimism-chainspec", + "reth-optimism-cli", "reth-optimism-consensus", "reth-optimism-evm", "reth-optimism-node", diff --git a/crates/optimism/reth/Cargo.toml b/crates/optimism/reth/Cargo.toml index 883fdb9218..d482dd6141 100644 --- a/crates/optimism/reth/Cargo.toml +++ b/crates/optimism/reth/Cargo.toml @@ -35,6 +35,7 @@ reth-optimism-consensus = { workspace = true, optional = true } reth-optimism-evm = { workspace = true, optional = true } reth-optimism-node = { workspace = true, optional = true } reth-optimism-rpc = { workspace = true, optional = true } +reth-optimism-cli = { workspace = true, optional = true } [features] default = ["std"] @@ -75,6 +76,7 @@ full = ["consensus", "evm", "node", "provider", "rpc", "trie"] alloy-compat = [ "reth-optimism-primitives/alloy-compat", ] +cli = ["dep:reth-optimism-cli"] consensus = ["dep:reth-consensus", "dep:reth-consensus-common", "dep:reth-optimism-consensus"] evm = ["dep:reth-evm", "dep:reth-optimism-evm"] node-api = ["dep:reth-node-api"] diff --git a/crates/optimism/reth/src/lib.rs b/crates/optimism/reth/src/lib.rs index d6b64153a1..5bed355926 100644 --- a/crates/optimism/reth/src/lib.rs +++ b/crates/optimism/reth/src/lib.rs @@ -20,6 +20,10 @@ pub mod primitives { pub use reth_primitives_traits::*; } +/// Re-exported cli types +#[cfg(feature = "cli")] +pub use reth_optimism_cli as cli; + /// Re-exported consensus types #[cfg(feature = "consensus")] pub mod consensus { diff --git a/examples/exex-hello-world/Cargo.toml b/examples/exex-hello-world/Cargo.toml index 0f82aff3a1..896886cd7d 100644 --- a/examples/exex-hello-world/Cargo.toml +++ b/examples/exex-hello-world/Cargo.toml @@ -13,3 +13,5 @@ reth-tracing.workspace = true eyre.workspace = true futures.workspace = true +clap = { workspace = true, features = ["derive"] } +reth-op = { workspace = true, features = ["full", "cli"] } diff --git a/examples/exex-hello-world/src/main.rs b/examples/exex-hello-world/src/main.rs index 140e460c54..d5f8fd284f 100644 --- a/examples/exex-hello-world/src/main.rs +++ b/examples/exex-hello-world/src/main.rs @@ -6,20 +6,21 @@ //! cargo run -p example-exex-hello-world -- node --dev --dev.block-time 5s //! ``` +use clap::Parser; use futures::TryStreamExt; use reth_ethereum::{ exex::{ExExContext, ExExEvent, ExExNotification}, - node::{ - api::{FullNodeComponents, NodeTypes}, - EthereumNode, - }, - EthPrimitives, + node::{api::FullNodeComponents, EthereumNode}, }; use reth_tracing::tracing::info; -async fn my_exex>>( - mut ctx: ExExContext, -) -> eyre::Result<()> { +#[derive(Parser)] +struct ExExArgs { + #[arg(long)] + optimism: bool, +} + +async fn my_exex(mut ctx: ExExContext) -> eyre::Result<()> { while let Some(notification) = ctx.notifications.try_next().await? { match ¬ification { ExExNotification::ChainCommitted { new } => { @@ -42,13 +43,31 @@ async fn my_exex eyre::Result<()> { - reth::cli::Cli::parse_args().run(async move |builder, _| { - let handle = builder - .node(EthereumNode::default()) - .install_exex("my-exex", async move |ctx| Ok(my_exex(ctx))) - .launch() - .await?; + let args = ExExArgs::parse(); - handle.wait_for_node_exit().await - }) + if args.optimism { + reth_op::cli::Cli::parse_args().run(|builder, _| { + Box::pin(async move { + let handle = builder + .node(reth_op::node::OpNode::default()) + .install_exex("my-exex", async move |ctx| Ok(my_exex(ctx))) + .launch() + .await?; + + handle.wait_for_node_exit().await + }) + }) + } else { + reth::cli::Cli::parse_args().run(|builder, _| { + Box::pin(async move { + let handle = builder + .node(EthereumNode::default()) + .install_exex("my-exex", async move |ctx| Ok(my_exex(ctx))) + .launch() + .await?; + + handle.wait_for_node_exit().await + }) + }) + } }