reth_optimism_cli/commands/
mod.rs

1use crate::chainspec::OpChainSpecParser;
2use clap::Subcommand;
3use import::ImportOpCommand;
4use import_receipts::ImportReceiptsOpCommand;
5use reth_chainspec::{EthChainSpec, EthereumHardforks, Hardforks};
6use reth_cli::chainspec::ChainSpecParser;
7use reth_cli_commands::{
8    config_cmd, db, dump_genesis, init_cmd,
9    node::{self, NoArgs},
10    p2p, prune, recover, stage,
11};
12use std::{fmt, sync::Arc};
13
14pub mod import;
15pub mod import_receipts;
16pub mod init_state;
17
18#[cfg(feature = "dev")]
19pub mod test_vectors;
20
21/// Commands to be executed
22#[derive(Debug, Subcommand)]
23#[expect(clippy::large_enum_variant)]
24pub enum Commands<Spec: ChainSpecParser = OpChainSpecParser, Ext: clap::Args + fmt::Debug = NoArgs>
25{
26    /// Start the node
27    #[command(name = "node")]
28    Node(Box<node::NodeCommand<Spec, Ext>>),
29    /// Initialize the database from a genesis file.
30    #[command(name = "init")]
31    Init(init_cmd::InitCommand<Spec>),
32    /// Initialize the database from a state dump file.
33    #[command(name = "init-state")]
34    InitState(init_state::InitStateCommandOp<Spec>),
35    /// This syncs RLP encoded OP blocks below Bedrock from a file, without executing.
36    #[command(name = "import-op")]
37    ImportOp(ImportOpCommand<Spec>),
38    /// This imports RLP encoded receipts from a file.
39    #[command(name = "import-receipts-op")]
40    ImportReceiptsOp(ImportReceiptsOpCommand<Spec>),
41    /// Dumps genesis block JSON configuration to stdout.
42    DumpGenesis(dump_genesis::DumpGenesisCommand<Spec>),
43    /// Database debugging utilities
44    #[command(name = "db")]
45    Db(db::Command<Spec>),
46    /// Manipulate individual stages.
47    #[command(name = "stage")]
48    Stage(Box<stage::Command<Spec>>),
49    /// P2P Debugging utilities
50    #[command(name = "p2p")]
51    P2P(p2p::Command<Spec>),
52    /// Write config to stdout
53    #[command(name = "config")]
54    Config(config_cmd::Command),
55    /// Scripts for node recovery
56    #[command(name = "recover")]
57    Recover(recover::Command<Spec>),
58    /// Prune according to the configuration without any limits
59    #[command(name = "prune")]
60    Prune(prune::PruneCommand<Spec>),
61    /// Generate Test Vectors
62    #[cfg(feature = "dev")]
63    #[command(name = "test-vectors")]
64    TestVectors(test_vectors::Command),
65}
66
67impl<
68        C: ChainSpecParser<ChainSpec: EthChainSpec + Hardforks + EthereumHardforks>,
69        Ext: clap::Args + fmt::Debug,
70    > Commands<C, Ext>
71{
72    /// Returns the underlying chain being used for commands
73    pub fn chain_spec(&self) -> Option<&Arc<C::ChainSpec>> {
74        match self {
75            Self::Node(cmd) => cmd.chain_spec(),
76            Self::Init(cmd) => cmd.chain_spec(),
77            Self::InitState(cmd) => cmd.chain_spec(),
78            Self::DumpGenesis(cmd) => cmd.chain_spec(),
79            Self::Db(cmd) => cmd.chain_spec(),
80            Self::Stage(cmd) => cmd.chain_spec(),
81            Self::P2P(cmd) => cmd.chain_spec(),
82            Self::Config(_) => None,
83            Self::Recover(cmd) => cmd.chain_spec(),
84            Self::Prune(cmd) => cmd.chain_spec(),
85            Self::ImportOp(cmd) => cmd.chain_spec(),
86            Self::ImportReceiptsOp(cmd) => cmd.chain_spec(),
87            #[cfg(feature = "dev")]
88            Self::TestVectors(_) => None,
89        }
90    }
91}