git.delta.rocks / unique-network / refs/commits / 623e2e26812b

difftreelog

source

node/src/chain_spec.rs3.7 KiBsourcehistory
1use sp_core::{Pair, Public, sr25519};2use node_template_runtime::{3	AccountId, AuraConfig, BalancesConfig, GenesisConfig, GrandpaConfig,4	SudoConfig, SystemConfig, WASM_BINARY, Signature5};6use sp_consensus_aura::sr25519::AuthorityId as AuraId;7use sp_finality_grandpa::AuthorityId as GrandpaId;8use sp_runtime::traits::{Verify, IdentifyAccount};9use sc_service::ChainType;1011// Note this is the URL for the telemetry server12//const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";1314/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.15pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig>;1617/// Helper function to generate a crypto pair from seed18pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {19	TPublic::Pair::from_string(&format!("//{}", seed), None)20		.expect("static values are valid; qed")21		.public()22}2324type AccountPublic = <Signature as Verify>::Signer;2526/// Helper function to generate an account ID from seed27pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId where28	AccountPublic: From<<TPublic::Pair as Pair>::Public>29{30	AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()31}3233/// Helper function to generate an authority key for Aura34pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) {35	(36		get_from_seed::<AuraId>(s),37		get_from_seed::<GrandpaId>(s),38	)39}4041pub fn development_config() -> ChainSpec {42	ChainSpec::from_genesis(43		"Development",44		"dev",45		ChainType::Development,46		|| testnet_genesis(47			vec![48				authority_keys_from_seed("Alice"),49			],50			get_account_id_from_seed::<sr25519::Public>("Alice"),51			vec![52				get_account_id_from_seed::<sr25519::Public>("Alice"),53				get_account_id_from_seed::<sr25519::Public>("Bob"),54				get_account_id_from_seed::<sr25519::Public>("Alice//stash"),55				get_account_id_from_seed::<sr25519::Public>("Bob//stash"),56			],57			true,58		),59		vec![],60		None,61		None,62		None,63		None,64	)65}6667pub fn local_testnet_config() -> ChainSpec {68	ChainSpec::from_genesis(69		"Local Testnet",70		"local_testnet",71		ChainType::Local,72		|| testnet_genesis(73			vec![74				authority_keys_from_seed("Alice"),75				authority_keys_from_seed("Bob"),76			],77			get_account_id_from_seed::<sr25519::Public>("Alice"),78			vec![79				get_account_id_from_seed::<sr25519::Public>("Alice"),80				get_account_id_from_seed::<sr25519::Public>("Bob"),81				get_account_id_from_seed::<sr25519::Public>("Charlie"),82				get_account_id_from_seed::<sr25519::Public>("Dave"),83				get_account_id_from_seed::<sr25519::Public>("Eve"),84				get_account_id_from_seed::<sr25519::Public>("Ferdie"),85				get_account_id_from_seed::<sr25519::Public>("Alice//stash"),86				get_account_id_from_seed::<sr25519::Public>("Bob//stash"),87				get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),88				get_account_id_from_seed::<sr25519::Public>("Dave//stash"),89				get_account_id_from_seed::<sr25519::Public>("Eve//stash"),90				get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),91			],92			true,93		),94		vec![],95		None,96		None,97		None,98		None,99	)100}101102fn testnet_genesis(initial_authorities: Vec<(AuraId, GrandpaId)>,103	root_key: AccountId,104	endowed_accounts: Vec<AccountId>,105	_enable_println: bool) -> GenesisConfig {106	GenesisConfig {107		system: Some(SystemConfig {108			code: WASM_BINARY.to_vec(),109			changes_trie_config: Default::default(),110		}),111		balances: Some(BalancesConfig {112			balances: endowed_accounts.iter().cloned().map(|k|(k, 1 << 60)).collect(),113		}),114		aura: Some(AuraConfig {115			authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(),116		}),117		grandpa: Some(GrandpaConfig {118			authorities: initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect(),119		}),120		sudo: Some(SudoConfig {121			key: root_key,122		}),123	}124}