chore: rm custom chainspec parser (#8998)

This commit is contained in:
Matthias Seitz
2024-06-20 20:44:31 +02:00
committed by GitHub
parent d213c1eadf
commit 27d26ac10d
2 changed files with 2 additions and 32 deletions

View File

@ -3,7 +3,7 @@
use crate::{ use crate::{
args::{ args::{
get_secret_key, get_secret_key,
utils::{chain_help, chain_spec_value_parser, hash_or_num_value_parser, SUPPORTED_CHAINS}, utils::{chain_help, genesis_value_parser, hash_or_num_value_parser, SUPPORTED_CHAINS},
DatabaseArgs, DiscoveryArgs, NetworkArgs, DatabaseArgs, DiscoveryArgs, NetworkArgs,
}, },
utils::get_single_header, utils::get_single_header,
@ -40,7 +40,7 @@ pub struct Command {
value_name = "CHAIN_OR_PATH", value_name = "CHAIN_OR_PATH",
long_help = chain_help(), long_help = chain_help(),
default_value = SUPPORTED_CHAINS[0], default_value = SUPPORTED_CHAINS[0],
value_parser = chain_spec_value_parser value_parser = genesis_value_parser
)] )]
chain: Arc<ChainSpec>, chain: Arc<ChainSpec>,

View File

@ -32,35 +32,6 @@ pub fn parse_duration_from_secs(arg: &str) -> eyre::Result<Duration, std::num::P
Ok(Duration::from_secs(seconds)) Ok(Duration::from_secs(seconds))
} }
/// Clap value parser for [`ChainSpec`]s that takes either a built-in chainspec or the path
/// to a custom one.
pub fn chain_spec_value_parser(s: &str) -> eyre::Result<Arc<ChainSpec>, eyre::Error> {
Ok(match s {
#[cfg(not(feature = "optimism"))]
"mainnet" => MAINNET.clone(),
#[cfg(not(feature = "optimism"))]
"goerli" => GOERLI.clone(),
#[cfg(not(feature = "optimism"))]
"sepolia" => SEPOLIA.clone(),
#[cfg(not(feature = "optimism"))]
"holesky" => HOLESKY.clone(),
#[cfg(not(feature = "optimism"))]
"dev" => DEV.clone(),
#[cfg(feature = "optimism")]
"optimism" => OP_MAINNET.clone(),
#[cfg(feature = "optimism")]
"optimism_sepolia" | "optimism-sepolia" => OP_SEPOLIA.clone(),
#[cfg(feature = "optimism")]
"base" => BASE_MAINNET.clone(),
#[cfg(feature = "optimism")]
"base_sepolia" | "base-sepolia" => BASE_SEPOLIA.clone(),
_ => {
let raw = fs::read_to_string(PathBuf::from(shellexpand::full(s)?.into_owned()))?;
serde_json::from_str(&raw)?
}
})
}
/// The help info for the --chain flag /// The help info for the --chain flag
pub fn chain_help() -> String { pub fn chain_help() -> String {
format!("The chain this node is running.\nPossible values are either a built-in chain or the path to a chain specification file.\n\nBuilt-in chains:\n {}", SUPPORTED_CHAINS.join(", ")) format!("The chain this node is running.\nPossible values are either a built-in chain or the path to a chain specification file.\n\nBuilt-in chains:\n {}", SUPPORTED_CHAINS.join(", "))
@ -178,7 +149,6 @@ mod tests {
#[test] #[test]
fn parse_known_chain_spec() { fn parse_known_chain_spec() {
for chain in SUPPORTED_CHAINS { for chain in SUPPORTED_CHAINS {
chain_spec_value_parser(chain).unwrap();
genesis_value_parser(chain).unwrap(); genesis_value_parser(chain).unwrap();
} }
} }