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
75}75}
7676
77fn load_spec(id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {77fn load_spec(id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
78 Ok(match id {78 match id {
79 "westend-local" => Box::new(chain_spec::local_testnet_westend_config()),79 "westend-local" => Ok(Box::new(chain_spec::local_testnet_westend_config())),
80 "rococo-local" => Box::new(chain_spec::local_testnet_rococo_config()),80 "rococo-local" => Ok(Box::new(chain_spec::local_testnet_rococo_config())),
81 "dev" => Box::new(chain_spec::development_config()),81 "dev" => Ok(Box::new(chain_spec::development_config())),
82 "" | "local" => Box::new(chain_spec::local_testnet_rococo_config()),82 "" | "local" => Ok(Box::new(chain_spec::local_testnet_rococo_config())),
83 path => Box::new(chain_spec::ChainSpec::from_json_file(83 path => {
84 let path = std::path::PathBuf::from(path);
85 let chain_spec = Box::new(
84 std::path::PathBuf::from(path),86 chain_spec::UniqueChainSpec::from_json_file(path.clone())?
85 )?),87 ) as Box<dyn sc_service::ChainSpec>;
88
89 #[cfg(feature = "unique-runtime")]
90 if chain_spec.is_unique() {
91 return Ok(chain_spec);
92 }
93
94 #[cfg(feature = "quartz-runtime")]
95 if chain_spec.is_quartz() {
96 let chain_spec = chain_spec::QuartzChainSpec::from_json_file(
97 path
98 )?;
99 return Ok(Box::new(chain_spec));
100 }
101
102 #[cfg(feature = "opal-runtime")]
103 if chain_spec.is_opal() {
104 let chain_spec = chain_spec::OpalChainSpec::from_json_file(
105 path
106 )?;
107 return Ok(Box::new(chain_spec));
108 }
109
110 Err(no_runtime_err!(chain_spec))
111 },
86 })112 }
87}113}
88114
89impl SubstrateCli for Cli {115impl SubstrateCli for Cli {