From ded25e755bd3b2512b3695931b0a6013b1602f18 Mon Sep 17 00:00:00 2001 From: librelois <c@elo.tf> Date: Fri, 21 Jan 2022 22:03:52 +0100 Subject: [PATCH] =?UTF-8?q?feat(gdev):=C2=A0create=20local=20chain=20spec?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- node/src/chain_spec/gdev.rs | 48 +++++++++++++++++++++++++++++++++++++ node/src/command.rs | 31 ++++++++++++++++++++---- 2 files changed, 75 insertions(+), 4 deletions(-) diff --git a/node/src/chain_spec/gdev.rs b/node/src/chain_spec/gdev.rs index e8f1b157f..e1c9ea534 100644 --- a/node/src/chain_spec/gdev.rs +++ b/node/src/chain_spec/gdev.rs @@ -101,6 +101,54 @@ pub fn development_chain_spec() -> Result<ChainSpec, String> { )) } +pub fn local_testnet_config( + initial_authorities_len: usize, + initial_smiths_len: usize, + initial_identities_len: usize, +) -> Result<ChainSpec, String> { + let wasm_binary = WASM_BINARY.ok_or_else(|| "wasm not available".to_string())?; + + Ok(ChainSpec::from_genesis( + // Name + "Äždev Local Testnet", + // ID + "gdev_local_testnet", + ChainType::Local, + move || { + gen_genesis_conf( + wasm_binary, + // Initial authorities len + initial_authorities_len, + // Initial smiths len, + initial_smiths_len, + // Initial identities len + initial_identities_len, + // Sudo account + get_account_id_from_seed::<sr25519::Public>("Alice"), + true, + ) + }, + // Bootnodes + vec![], + // Telemetry + None, + // Protocol ID + None, + // Properties + Some( + serde_json::json!({ + "tokenDecimals": TOKEN_DECIMALS, + "tokenSymbol": TOKEN_SYMBOL, + }) + .as_object() + .expect("must be a map") + .clone(), + ), + // Extensions + None, + )) +} + fn gen_genesis_conf( wasm_binary: &[u8], initial_authorities_len: usize, diff --git a/node/src/command.rs b/node/src/command.rs index b0e3847fa..4a671429f 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -54,15 +54,38 @@ impl SubstrateCli for Cli { fn load_spec(&self, id: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> { Ok(match id { #[cfg(feature = "gdev")] - "dev" | "gdev" => Box::new(chain_spec::gdev::development_chain_spec()?), + "dev" => Box::new(chain_spec::gdev::development_chain_spec()?), + #[cfg(feature = "gdev")] + "local" => Box::new(chain_spec::gdev::local_testnet_config(1, 3, 4)?), + #[cfg(feature = "gdev")] + "local2" => Box::new(chain_spec::gdev::local_testnet_config(2, 3, 4)?), + #[cfg(feature = "gdev")] + "local3" => Box::new(chain_spec::gdev::local_testnet_config(3, 3, 4)?), + #[cfg(feature = "gdev")] + "local4" => Box::new(chain_spec::gdev::local_testnet_config(4, 4, 5)?), + #[cfg(feature = "gdev")] + "gdev" => { + unimplemented!() + //Box::new(chain_spec::gdev::ChainSpec::from_json_file(file_path)?) + } #[cfg(feature = "gtest")] "gtest_dev" => Box::new(chain_spec::gtest::development_chain_spec()?), #[cfg(feature = "gtest")] - "local" | "gtest_local" => Box::new(chain_spec::gtest::local_testnet_config(2, 3)?), + "gtest_local" => Box::new(chain_spec::gtest::local_testnet_config(2, 3)?), + #[cfg(feature = "gtest")] + "gtest_local3" => Box::new(chain_spec::gtest::local_testnet_config(3, 4)?), #[cfg(feature = "gtest")] - "local3" | "gtest_local3" => Box::new(chain_spec::gtest::local_testnet_config(3, 4)?), + "gtest_local4" => Box::new(chain_spec::gtest::local_testnet_config(4, 5)?), #[cfg(feature = "gtest")] - "local4" | "gtest_local4" => Box::new(chain_spec::gtest::local_testnet_config(4, 5)?), + "gtest" => { + unimplemented!() + //Box::new(chain_spec::gtest::ChainSpec::from_json_file(file_path)?) + } + #[cfg(feature = "g1")] + "g1" => { + unimplemented!() + //Box::new(chain_spec::g1::ChainSpec::from_json_file(file_path)?) + } // Specs provided as json specify which runtime to use in their file name. For example, // `g1-custom.json` uses the g1 runtime. // `gdev-workshop.json` uses the gdev runtime. -- GitLab