diff --git a/cumulus/polkadot-parachain/src/chain_spec/contracts.rs b/cumulus/polkadot-parachain/src/chain_spec/contracts.rs new file mode 100644 index 0000000000..de42636382 --- /dev/null +++ b/cumulus/polkadot-parachain/src/chain_spec/contracts.rs @@ -0,0 +1,279 @@ +// Copyright 2019-2021 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + +use crate::chain_spec::{ + get_account_id_from_seed, get_collator_keys_from_seed, Extensions, SAFE_XCM_VERSION, +}; +use cumulus_primitives_core::ParaId; +use hex_literal::hex; +use rococo_parachain_runtime::{AccountId, AuraId}; +use sc_service::ChainType; +use sp_core::{crypto::UncheckedInto, sr25519}; + +pub type ContractsRococoChainSpec = + sc_service::GenericChainSpec; + +/// No relay chain suffix because the id is the same over all relay chains. +const CONTRACTS_PARACHAIN_ID: u32 = 1002; + +/// The existential deposit is determined by the runtime "contracts-rococo". +const CONTRACTS_ROCOCO_ED: contracts_rococo_runtime::Balance = + contracts_rococo_runtime::constants::currency::EXISTENTIAL_DEPOSIT; + +pub fn contracts_rococo_development_config() -> ContractsRococoChainSpec { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("tokenSymbol".into(), "ROC".into()); + properties.insert("tokenDecimals".into(), 12.into()); + + ContractsRococoChainSpec::from_genesis( + // Name + "Contracts on Rococo Development", + // ID + "contracts-rococo-dev", + ChainType::Development, + move || { + contracts_rococo_genesis( + // initial collators. + vec![ + ( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + ), + ( + get_account_id_from_seed::("Bob"), + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + CONTRACTS_PARACHAIN_ID.into(), + ) + }, + Vec::new(), + None, + None, + None, + None, + Extensions { + relay_chain: "rococo-local".into(), // You MUST set this to the correct network! + para_id: CONTRACTS_PARACHAIN_ID, + }, + ) +} + +pub fn contracts_rococo_local_config() -> ContractsRococoChainSpec { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("tokenSymbol".into(), "ROC".into()); + properties.insert("tokenDecimals".into(), 12.into()); + + ContractsRococoChainSpec::from_genesis( + // Name + "Contracts on Rococo", + // ID + "contracts-rococo-local", + ChainType::Local, + move || { + contracts_rococo_genesis( + // initial collators. + vec![ + ( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + ), + ( + get_account_id_from_seed::("Bob"), + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + CONTRACTS_PARACHAIN_ID.into(), + ) + }, + // Bootnodes + Vec::new(), + // Telemetry + None, + // Protocol ID + None, + // Fork ID + None, + // Properties + Some(properties), + // Extensions + Extensions { + relay_chain: "rococo-local".into(), // You MUST set this to the correct network! + para_id: CONTRACTS_PARACHAIN_ID, + }, + ) +} + +pub fn contracts_rococo_config() -> ContractsRococoChainSpec { + // Give your base currency a unit name and decimal places + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("tokenSymbol".into(), "ROC".into()); + properties.insert("tokenDecimals".into(), 12.into()); + + ContractsRococoChainSpec::from_genesis( + // Name + "Contracts on Rococo", + // ID + "contracts-rococo", + ChainType::Live, + move || { + contracts_rococo_genesis( + vec![ + // 5GKFbTTgrVS4Vz1UWWHPqMZQNFWZtqo7H2KpCDyYhEL3aS26 + ( + hex!["bc09354c12c054c8f6b3da208485eacec4ac648bad348895273b37bab5a0937c"] + .into(), + hex!["bc09354c12c054c8f6b3da208485eacec4ac648bad348895273b37bab5a0937c"] + .unchecked_into(), + ), + // 5EPRJHm2GpABVWcwnAujcrhnrjFZyDGd5TwKFzkBoGgdRyv2 + ( + hex!["66be63b7bcbfb91040e5248e2d1ceb822cf219c57848c5924ffa3a1f8e67ba72"] + .into(), + hex!["66be63b7bcbfb91040e5248e2d1ceb822cf219c57848c5924ffa3a1f8e67ba72"] + .unchecked_into(), + ), + // 5GH62vrJrVZxLREcHzm2PR5uTLAT5RQMJitoztCGyaP4o3uM + ( + hex!["ba62886472a0a9f66b5e39f1469ce1c5b3d8cad6be39078daf16f111e89d1e44"] + .into(), + hex!["ba62886472a0a9f66b5e39f1469ce1c5b3d8cad6be39078daf16f111e89d1e44"] + .unchecked_into(), + ), + // 5FHfoJDLdjRYX5KXLRqMDYBbWrwHLMtti21uK4QByUoUAbJF + ( + hex!["8e97f65cda001976311df9bed39e8d0c956089093e94a75ef76fe9347a0eda7b"] + .into(), + hex!["8e97f65cda001976311df9bed39e8d0c956089093e94a75ef76fe9347a0eda7b"] + .unchecked_into(), + ), + ], + // Warning: The configuration for a production chain should not contain + // any endowed accounts here, otherwise it'll be minting extra native tokens + // from the relay chain on the parachain. + vec![ + // NOTE: Remove endowed accounts if deployed on other relay chains. + // Endowed accounts + hex!["baa78c7154c7f82d6d377177e20bcab65d327eca0086513f9964f5a0f6bdad56"].into(), + // AccountId of an account which `ink-waterfall` uses for automated testing + hex!["0e47e2344d523c3cc5c34394b0d58b9a4200e813a038e6c5a6163cc07d70b069"].into(), + ], + CONTRACTS_PARACHAIN_ID.into(), + ) + }, + // Bootnodes + vec![ + "/dns/contracts-collator-0.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWKg3Rpxcr9oJ8n6khoxpGKWztCZydtUZk2cojHqnfLrpj" + .parse() + .expect("MultiaddrWithPeerId"), + "/dns/contracts-collator-1.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWPEXYrz8tHU3nDtPoPw4V7ou5dzMEWSTuUj7vaWiYVAVh" + .parse() + .expect("MultiaddrWithPeerId"), + "/dns/contracts-collator-2.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWEVU8AFNary4nP4qEnEcwJaRuy59Wefekzdu9pKbnVEhk" + .parse() + .expect("MultiaddrWithPeerId"), + "/dns/contracts-collator-3.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWP6pV3ZmcXzGDjv8ZMgA6nZxfAKDxSz4VNiLx6vVCQgJX" + .parse() + .expect("MultiaddrWithPeerId"), + ], + // Telemetry + None, + // Protocol ID + None, + // Fork ID + None, + // Properties + Some(properties), + // Extensions + Extensions { relay_chain: "rococo".into(), para_id: CONTRACTS_PARACHAIN_ID }, + ) +} + +fn contracts_rococo_genesis( + invulnerables: Vec<(AccountId, AuraId)>, + endowed_accounts: Vec, + id: ParaId, +) -> contracts_rococo_runtime::GenesisConfig { + contracts_rococo_runtime::GenesisConfig { + system: contracts_rococo_runtime::SystemConfig { + code: contracts_rococo_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!") + .to_vec(), + }, + balances: contracts_rococo_runtime::BalancesConfig { + balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), + }, + parachain_info: contracts_rococo_runtime::ParachainInfoConfig { parachain_id: id }, + collator_selection: contracts_rococo_runtime::CollatorSelectionConfig { + invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), + candidacy_bond: CONTRACTS_ROCOCO_ED * 16, + ..Default::default() + }, + session: contracts_rococo_runtime::SessionConfig { + keys: invulnerables + .into_iter() + .map(|(acc, aura)| { + ( + acc.clone(), // account id + acc, // validator id + contracts_rococo_runtime::SessionKeys { aura }, // session keys + ) + }) + .collect(), + }, + // no need to pass anything to aura, in fact it will panic if we do. Session will take care + // of this. + aura: Default::default(), + aura_ext: Default::default(), + parachain_system: Default::default(), + polkadot_xcm: contracts_rococo_runtime::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + }, + sudo: contracts_rococo_runtime::SudoConfig { + key: Some( + hex!["2681a28014e7d3a5bfb32a003b3571f53c408acbc28d351d6bf58f5028c4ef14"].into(), + ), + }, + } +} diff --git a/cumulus/polkadot-parachain/src/chain_spec/mod.rs b/cumulus/polkadot-parachain/src/chain_spec/mod.rs new file mode 100644 index 0000000000..f5e442f5e2 --- /dev/null +++ b/cumulus/polkadot-parachain/src/chain_spec/mod.rs @@ -0,0 +1,176 @@ +// Copyright 2019-2021 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + +use cumulus_primitives_core::ParaId; +use hex_literal::hex; +use rococo_parachain_runtime::{AccountId, AuraId, Signature}; +use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup}; +use sc_service::ChainType; +use serde::{Deserialize, Serialize}; +use sp_core::{crypto::UncheckedInto, sr25519, Pair, Public}; +use sp_runtime::traits::{IdentifyAccount, Verify}; + +pub mod contracts; +pub mod seedling; +pub mod shell; +pub mod statemint; + +/// Specialized `ChainSpec` for the normal parachain runtime. +pub type ChainSpec = + sc_service::GenericChainSpec; + +/// The default XCM version to set in genesis config. +const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; + +/// Helper function to generate a crypto pair from seed +pub fn get_from_seed(seed: &str) -> ::Public { + TPublic::Pair::from_string(&format!("//{}", seed), None) + .expect("static values are valid; qed") + .public() +} + +/// The extensions for the [`ChainSpec`]. +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)] +#[serde(deny_unknown_fields)] +pub struct Extensions { + /// The relay chain of the Parachain. + pub relay_chain: String, + /// The id of the Parachain. + pub para_id: u32, +} + +impl Extensions { + /// Try to get the extension from the given `ChainSpec`. + pub fn try_get(chain_spec: &dyn sc_service::ChainSpec) -> Option<&Self> { + sc_chain_spec::get_extension(chain_spec.extensions()) + } +} + +type AccountPublic = ::Signer; + +/// Helper function to generate an account ID from seed +pub fn get_account_id_from_seed(seed: &str) -> AccountId +where + AccountPublic: From<::Public>, +{ + AccountPublic::from(get_from_seed::(seed)).into_account() +} + +pub fn get_chain_spec() -> ChainSpec { + ChainSpec::from_genesis( + "Local Testnet", + "local_testnet", + ChainType::Local, + move || { + testnet_genesis( + get_account_id_from_seed::("Alice"), + vec![get_from_seed::("Alice"), get_from_seed::("Bob")], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + 1000.into(), + ) + }, + Vec::new(), + None, + None, + None, + None, + Extensions { relay_chain: "westend".into(), para_id: 1000 }, + ) +} + +pub fn staging_test_net() -> ChainSpec { + ChainSpec::from_genesis( + "Staging Testnet", + "staging_testnet", + ChainType::Live, + move || { + testnet_genesis( + hex!["9ed7705e3c7da027ba0583a22a3212042f7e715d3c168ba14f1424e2bc111d00"].into(), + vec![ + // $secret//one + hex!["aad9fa2249f87a210a0f93400b7f90e47b810c6d65caa0ca3f5af982904c2a33"] + .unchecked_into(), + // $secret//two + hex!["d47753f0cca9dd8da00c70e82ec4fc5501a69c49a5952a643d18802837c88212"] + .unchecked_into(), + ], + vec![ + hex!["9ed7705e3c7da027ba0583a22a3212042f7e715d3c168ba14f1424e2bc111d00"].into() + ], + 1000.into(), + ) + }, + Vec::new(), + None, + None, + None, + None, + Extensions { relay_chain: "westend".into(), para_id: 1000 }, + ) +} + +fn testnet_genesis( + root_key: AccountId, + initial_authorities: Vec, + endowed_accounts: Vec, + id: ParaId, +) -> rococo_parachain_runtime::GenesisConfig { + rococo_parachain_runtime::GenesisConfig { + system: rococo_parachain_runtime::SystemConfig { + code: rococo_parachain_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!") + .to_vec(), + }, + balances: rococo_parachain_runtime::BalancesConfig { + balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), + }, + sudo: rococo_parachain_runtime::SudoConfig { key: Some(root_key) }, + parachain_info: rococo_parachain_runtime::ParachainInfoConfig { parachain_id: id }, + aura: rococo_parachain_runtime::AuraConfig { authorities: initial_authorities }, + aura_ext: Default::default(), + parachain_system: Default::default(), + polkadot_xcm: rococo_parachain_runtime::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + }, + } +} + +/// Helper function to generate a crypto pair from seed +pub fn get_public_from_seed(seed: &str) -> ::Public { + TPublic::Pair::from_string(&format!("//{}", seed), None) + .expect("static values are valid; qed") + .public() +} + +/// Generate collator keys from seed. +/// +/// This function's return type must always match the session keys of the chain in tuple format. +pub fn get_collator_keys_from_seed(seed: &str) -> ::Public { + get_public_from_seed::(seed) +} diff --git a/cumulus/polkadot-parachain/src/chain_spec/seedling.rs b/cumulus/polkadot-parachain/src/chain_spec/seedling.rs new file mode 100644 index 0000000000..75166a1b8f --- /dev/null +++ b/cumulus/polkadot-parachain/src/chain_spec/seedling.rs @@ -0,0 +1,61 @@ +// Copyright 2019-2021 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + +use crate::chain_spec::{get_account_id_from_seed, Extensions}; +use cumulus_primitives_core::ParaId; +use rococo_parachain_runtime::AccountId; +use sc_service::ChainType; +use sp_core::sr25519; + +/// Specialized `ChainSpec` for the seedling parachain runtime. +pub type SeedlingChainSpec = + sc_service::GenericChainSpec; + +pub fn get_seedling_chain_spec() -> SeedlingChainSpec { + SeedlingChainSpec::from_genesis( + "Seedling Local Testnet", + "seedling_local_testnet", + ChainType::Local, + move || { + seedling_testnet_genesis( + get_account_id_from_seed::("Alice"), + 2000.into(), + ) + }, + Vec::new(), + None, + None, + None, + None, + Extensions { relay_chain: "westend".into(), para_id: 2000 }, + ) +} + +fn seedling_testnet_genesis( + root_key: AccountId, + parachain_id: ParaId, +) -> seedling_runtime::GenesisConfig { + seedling_runtime::GenesisConfig { + system: seedling_runtime::SystemConfig { + code: seedling_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!") + .to_vec(), + }, + sudo: seedling_runtime::SudoConfig { key: Some(root_key) }, + parachain_info: seedling_runtime::ParachainInfoConfig { parachain_id }, + parachain_system: Default::default(), + } +} diff --git a/cumulus/polkadot-parachain/src/chain_spec/shell.rs b/cumulus/polkadot-parachain/src/chain_spec/shell.rs new file mode 100644 index 0000000000..bab4ee73fd --- /dev/null +++ b/cumulus/polkadot-parachain/src/chain_spec/shell.rs @@ -0,0 +1,49 @@ +// Copyright 2019-2021 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + +use crate::chain_spec::Extensions; +use cumulus_primitives_core::ParaId; +use sc_service::ChainType; + +/// Specialized `ChainSpec` for the shell parachain runtime. +pub type ShellChainSpec = sc_service::GenericChainSpec; + +pub fn get_shell_chain_spec() -> ShellChainSpec { + ShellChainSpec::from_genesis( + "Shell Local Testnet", + "shell_local_testnet", + ChainType::Local, + move || shell_testnet_genesis(1000.into()), + Vec::new(), + None, + None, + None, + None, + Extensions { relay_chain: "westend".into(), para_id: 1000 }, + ) +} + +fn shell_testnet_genesis(parachain_id: ParaId) -> shell_runtime::GenesisConfig { + shell_runtime::GenesisConfig { + system: shell_runtime::SystemConfig { + code: shell_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!") + .to_vec(), + }, + parachain_info: shell_runtime::ParachainInfoConfig { parachain_id }, + parachain_system: Default::default(), + } +} diff --git a/cumulus/polkadot-parachain/src/chain_spec.rs b/cumulus/polkadot-parachain/src/chain_spec/statemint.rs similarity index 54% rename from cumulus/polkadot-parachain/src/chain_spec.rs rename to cumulus/polkadot-parachain/src/chain_spec/statemint.rs index 421e571a02..c8978b23a8 100644 --- a/cumulus/polkadot-parachain/src/chain_spec.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/statemint.rs @@ -14,219 +14,15 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . +use crate::chain_spec::{ + get_account_id_from_seed, get_collator_keys_from_seed, Extensions, SAFE_XCM_VERSION, +}; use cumulus_primitives_core::ParaId; use hex_literal::hex; -use rococo_parachain_runtime::{AccountId, AuraId, Signature}; -use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup}; -use sc_service::ChainType; -use serde::{Deserialize, Serialize}; -use sp_core::{crypto::UncheckedInto, sr25519, Pair, Public}; -use sp_runtime::traits::{IdentifyAccount, Verify}; - -/// Specialized `ChainSpec` for the normal parachain runtime. -pub type ChainSpec = - sc_service::GenericChainSpec; - -/// Specialized `ChainSpec` for the shell parachain runtime. -pub type ShellChainSpec = sc_service::GenericChainSpec; - -/// Specialized `ChainSpec` for the seedling parachain runtime. -pub type SeedlingChainSpec = - sc_service::GenericChainSpec; - -/// The default XCM version to set in genesis config. -const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; - -/// Helper function to generate a crypto pair from seed -pub fn get_from_seed(seed: &str) -> ::Public { - TPublic::Pair::from_string(&format!("//{}", seed), None) - .expect("static values are valid; qed") - .public() -} - -/// The extensions for the [`ChainSpec`]. -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)] -#[serde(deny_unknown_fields)] -pub struct Extensions { - /// The relay chain of the Parachain. - pub relay_chain: String, - /// The id of the Parachain. - pub para_id: u32, -} - -impl Extensions { - /// Try to get the extension from the given `ChainSpec`. - pub fn try_get(chain_spec: &dyn sc_service::ChainSpec) -> Option<&Self> { - sc_chain_spec::get_extension(chain_spec.extensions()) - } -} - -type AccountPublic = ::Signer; - -/// Helper function to generate an account ID from seed -pub fn get_account_id_from_seed(seed: &str) -> AccountId -where - AccountPublic: From<::Public>, -{ - AccountPublic::from(get_from_seed::(seed)).into_account() -} - -pub fn get_chain_spec() -> ChainSpec { - ChainSpec::from_genesis( - "Local Testnet", - "local_testnet", - ChainType::Local, - move || { - testnet_genesis( - get_account_id_from_seed::("Alice"), - vec![get_from_seed::("Alice"), get_from_seed::("Bob")], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - 1000.into(), - ) - }, - Vec::new(), - None, - None, - None, - None, - Extensions { relay_chain: "westend".into(), para_id: 1000 }, - ) -} - -pub fn get_shell_chain_spec() -> ShellChainSpec { - ShellChainSpec::from_genesis( - "Shell Local Testnet", - "shell_local_testnet", - ChainType::Local, - move || shell_testnet_genesis(1000.into()), - Vec::new(), - None, - None, - None, - None, - Extensions { relay_chain: "westend".into(), para_id: 1000 }, - ) -} - -pub fn get_seedling_chain_spec() -> SeedlingChainSpec { - SeedlingChainSpec::from_genesis( - "Seedling Local Testnet", - "seedling_local_testnet", - ChainType::Local, - move || { - seedling_testnet_genesis( - get_account_id_from_seed::("Alice"), - 2000.into(), - ) - }, - Vec::new(), - None, - None, - None, - None, - Extensions { relay_chain: "westend".into(), para_id: 2000 }, - ) -} - -pub fn staging_test_net() -> ChainSpec { - ChainSpec::from_genesis( - "Staging Testnet", - "staging_testnet", - ChainType::Live, - move || { - testnet_genesis( - hex!["9ed7705e3c7da027ba0583a22a3212042f7e715d3c168ba14f1424e2bc111d00"].into(), - vec![ - // $secret//one - hex!["aad9fa2249f87a210a0f93400b7f90e47b810c6d65caa0ca3f5af982904c2a33"] - .unchecked_into(), - // $secret//two - hex!["d47753f0cca9dd8da00c70e82ec4fc5501a69c49a5952a643d18802837c88212"] - .unchecked_into(), - ], - vec![ - hex!["9ed7705e3c7da027ba0583a22a3212042f7e715d3c168ba14f1424e2bc111d00"].into() - ], - 1000.into(), - ) - }, - Vec::new(), - None, - None, - None, - None, - Extensions { relay_chain: "westend".into(), para_id: 1000 }, - ) -} - -fn testnet_genesis( - root_key: AccountId, - initial_authorities: Vec, - endowed_accounts: Vec, - id: ParaId, -) -> rococo_parachain_runtime::GenesisConfig { - rococo_parachain_runtime::GenesisConfig { - system: rococo_parachain_runtime::SystemConfig { - code: rococo_parachain_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - }, - balances: rococo_parachain_runtime::BalancesConfig { - balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), - }, - sudo: rococo_parachain_runtime::SudoConfig { key: Some(root_key) }, - parachain_info: rococo_parachain_runtime::ParachainInfoConfig { parachain_id: id }, - aura: rococo_parachain_runtime::AuraConfig { authorities: initial_authorities }, - aura_ext: Default::default(), - parachain_system: Default::default(), - polkadot_xcm: rococo_parachain_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - }, - } -} - -fn shell_testnet_genesis(parachain_id: ParaId) -> shell_runtime::GenesisConfig { - shell_runtime::GenesisConfig { - system: shell_runtime::SystemConfig { - code: shell_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - }, - parachain_info: shell_runtime::ParachainInfoConfig { parachain_id }, - parachain_system: Default::default(), - } -} - -fn seedling_testnet_genesis( - root_key: AccountId, - parachain_id: ParaId, -) -> seedling_runtime::GenesisConfig { - seedling_runtime::GenesisConfig { - system: seedling_runtime::SystemConfig { - code: seedling_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - }, - sudo: seedling_runtime::SudoConfig { key: Some(root_key) }, - parachain_info: seedling_runtime::ParachainInfoConfig { parachain_id }, - parachain_system: Default::default(), - } -} - use parachains_common::{Balance as StatemintBalance, StatemintAuraId}; +use rococo_parachain_runtime::{AccountId, AuraId}; +use sc_service::ChainType; +use sp_core::{crypto::UncheckedInto, sr25519}; /// Specialized `ChainSpec` for the normal parachain runtime. pub type StatemintChainSpec = @@ -240,20 +36,6 @@ const STATEMINT_ED: StatemintBalance = statemint_runtime::constants::currency::E const STATEMINE_ED: StatemintBalance = statemine_runtime::constants::currency::EXISTENTIAL_DEPOSIT; const WESTMINT_ED: StatemintBalance = westmint_runtime::constants::currency::EXISTENTIAL_DEPOSIT; -/// Helper function to generate a crypto pair from seed -pub fn get_public_from_seed(seed: &str) -> ::Public { - TPublic::Pair::from_string(&format!("//{}", seed), None) - .expect("static values are valid; qed") - .public() -} - -/// Generate collator keys from seed. -/// -/// This function's return type must always match the session keys of the chain in tuple format. -pub fn get_collator_keys_from_seed(seed: &str) -> ::Public { - get_public_from_seed::(seed) -} - /// Generate the session keys from individual elements. /// /// The input must be a tuple of individual keys (a single arg for now since we have just one key). @@ -834,258 +616,3 @@ fn westmint_genesis( }, } } - -pub type ContractsRococoChainSpec = - sc_service::GenericChainSpec; - -/// No relay chain suffix because the id is the same over all relay chains. -const CONTRACTS_PARACHAIN_ID: u32 = 1002; - -/// The existential deposit is determined by the runtime "contracts-rococo". -const CONTRACTS_ROCOCO_ED: contracts_rococo_runtime::Balance = - contracts_rococo_runtime::constants::currency::EXISTENTIAL_DEPOSIT; - -pub fn contracts_rococo_development_config() -> ContractsRococoChainSpec { - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("tokenSymbol".into(), "ROC".into()); - properties.insert("tokenDecimals".into(), 12.into()); - - ContractsRococoChainSpec::from_genesis( - // Name - "Contracts on Rococo Development", - // ID - "contracts-rococo-dev", - ChainType::Development, - move || { - contracts_rococo_genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - CONTRACTS_PARACHAIN_ID.into(), - ) - }, - Vec::new(), - None, - None, - None, - None, - Extensions { - relay_chain: "rococo-local".into(), // You MUST set this to the correct network! - para_id: CONTRACTS_PARACHAIN_ID, - }, - ) -} - -pub fn contracts_rococo_local_config() -> ContractsRococoChainSpec { - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("tokenSymbol".into(), "ROC".into()); - properties.insert("tokenDecimals".into(), 12.into()); - - ContractsRococoChainSpec::from_genesis( - // Name - "Contracts on Rococo", - // ID - "contracts-rococo-local", - ChainType::Local, - move || { - contracts_rococo_genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - CONTRACTS_PARACHAIN_ID.into(), - ) - }, - // Bootnodes - Vec::new(), - // Telemetry - None, - // Protocol ID - None, - // Fork ID - None, - // Properties - Some(properties), - // Extensions - Extensions { - relay_chain: "rococo-local".into(), // You MUST set this to the correct network! - para_id: CONTRACTS_PARACHAIN_ID, - }, - ) -} - -pub fn contracts_rococo_config() -> ContractsRococoChainSpec { - // Give your base currency a unit name and decimal places - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("tokenSymbol".into(), "ROC".into()); - properties.insert("tokenDecimals".into(), 12.into()); - - ContractsRococoChainSpec::from_genesis( - // Name - "Contracts on Rococo", - // ID - "contracts-rococo", - ChainType::Live, - move || { - contracts_rococo_genesis( - vec![ - // 5GKFbTTgrVS4Vz1UWWHPqMZQNFWZtqo7H2KpCDyYhEL3aS26 - ( - hex!["bc09354c12c054c8f6b3da208485eacec4ac648bad348895273b37bab5a0937c"] - .into(), - hex!["bc09354c12c054c8f6b3da208485eacec4ac648bad348895273b37bab5a0937c"] - .unchecked_into(), - ), - // 5EPRJHm2GpABVWcwnAujcrhnrjFZyDGd5TwKFzkBoGgdRyv2 - ( - hex!["66be63b7bcbfb91040e5248e2d1ceb822cf219c57848c5924ffa3a1f8e67ba72"] - .into(), - hex!["66be63b7bcbfb91040e5248e2d1ceb822cf219c57848c5924ffa3a1f8e67ba72"] - .unchecked_into(), - ), - // 5GH62vrJrVZxLREcHzm2PR5uTLAT5RQMJitoztCGyaP4o3uM - ( - hex!["ba62886472a0a9f66b5e39f1469ce1c5b3d8cad6be39078daf16f111e89d1e44"] - .into(), - hex!["ba62886472a0a9f66b5e39f1469ce1c5b3d8cad6be39078daf16f111e89d1e44"] - .unchecked_into(), - ), - // 5FHfoJDLdjRYX5KXLRqMDYBbWrwHLMtti21uK4QByUoUAbJF - ( - hex!["8e97f65cda001976311df9bed39e8d0c956089093e94a75ef76fe9347a0eda7b"] - .into(), - hex!["8e97f65cda001976311df9bed39e8d0c956089093e94a75ef76fe9347a0eda7b"] - .unchecked_into(), - ), - ], - // Warning: The configuration for a production chain should not contain - // any endowed accounts here, otherwise it'll be minting extra native tokens - // from the relay chain on the parachain. - vec![ - // NOTE: Remove endowed accounts if deployed on other relay chains. - // Endowed accounts - hex!["baa78c7154c7f82d6d377177e20bcab65d327eca0086513f9964f5a0f6bdad56"].into(), - // AccountId of an account which `ink-waterfall` uses for automated testing - hex!["0e47e2344d523c3cc5c34394b0d58b9a4200e813a038e6c5a6163cc07d70b069"].into(), - ], - CONTRACTS_PARACHAIN_ID.into(), - ) - }, - // Bootnodes - vec![ - "/dns/contracts-collator-0.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWKg3Rpxcr9oJ8n6khoxpGKWztCZydtUZk2cojHqnfLrpj" - .parse() - .expect("MultiaddrWithPeerId"), - "/dns/contracts-collator-1.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWPEXYrz8tHU3nDtPoPw4V7ou5dzMEWSTuUj7vaWiYVAVh" - .parse() - .expect("MultiaddrWithPeerId"), - "/dns/contracts-collator-2.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWEVU8AFNary4nP4qEnEcwJaRuy59Wefekzdu9pKbnVEhk" - .parse() - .expect("MultiaddrWithPeerId"), - "/dns/contracts-collator-3.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWP6pV3ZmcXzGDjv8ZMgA6nZxfAKDxSz4VNiLx6vVCQgJX" - .parse() - .expect("MultiaddrWithPeerId"), - ], - // Telemetry - None, - // Protocol ID - None, - // Fork ID - None, - // Properties - Some(properties), - // Extensions - Extensions { relay_chain: "rococo".into(), para_id: CONTRACTS_PARACHAIN_ID }, - ) -} - -fn contracts_rococo_genesis( - invulnerables: Vec<(AccountId, AuraId)>, - endowed_accounts: Vec, - id: ParaId, -) -> contracts_rococo_runtime::GenesisConfig { - contracts_rococo_runtime::GenesisConfig { - system: contracts_rococo_runtime::SystemConfig { - code: contracts_rococo_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - }, - balances: contracts_rococo_runtime::BalancesConfig { - balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), - }, - parachain_info: contracts_rococo_runtime::ParachainInfoConfig { parachain_id: id }, - collator_selection: contracts_rococo_runtime::CollatorSelectionConfig { - invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), - candidacy_bond: CONTRACTS_ROCOCO_ED * 16, - ..Default::default() - }, - session: contracts_rococo_runtime::SessionConfig { - keys: invulnerables - .into_iter() - .map(|(acc, aura)| { - ( - acc.clone(), // account id - acc, // validator id - contracts_rococo_runtime::SessionKeys { aura }, // session keys - ) - }) - .collect(), - }, - // no need to pass anything to aura, in fact it will panic if we do. Session will take care - // of this. - aura: Default::default(), - aura_ext: Default::default(), - parachain_system: Default::default(), - polkadot_xcm: contracts_rococo_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - }, - sudo: contracts_rococo_runtime::SudoConfig { - key: Some( - hex!["2681a28014e7d3a5bfb32a003b3571f53c408acbc28d351d6bf58f5028c4ef14"].into(), - ), - }, - } -} diff --git a/cumulus/polkadot-parachain/src/command.rs b/cumulus/polkadot-parachain/src/command.rs index daf24797b5..37dd42b0eb 100644 --- a/cumulus/polkadot-parachain/src/command.rs +++ b/cumulus/polkadot-parachain/src/command.rs @@ -40,54 +40,51 @@ use sp_core::hexdisplay::HexDisplay; use sp_runtime::traits::{AccountIdConversion, Block as BlockT}; use std::{io::Write, net::SocketAddr}; -trait IdentifyChain { - fn is_shell(&self) -> bool; - fn is_seedling(&self) -> bool; - fn is_statemint(&self) -> bool; - fn is_statemine(&self) -> bool; - fn is_westmint(&self) -> bool; - fn is_contracts_rococo(&self) -> bool; +enum Runtime { + /// This is the default runtime (based on rococo) + Generic, + Shell, + Seedling, + Statemint, + Statemine, + Westmint, + ContractsRococo, } -impl IdentifyChain for dyn sc_service::ChainSpec { - fn is_shell(&self) -> bool { - self.id().starts_with("shell") - } - fn is_seedling(&self) -> bool { - self.id().starts_with("seedling") - } - fn is_statemint(&self) -> bool { - self.id().starts_with("statemint") - } - fn is_statemine(&self) -> bool { - self.id().starts_with("statemine") - } - fn is_westmint(&self) -> bool { - self.id().starts_with("westmint") - } - fn is_contracts_rococo(&self) -> bool { - self.id().starts_with("contracts-rococo") +trait ChainType { + fn runtime(&self) -> Runtime; +} + +impl ChainType for dyn ChainSpec { + fn runtime(&self) -> Runtime { + runtime(self.id()) } } -impl IdentifyChain for T { - fn is_shell(&self) -> bool { - ::is_shell(self) +use sc_chain_spec::GenericChainSpec; +impl ChainType + for GenericChainSpec +{ + fn runtime(&self) -> Runtime { + runtime(self.id()) } - fn is_seedling(&self) -> bool { - ::is_seedling(self) - } - fn is_statemint(&self) -> bool { - ::is_statemint(self) - } - fn is_statemine(&self) -> bool { - ::is_statemine(self) - } - fn is_westmint(&self) -> bool { - ::is_westmint(self) - } - fn is_contracts_rococo(&self) -> bool { - ::is_contracts_rococo(self) +} + +fn runtime(id: &str) -> Runtime { + if id.starts_with("shell") { + Runtime::Shell + } else if id.starts_with("seedling") { + Runtime::Seedling + } else if id.starts_with("statemint") { + Runtime::Statemint + } else if id.starts_with("statemine") { + Runtime::Statemine + } else if id.starts_with("westmint") { + Runtime::Westmint + } else if id.starts_with("contracts-rococo") { + Runtime::ContractsRococo + } else { + Runtime::Generic } } @@ -103,39 +100,41 @@ fn load_spec(id: &str) -> std::result::Result, St "track" => Box::new(chain_spec::ChainSpec::from_json_bytes( &include_bytes!("../../parachains/chain-specs/track.json")[..], )?), - "shell" => Box::new(chain_spec::get_shell_chain_spec()), + "shell" => Box::new(chain_spec::shell::get_shell_chain_spec()), // -- Statemint - "seedling" => Box::new(chain_spec::get_seedling_chain_spec()), - "statemint-dev" => Box::new(chain_spec::statemint_development_config()), - "statemint-local" => Box::new(chain_spec::statemint_local_config()), + "seedling" => Box::new(chain_spec::seedling::get_seedling_chain_spec()), + "statemint-dev" => Box::new(chain_spec::statemint::statemint_development_config()), + "statemint-local" => Box::new(chain_spec::statemint::statemint_local_config()), // the chain spec as used for generating the upgrade genesis values - "statemint-genesis" => Box::new(chain_spec::statemint_config()), + "statemint-genesis" => Box::new(chain_spec::statemint::statemint_config()), // the shell-based chain spec as used for syncing "statemint" => Box::new(chain_spec::ChainSpec::from_json_bytes( &include_bytes!("../../parachains/chain-specs/statemint.json")[..], )?), // -- Statemine - "statemine-dev" => Box::new(chain_spec::statemine_development_config()), - "statemine-local" => Box::new(chain_spec::statemine_local_config()), + "statemine-dev" => Box::new(chain_spec::statemint::statemine_development_config()), + "statemine-local" => Box::new(chain_spec::statemint::statemine_local_config()), // the chain spec as used for generating the upgrade genesis values - "statemine-genesis" => Box::new(chain_spec::statemine_config()), + "statemine-genesis" => Box::new(chain_spec::statemint::statemine_config()), // the shell-based chain spec as used for syncing "statemine" => Box::new(chain_spec::ChainSpec::from_json_bytes( &include_bytes!("../../parachains/chain-specs/statemine.json")[..], )?), // -- Westmint - "westmint-dev" => Box::new(chain_spec::westmint_development_config()), - "westmint-local" => Box::new(chain_spec::westmint_local_config()), + "westmint-dev" => Box::new(chain_spec::statemint::westmint_development_config()), + "westmint-local" => Box::new(chain_spec::statemint::westmint_local_config()), // the chain spec as used for generating the upgrade genesis values - "westmint-genesis" => Box::new(chain_spec::westmint_config()), + "westmint-genesis" => Box::new(chain_spec::statemint::westmint_config()), // the shell-based chain spec as used for syncing "westmint" => Box::new(chain_spec::ChainSpec::from_json_bytes( &include_bytes!("../../parachains/chain-specs/westmint.json")[..], )?), // -- Contracts on Rococo - "contracts-rococo-dev" => Box::new(chain_spec::contracts_rococo_development_config()), - "contracts-rococo-local" => Box::new(chain_spec::contracts_rococo_local_config()), - "contracts-rococo-genesis" => Box::new(chain_spec::contracts_rococo_config()), + "contracts-rococo-dev" => + Box::new(chain_spec::contracts::contracts_rococo_development_config()), + "contracts-rococo-local" => + Box::new(chain_spec::contracts::contracts_rococo_local_config()), + "contracts-rococo-genesis" => Box::new(chain_spec::contracts::contracts_rococo_config()), "contracts-rococo" => Box::new(chain_spec::ChainSpec::from_json_bytes( &include_bytes!("../../parachains/chain-specs/contracts-rococo.json")[..], )?), @@ -144,20 +143,23 @@ fn load_spec(id: &str) -> std::result::Result, St // -- Loading a specific spec from disk path => { let chain_spec = chain_spec::ChainSpec::from_json_file(path.into())?; - if chain_spec.is_statemint() { - Box::new(chain_spec::StatemintChainSpec::from_json_file(path.into())?) - } else if chain_spec.is_statemine() { - Box::new(chain_spec::StatemineChainSpec::from_json_file(path.into())?) - } else if chain_spec.is_westmint() { - Box::new(chain_spec::WestmintChainSpec::from_json_file(path.into())?) - } else if chain_spec.is_shell() { - Box::new(chain_spec::ShellChainSpec::from_json_file(path.into())?) - } else if chain_spec.is_seedling() { - Box::new(chain_spec::SeedlingChainSpec::from_json_file(path.into())?) - } else if chain_spec.is_contracts_rococo() { - Box::new(chain_spec::ContractsRococoChainSpec::from_json_file(path.into())?) - } else { - Box::new(chain_spec) + match chain_spec.runtime() { + Runtime::Statemint => Box::new( + chain_spec::statemint::StatemintChainSpec::from_json_file(path.into())?, + ), + Runtime::Statemine => Box::new( + chain_spec::statemint::StatemineChainSpec::from_json_file(path.into())?, + ), + Runtime::Westmint => + Box::new(chain_spec::statemint::WestmintChainSpec::from_json_file(path.into())?), + Runtime::Shell => + Box::new(chain_spec::shell::ShellChainSpec::from_json_file(path.into())?), + Runtime::Seedling => + Box::new(chain_spec::seedling::SeedlingChainSpec::from_json_file(path.into())?), + Runtime::ContractsRococo => Box::new( + chain_spec::contracts::ContractsRococoChainSpec::from_json_file(path.into())?, + ), + Runtime::Generic => Box::new(chain_spec), } }, }) @@ -199,20 +201,14 @@ impl SubstrateCli for Cli { } fn native_runtime_version(chain_spec: &Box) -> &'static RuntimeVersion { - if chain_spec.is_statemint() { - &statemint_runtime::VERSION - } else if chain_spec.is_statemine() { - &statemine_runtime::VERSION - } else if chain_spec.is_westmint() { - &westmint_runtime::VERSION - } else if chain_spec.is_shell() { - &shell_runtime::VERSION - } else if chain_spec.is_seedling() { - &seedling_runtime::VERSION - } else if chain_spec.is_contracts_rococo() { - &contracts_rococo_runtime::VERSION - } else { - &rococo_parachain_runtime::VERSION + match chain_spec.runtime() { + Runtime::Statemint => &statemint_runtime::VERSION, + Runtime::Statemine => &statemine_runtime::VERSION, + Runtime::Westmint => &westmint_runtime::VERSION, + Runtime::Shell => &shell_runtime::VERSION, + Runtime::Seedling => &seedling_runtime::VERSION, + Runtime::ContractsRococo => &contracts_rococo_runtime::VERSION, + Runtime::Generic => &rococo_parachain_runtime::VERSION, } } } @@ -270,26 +266,29 @@ fn extract_genesis_wasm(chain_spec: &Box) -> Result { - if $config.chain_spec.is_statemine() { - let $partials = new_partial::( - &$config, - crate::service::statemint_build_import_queue::<_, AuraId>, - )?; - $code - } else if $config.chain_spec.is_westmint() { - let $partials = new_partial::( - &$config, - crate::service::statemint_build_import_queue::<_, AuraId>, - )?; - $code - } else if $config.chain_spec.is_statemint() { - let $partials = new_partial::( - &$config, - crate::service::statemint_build_import_queue::<_, StatemintAuraId>, - )?; - $code - } else { - Err("The chain is not supported".into()) + match $config.chain_spec.runtime() { + Runtime::Statemine => { + let $partials = new_partial::( + &$config, + crate::service::statemint_build_import_queue::<_, AuraId>, + )?; + $code + }, + Runtime::Westmint => { + let $partials = new_partial::( + &$config, + crate::service::statemint_build_import_queue::<_, AuraId>, + )?; + $code + }, + Runtime::Statemint => { + let $partials = new_partial::( + &$config, + crate::service::statemint_build_import_queue::<_, StatemintAuraId>, + )?; + $code + }, + _ => Err("The chain is not supported".into()), } }; } @@ -297,72 +296,80 @@ macro_rules! construct_benchmark_partials { macro_rules! construct_async_run { (|$components:ident, $cli:ident, $cmd:ident, $config:ident| $( $code:tt )* ) => {{ let runner = $cli.create_runner($cmd)?; - if runner.config().chain_spec.is_westmint() { - runner.async_run(|$config| { - let $components = new_partial::( - &$config, - crate::service::statemint_build_import_queue::<_, AuraId>, - )?; - let task_manager = $components.task_manager; - { $( $code )* }.map(|v| (v, task_manager)) - }) - } else if runner.config().chain_spec.is_statemine() { - runner.async_run(|$config| { - let $components = new_partial::( - &$config, - crate::service::statemint_build_import_queue::<_, AuraId>, - )?; - let task_manager = $components.task_manager; - { $( $code )* }.map(|v| (v, task_manager)) - }) - } else if runner.config().chain_spec.is_statemint() { - runner.async_run(|$config| { - let $components = new_partial::( - &$config, - crate::service::statemint_build_import_queue::<_, StatemintAuraId>, - )?; - let task_manager = $components.task_manager; - { $( $code )* }.map(|v| (v, task_manager)) - }) - } else if runner.config().chain_spec.is_shell() { - runner.async_run(|$config| { - let $components = new_partial::( - &$config, - crate::service::shell_build_import_queue, - )?; - let task_manager = $components.task_manager; - { $( $code )* }.map(|v| (v, task_manager)) - }) - } else if runner.config().chain_spec.is_seedling() { - runner.async_run(|$config| { - let $components = new_partial::( - &$config, - crate::service::shell_build_import_queue, - )?; - let task_manager = $components.task_manager; - { $( $code )* }.map(|v| (v, task_manager)) - }) - } else if runner.config().chain_spec.is_contracts_rococo() { - runner.async_run(|$config| { - let $components = new_partial::( - &$config, - crate::service::contracts_rococo_build_import_queue, - )?; - let task_manager = $components.task_manager; - { $( $code )* }.map(|v| (v, task_manager)) - }) - } else { - runner.async_run(|$config| { - let $components = new_partial::< - rococo_parachain_runtime::RuntimeApi, - _ - >( - &$config, - crate::service::rococo_parachain_build_import_queue, - )?; - let task_manager = $components.task_manager; - { $( $code )* }.map(|v| (v, task_manager)) - }) + match runner.config().chain_spec.runtime() { + Runtime::Westmint => { + runner.async_run(|$config| { + let $components = new_partial::( + &$config, + crate::service::statemint_build_import_queue::<_, AuraId>, + )?; + let task_manager = $components.task_manager; + { $( $code )* }.map(|v| (v, task_manager)) + }) + }, + Runtime::Statemine => { + runner.async_run(|$config| { + let $components = new_partial::( + &$config, + crate::service::statemint_build_import_queue::<_, AuraId>, + )?; + let task_manager = $components.task_manager; + { $( $code )* }.map(|v| (v, task_manager)) + }) + }, + Runtime::Statemint => { + runner.async_run(|$config| { + let $components = new_partial::( + &$config, + crate::service::statemint_build_import_queue::<_, StatemintAuraId>, + )?; + let task_manager = $components.task_manager; + { $( $code )* }.map(|v| (v, task_manager)) + }) + }, + Runtime::Shell => { + runner.async_run(|$config| { + let $components = new_partial::( + &$config, + crate::service::shell_build_import_queue, + )?; + let task_manager = $components.task_manager; + { $( $code )* }.map(|v| (v, task_manager)) + }) + }, + Runtime::Seedling => { + runner.async_run(|$config| { + let $components = new_partial::( + &$config, + crate::service::shell_build_import_queue, + )?; + let task_manager = $components.task_manager; + { $( $code )* }.map(|v| (v, task_manager)) + }) + }, + Runtime::ContractsRococo => { + runner.async_run(|$config| { + let $components = new_partial::( + &$config, + crate::service::contracts_rococo_build_import_queue, + )?; + let task_manager = $components.task_manager; + { $( $code )* }.map(|v| (v, task_manager)) + }) + }, + Runtime::Generic => { + runner.async_run(|$config| { + let $components = new_partial::< + rococo_parachain_runtime::RuntimeApi, + _ + >( + &$config, + crate::service::rococo_parachain_build_import_queue, + )?; + let task_manager = $components.task_manager; + { $( $code )* }.map(|v| (v, task_manager)) + }) + } } }} } @@ -472,16 +479,13 @@ pub fn run() -> Result<()> { match cmd { BenchmarkCmd::Pallet(cmd) => if cfg!(feature = "runtime-benchmarks") { - runner.sync_run(|config| { - if config.chain_spec.is_statemine() { - cmd.run::(config) - } else if config.chain_spec.is_westmint() { - cmd.run::(config) - } else if config.chain_spec.is_statemint() { - cmd.run::(config) - } else { - Err("Chain doesn't support benchmarking".into()) - } + runner.sync_run(|config| match config.chain_spec.runtime() { + Runtime::Statemine => + cmd.run::(config), + Runtime::Westmint => cmd.run::(config), + Runtime::Statemint => + cmd.run::(config), + _ => Err("Chain doesn't support benchmarking".into()), }) } else { Err("Benchmarking wasn't enabled when building the node. \ @@ -513,24 +517,20 @@ pub fn run() -> Result<()> { TaskManager::new(runner.config().tokio_handle.clone(), *registry) .map_err(|e| format!("Error: {:?}", e))?; - if runner.config().chain_spec.is_statemine() { - runner.async_run(|config| { + match runner.config().chain_spec.runtime() { + Runtime::Statemine => runner.async_run(|config| { Ok((cmd.run::(config), task_manager)) - }) - } else if runner.config().chain_spec.is_westmint() { - runner.async_run(|config| { + }), + Runtime::Westmint => runner.async_run(|config| { Ok((cmd.run::(config), task_manager)) - }) - } else if runner.config().chain_spec.is_statemint() { - runner.async_run(|config| { + }), + Runtime::Statemint => runner.async_run(|config| { Ok((cmd.run::(config), task_manager)) - }) - } else if runner.config().chain_spec.is_shell() { - runner.async_run(|config| { + }), + Runtime::Shell => runner.async_run(|config| { Ok((cmd.run::(config), task_manager)) - }) - } else { - Err("Chain doesn't support try-runtime".into()) + }), + _ => Err("Chain doesn't support try-runtime".into()), } } else { Err("Try-runtime must be enabled by `--features try-runtime`.".into()) @@ -584,16 +584,46 @@ pub fn run() -> Result<()> { info!("Parachain genesis state: {}", genesis_state); info!("Is collating: {}", if config.role.is_authority() { "yes" } else { "no" }); - if config.chain_spec.is_statemint() { - crate::service::start_statemint_node::< + match config.chain_spec.runtime() { + Runtime::Statemint => crate::service::start_statemint_node::< statemint_runtime::RuntimeApi, StatemintAuraId, >(config, polkadot_config, collator_options, id, hwbench) .await .map(|r| r.0) - .map_err(Into::into) - } else if config.chain_spec.is_statemine() { - crate::service::start_statemint_node::( + .map_err(Into::into), + Runtime::Statemine => crate::service::start_statemint_node::< + statemine_runtime::RuntimeApi, + AuraId, + >(config, polkadot_config, collator_options, id, hwbench) + .await + .map(|r| r.0) + .map_err(Into::into), + Runtime::Westmint => crate::service::start_statemint_node::< + westmint_runtime::RuntimeApi, + AuraId, + >(config, polkadot_config, collator_options, id, hwbench) + .await + .map(|r| r.0) + .map_err(Into::into), + Runtime::Shell => + crate::service::start_shell_node::( + config, + polkadot_config, + collator_options, + id, + hwbench, + ) + .await + .map(|r| r.0) + .map_err(Into::into), + Runtime::Seedling => crate::service::start_shell_node::< + seedling_runtime::RuntimeApi, + >(config, polkadot_config, collator_options, id, hwbench) + .await + .map(|r| r.0) + .map_err(Into::into), + Runtime::ContractsRococo => crate::service::start_contracts_rococo_node( config, polkadot_config, collator_options, @@ -602,9 +632,8 @@ pub fn run() -> Result<()> { ) .await .map(|r| r.0) - .map_err(Into::into) - } else if config.chain_spec.is_westmint() { - crate::service::start_statemint_node::( + .map_err(Into::into), + Runtime::Generic => crate::service::start_rococo_parachain_node( config, polkadot_config, collator_options, @@ -613,51 +642,7 @@ pub fn run() -> Result<()> { ) .await .map(|r| r.0) - .map_err(Into::into) - } else if config.chain_spec.is_shell() { - crate::service::start_shell_node::( - config, - polkadot_config, - collator_options, - id, - hwbench, - ) - .await - .map(|r| r.0) - .map_err(Into::into) - } else if config.chain_spec.is_seedling() { - crate::service::start_shell_node::( - config, - polkadot_config, - collator_options, - id, - hwbench, - ) - .await - .map(|r| r.0) - .map_err(Into::into) - } else if config.chain_spec.is_contracts_rococo() { - crate::service::start_contracts_rococo_node( - config, - polkadot_config, - collator_options, - id, - hwbench, - ) - .await - .map(|r| r.0) - .map_err(Into::into) - } else { - crate::service::start_rococo_parachain_node( - config, - polkadot_config, - collator_options, - id, - hwbench, - ) - .await - .map(|r| r.0) - .map_err(Into::into) + .map_err(Into::into), } }) },