reth_cli_commands/
dump_genesis.rs

1//! Command that dumps genesis block JSON configuration to stdout
2use std::sync::Arc;
3
4use clap::Parser;
5use reth_chainspec::EthChainSpec;
6use reth_cli::chainspec::ChainSpecParser;
7
8/// Dumps genesis block JSON configuration to stdout
9#[derive(Debug, Parser)]
10pub struct DumpGenesisCommand<C: ChainSpecParser> {
11    /// The chain this node is running.
12    ///
13    /// Possible values are either a built-in chain or the path to a chain specification file.
14    #[arg(
15        long,
16        value_name = "CHAIN_OR_PATH",
17        long_help = C::help_message(),
18        default_value = C::SUPPORTED_CHAINS[0],
19        value_parser = C::parser()
20    )]
21    chain: Arc<C::ChainSpec>,
22}
23
24impl<C: ChainSpecParser<ChainSpec: EthChainSpec>> DumpGenesisCommand<C> {
25    /// Execute the `dump-genesis` command
26    pub async fn execute(self) -> eyre::Result<()> {
27        println!("{}", serde_json::to_string_pretty(self.chain.genesis())?);
28        Ok(())
29    }
30}
31
32#[cfg(test)]
33mod tests {
34    use super::*;
35    use reth_ethereum_cli::chainspec::{EthereumChainSpecParser, SUPPORTED_CHAINS};
36
37    #[test]
38    fn parse_dump_genesis_command_chain_args() {
39        for chain in SUPPORTED_CHAINS {
40            let args: DumpGenesisCommand<EthereumChainSpecParser> =
41                DumpGenesisCommand::parse_from(["reth", "--chain", chain]);
42            assert_eq!(
43                Ok(args.chain.chain),
44                chain.parse::<reth_chainspec::Chain>(),
45                "failed to parse chain {chain}"
46            );
47        }
48    }
49}