--- a/node/cli/src/chain_spec.rs +++ b/node/cli/src/chain_spec.rs @@ -26,8 +26,17 @@ use unique_runtime_common::types::*; -/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type. -pub type ChainSpec = sc_service::GenericChainSpec; +/// The `ChainSpec` parameterized for the unique runtime. +#[cfg(feature = "unique-runtime")] +pub type UniqueChainSpec = sc_service::GenericChainSpec; + +/// The `ChainSpec` parameterized for the quartz runtime. +#[cfg(feature = "quartz-runtime")] +pub type QuartzChainSpec = sc_service::GenericChainSpec; + +/// The `ChainSpec` parameterized for the opal runtime. +#[cfg(feature = "opal-runtime")] +pub type OpalChainSpec = sc_service::GenericChainSpec; pub trait RuntimeIdentification { fn is_unique(&self) -> bool; @@ -48,6 +57,8 @@ fn is_opal(&self) -> bool { self.id().starts_with("opal") + || self.id() == "dev" + || self.id() == "local_testnet" } } @@ -85,13 +96,13 @@ AccountPublic::from(get_from_seed::(seed)).into_account() } -pub fn development_config() -> ChainSpec { +pub fn development_config() -> OpalChainSpec { let mut properties = Map::new(); properties.insert("tokenSymbol".into(), "OPL".into()); properties.insert("tokenDecimals".into(), 15.into()); properties.insert("ss58Format".into(), 42.into()); - ChainSpec::from_genesis( + OpalChainSpec::from_genesis( // Name "Development", // ID @@ -130,8 +141,8 @@ ) } -pub fn local_testnet_rococo_config() -> ChainSpec { - ChainSpec::from_genesis( +pub fn local_testnet_rococo_config() -> OpalChainSpec { + OpalChainSpec::from_genesis( // Name "Local Testnet", // ID @@ -180,8 +191,8 @@ ) } -pub fn local_testnet_westend_config() -> ChainSpec { - ChainSpec::from_genesis( +pub fn local_testnet_westend_config() -> OpalChainSpec { + OpalChainSpec::from_genesis( // Name "Local Testnet", // ID @@ -238,8 +249,8 @@ initial_authorities: Vec, endowed_accounts: Vec, id: ParaId, -) -> unique_runtime::GenesisConfig { - use unique_runtime::*; +) -> opal_runtime::GenesisConfig { + use opal_runtime::*; GenesisConfig { system: SystemConfig { --- a/node/cli/src/command.rs +++ b/node/cli/src/command.rs @@ -75,15 +75,41 @@ } fn load_spec(id: &str) -> std::result::Result, String> { - Ok(match id { - "westend-local" => Box::new(chain_spec::local_testnet_westend_config()), - "rococo-local" => Box::new(chain_spec::local_testnet_rococo_config()), - "dev" => Box::new(chain_spec::development_config()), - "" | "local" => Box::new(chain_spec::local_testnet_rococo_config()), - path => Box::new(chain_spec::ChainSpec::from_json_file( - std::path::PathBuf::from(path), - )?), - }) + match id { + "westend-local" => Ok(Box::new(chain_spec::local_testnet_westend_config())), + "rococo-local" => Ok(Box::new(chain_spec::local_testnet_rococo_config())), + "dev" => Ok(Box::new(chain_spec::development_config())), + "" | "local" => Ok(Box::new(chain_spec::local_testnet_rococo_config())), + path => { + let path = std::path::PathBuf::from(path); + let chain_spec = Box::new( + chain_spec::UniqueChainSpec::from_json_file(path.clone())? + ) as Box; + + #[cfg(feature = "unique-runtime")] + if chain_spec.is_unique() { + return Ok(chain_spec); + } + + #[cfg(feature = "quartz-runtime")] + if chain_spec.is_quartz() { + let chain_spec = chain_spec::QuartzChainSpec::from_json_file( + path + )?; + return Ok(Box::new(chain_spec)); + } + + #[cfg(feature = "opal-runtime")] + if chain_spec.is_opal() { + let chain_spec = chain_spec::OpalChainSpec::from_json_file( + path + )?; + return Ok(Box::new(chain_spec)); + } + + Err(no_runtime_err!(chain_spec)) + }, + } } impl SubstrateCli for Cli {