git.delta.rocks / unique-network / refs/commits / 5985fa11530c

difftreelog

Fix load_spec and is_opal

Daniel Shiposha2022-03-14parent: #89a64dc.patch.diff
in: master

2 files changed

modifiednode/cli/src/chain_spec.rsdiffbeforeafterboth
2626
27use unique_runtime_common::types::*;27use unique_runtime_common::types::*;
2828
29/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.29/// The `ChainSpec` parameterized for the unique runtime.
30#[cfg(feature = "unique-runtime")]
30pub type ChainSpec = sc_service::GenericChainSpec<unique_runtime::GenesisConfig, Extensions>;31pub type UniqueChainSpec = sc_service::GenericChainSpec<unique_runtime::GenesisConfig, Extensions>;
32
33/// The `ChainSpec` parameterized for the quartz runtime.
34#[cfg(feature = "quartz-runtime")]
35pub type QuartzChainSpec = sc_service::GenericChainSpec<quartz_runtime::GenesisConfig, Extensions>;
36
37/// The `ChainSpec` parameterized for the opal runtime.
38#[cfg(feature = "opal-runtime")]
39pub type OpalChainSpec = sc_service::GenericChainSpec<opal_runtime::GenesisConfig, Extensions>;
3140
32pub trait RuntimeIdentification {41pub trait RuntimeIdentification {
33 fn is_unique(&self) -> bool;42 fn is_unique(&self) -> bool;
4857
49 fn is_opal(&self) -> bool {58 fn is_opal(&self) -> bool {
50 self.id().starts_with("opal")59 self.id().starts_with("opal")
60 || self.id() == "dev"
61 || self.id() == "local_testnet"
51 }62 }
52}63}
5364
85 AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()96 AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
86}97}
8798
88pub fn development_config() -> ChainSpec {99pub fn development_config() -> OpalChainSpec {
89 let mut properties = Map::new();100 let mut properties = Map::new();
90 properties.insert("tokenSymbol".into(), "OPL".into());101 properties.insert("tokenSymbol".into(), "OPL".into());
91 properties.insert("tokenDecimals".into(), 15.into());102 properties.insert("tokenDecimals".into(), 15.into());
92 properties.insert("ss58Format".into(), 42.into());103 properties.insert("ss58Format".into(), 42.into());
93104
94 ChainSpec::from_genesis(105 OpalChainSpec::from_genesis(
95 // Name106 // Name
96 "Development",107 "Development",
97 // ID108 // ID
130 )141 )
131}142}
132143
133pub fn local_testnet_rococo_config() -> ChainSpec {144pub fn local_testnet_rococo_config() -> OpalChainSpec {
134 ChainSpec::from_genesis(145 OpalChainSpec::from_genesis(
135 // Name146 // Name
136 "Local Testnet",147 "Local Testnet",
137 // ID148 // ID
180 )191 )
181}192}
182193
183pub fn local_testnet_westend_config() -> ChainSpec {194pub fn local_testnet_westend_config() -> OpalChainSpec {
184 ChainSpec::from_genesis(195 OpalChainSpec::from_genesis(
185 // Name196 // Name
186 "Local Testnet",197 "Local Testnet",
187 // ID198 // ID
238 initial_authorities: Vec<AuraId>,249 initial_authorities: Vec<AuraId>,
239 endowed_accounts: Vec<AccountId>,250 endowed_accounts: Vec<AccountId>,
240 id: ParaId,251 id: ParaId,
241) -> unique_runtime::GenesisConfig {252) -> opal_runtime::GenesisConfig {
242 use unique_runtime::*;253 use opal_runtime::*;
243254
244 GenesisConfig {255 GenesisConfig {
245 system: SystemConfig {256 system: SystemConfig {
modifiednode/cli/src/command.rsdiffbeforeafterboth
--- a/node/cli/src/command.rs
+++ b/node/cli/src/command.rs
@@ -75,15 +75,41 @@
 }
 
 fn load_spec(id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, 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<dyn sc_service::ChainSpec>;
+
+			#[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 {