reth_cli_commands/stage/
mod.rs1use std::sync::Arc;
4
5use crate::common::{CliNodeComponents, CliNodeTypes};
6use clap::{Parser, Subcommand};
7use reth_chainspec::{EthChainSpec, EthereumHardforks, Hardforks};
8use reth_cli::chainspec::ChainSpecParser;
9use reth_cli_runner::CliContext;
10use reth_eth_wire::NetPrimitivesFor;
11
12pub mod drop;
13pub mod dump;
14pub mod run;
15pub mod unwind;
16
17#[derive(Debug, Parser)]
19pub struct Command<C: ChainSpecParser> {
20 #[command(subcommand)]
21 command: Subcommands<C>,
22}
23
24#[derive(Subcommand, Debug)]
26pub enum Subcommands<C: ChainSpecParser> {
27 Run(Box<run::Command<C>>),
34 Drop(drop::Command<C>),
36 Dump(dump::Command<C>),
38 Unwind(unwind::Command<C>),
40}
41
42impl<C: ChainSpecParser<ChainSpec: EthChainSpec + Hardforks + EthereumHardforks>> Command<C> {
43 pub async fn execute<N, Comp, F, P>(self, ctx: CliContext, components: F) -> eyre::Result<()>
45 where
46 N: CliNodeTypes<ChainSpec = C::ChainSpec>,
47 Comp: CliNodeComponents<N>,
48 F: FnOnce(Arc<C::ChainSpec>) -> Comp,
49 P: NetPrimitivesFor<N::Primitives>,
50 {
51 match self.command {
52 Subcommands::Run(command) => command.execute::<N, _, _, P>(ctx, components).await,
53 Subcommands::Drop(command) => command.execute::<N>().await,
54 Subcommands::Dump(command) => command.execute::<N, _, _>(components).await,
55 Subcommands::Unwind(command) => command.execute::<N, _, _>(components).await,
56 }
57 }
58}
59
60impl<C: ChainSpecParser> Command<C> {
61 pub fn chain_spec(&self) -> Option<&Arc<C::ChainSpec>> {
63 match self.command {
64 Subcommands::Run(ref command) => command.chain_spec(),
65 Subcommands::Drop(ref command) => command.chain_spec(),
66 Subcommands::Dump(ref command) => command.chain_spec(),
67 Subcommands::Unwind(ref command) => command.chain_spec(),
68 }
69 }
70}