// Copyright 2019 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::ParaId; use hex_literal::hex; use rococo_parachain_primitives::{AccountId, Signature}; use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup}; use sc_service::ChainType; use serde::{Deserialize, Serialize}; use sp_core::{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 contracts parachain runtime. pub type ContractsChainSpec = sc_service::GenericChainSpec; /// 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: &Box) -> 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(id: ParaId) -> ChainSpec { ChainSpec::from_genesis( "Local Testnet", "local_testnet", ChainType::Local, move || { testnet_genesis( get_account_id_from_seed::("Alice"), 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"), ], id, ) }, vec![], None, None, None, Extensions { relay_chain: "westend-dev".into(), para_id: id.into(), }, ) } pub fn get_contracts_chain_spec(id: ParaId) -> ContractsChainSpec { ContractsChainSpec::from_genesis( "Contracts Local Testnet", "contracts_local_testnet", ChainType::Local, move || { contracts_testnet_genesis( get_account_id_from_seed::("Alice"), 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"), ], id, ) }, vec![], None, None, None, Extensions { relay_chain: "westend-dev".into(), para_id: id.into(), }, ) } pub fn staging_test_net(id: ParaId) -> ChainSpec { ChainSpec::from_genesis( "Staging Testnet", "staging_testnet", ChainType::Live, move || { testnet_genesis( hex!["9ed7705e3c7da027ba0583a22a3212042f7e715d3c168ba14f1424e2bc111d00"].into(), vec![ hex!["9ed7705e3c7da027ba0583a22a3212042f7e715d3c168ba14f1424e2bc111d00"].into(), ], id, ) }, Vec::new(), None, None, None, Extensions { relay_chain: "westend-dev".into(), para_id: id.into(), }, ) } fn testnet_genesis( root_key: AccountId, endowed_accounts: Vec, id: ParaId, ) -> parachain_runtime::GenesisConfig { parachain_runtime::GenesisConfig { frame_system: Some(parachain_runtime::SystemConfig { code: parachain_runtime::WASM_BINARY .expect("WASM binary was not build, please build it!") .to_vec(), changes_trie_config: Default::default(), }), pallet_balances: Some(parachain_runtime::BalancesConfig { balances: endowed_accounts .iter() .cloned() .map(|k| (k, 1 << 60)) .collect(), }), pallet_sudo: Some(parachain_runtime::SudoConfig { key: root_key }), parachain_info: Some(parachain_runtime::ParachainInfoConfig { parachain_id: id }), } } fn contracts_testnet_genesis( root_key: AccountId, endowed_accounts: Vec, id: ParaId, ) -> parachain_contracts_runtime::GenesisConfig { parachain_contracts_runtime::GenesisConfig { frame_system: Some(parachain_contracts_runtime::SystemConfig { code: parachain_contracts_runtime::WASM_BINARY .expect("WASM binary was not build, please build it!") .to_vec(), changes_trie_config: Default::default(), }), pallet_balances: Some(parachain_contracts_runtime::BalancesConfig { balances: endowed_accounts .iter() .cloned() .map(|k| (k, 1 << 60)) .collect(), }), pallet_sudo: Some(parachain_contracts_runtime::SudoConfig { key: root_key }), parachain_info: Some(parachain_contracts_runtime::ParachainInfoConfig { parachain_id: id }), cumulus_pallet_contracts: None, } }