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