From 6e403ec1a4b8b3c08d52bf49767da32b9a1971d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Sat, 29 May 2021 20:53:24 +0200 Subject: [PATCH] Be more smart when loading the chain spec (#3135) Instead of relying on the name of the chain spec file, we now use the `is_*` methods for this. --- polkadot/cli/src/command.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/polkadot/cli/src/command.rs b/polkadot/cli/src/command.rs index 42aeb46e83..7dde1f4379 100644 --- a/polkadot/cli/src/command.rs +++ b/polkadot/cli/src/command.rs @@ -95,20 +95,18 @@ impl SubstrateCli for Cli { path => { let path = std::path::PathBuf::from(path); - let starts_with = |prefix: &str| { - path.file_name().map(|f| f.to_str().map(|s| s.starts_with(&prefix))).flatten().unwrap_or(false) - }; + let chain_spec = Box::new(service::PolkadotChainSpec::from_json_file(path.clone())?) as Box; // When `force_*` is given or the file name starts with the name of one of the known chains, // we use the chain spec for the specific chain. - if self.run.force_rococo || starts_with("rococo") || starts_with("wococo") { + if self.run.force_rococo || chain_spec.is_rococo() || chain_spec.is_wococo() { Box::new(service::RococoChainSpec::from_json_file(path)?) - } else if self.run.force_kusama || starts_with("kusama") { + } else if self.run.force_kusama || chain_spec.is_kusama() { Box::new(service::KusamaChainSpec::from_json_file(path)?) - } else if self.run.force_westend || starts_with("westend") { + } else if self.run.force_westend || chain_spec.is_westend() { Box::new(service::WestendChainSpec::from_json_file(path)?) } else { - Box::new(service::PolkadotChainSpec::from_json_file(path)?) + chain_spec } }, })