diff --git a/crates/humanode-peer/src/chain_spec.rs b/crates/humanode-peer/src/chain_spec.rs index 9a23fb876..c44a5a9eb 100644 --- a/crates/humanode-peer/src/chain_spec.rs +++ b/crates/humanode-peer/src/chain_spec.rs @@ -5,6 +5,7 @@ use humanode_runtime::{ AccountId, AuraConfig, BalancesConfig, BioauthConfig, GenesisConfig, RobonodePublicKeyWrapper, Signature, SudoConfig, SystemConfig, WASM_BINARY, }; +use pallet_bioauth::StoredAuthTicket; use sc_service::ChainType; use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_runtime::{ @@ -55,49 +56,36 @@ pub fn local_testnet_config() -> Result { "local_testnet", ChainType::Local, move || { - GenesisConfig { - system: SystemConfig { - // Add Wasm runtime to storage. - code: wasm_binary.to_vec(), - changes_trie_config: Default::default(), - }, - balances: BalancesConfig { - // Configure endowed accounts with initial balance of 1 << 60. - balances: vec![ - ( - get_account_id_from_seed::("Alice"), - 1 << 60, - ), - ( - get_account_id_from_seed::("Alice//stash"), - 1 << 60, - ), - (get_account_id_from_seed::("Bob"), 1 << 60), - ( - get_account_id_from_seed::("Bob//stash"), - 1 << 60, - ), - ], - }, - aura: AuraConfig { - authorities: vec![ - authority_keys_from_seed("Alice"), - authority_keys_from_seed("Bob"), - ], - }, - sudo: SudoConfig { - // Assign network admin rights. - key: get_account_id_from_seed::("Alice"), - }, - bioauth: BioauthConfig { - // Add Alice AuraId to StoredAuthTickets for producing blocks - stored_auth_tickets: vec![pallet_bioauth::StoredAuthTicket { - public_key: authority_keys_from_seed("Alice").as_slice().to_vec(), - nonce: "1".as_bytes().to_vec(), - }], - robonode_public_key, - }, - } + testnet_genesis( + wasm_binary, + // Initial PoA authorities + vec![ + authority_keys_from_seed("Alice"), + authority_keys_from_seed("Bob"), + ], + // Sudo account + get_account_id_from_seed::("Alice"), + // Pre-funded accounts + 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"), + ], + vec![pallet_bioauth::StoredAuthTicket { + public_key: authority_keys_from_seed("Alice").as_slice().to_vec(), + nonce: "1".as_bytes().to_vec(), + }], + robonode_public_key, + ) }, // Bootnodes vec![], @@ -111,3 +99,90 @@ pub fn local_testnet_config() -> Result { None, )) } + +/// A configuration for dev. +pub fn development_config() -> Result { + let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?; + + let robonode_public_key = RobonodePublicKeyWrapper::from_bytes( + &hex!("5dde03934419252d13336e5a5881f5b1ef9ea47084538eb229f86349e7f394ab")[..], + ) + .map_err(|err| format!("{:?}", err))?; + + Ok(ChainSpec::from_genesis( + // Name + "Development", + // ID + "dev", + ChainType::Development, + move || { + testnet_genesis( + wasm_binary, + // Initial PoA authorities + vec![authority_keys_from_seed("Alice")], + // Sudo account + get_account_id_from_seed::("Alice"), + // Pre-funded accounts + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + ], + vec![pallet_bioauth::StoredAuthTicket { + public_key: authority_keys_from_seed("Alice").as_slice().to_vec(), + nonce: "1".as_bytes().to_vec(), + }], + robonode_public_key, + ) + }, + // Bootnodes + vec![], + // Telemetry + None, + // Protocol ID + None, + // Properties + None, + // Extensions + None, + )) +} + +/// Configure initial storage state for FRAME modules. +fn testnet_genesis( + wasm_binary: &[u8], + initial_authorities: Vec, + root_key: AccountId, + endowed_accounts: Vec, + stored_auth_tickets: Vec, + robonode_public_key: RobonodePublicKeyWrapper, +) -> GenesisConfig { + GenesisConfig { + system: SystemConfig { + // Add Wasm runtime to storage. + code: wasm_binary.to_vec(), + changes_trie_config: Default::default(), + }, + balances: BalancesConfig { + // Configure endowed accounts with initial balance of 1 << 60. + balances: endowed_accounts + .iter() + .cloned() + .map(|k| (k, 1 << 60)) + .collect(), + }, + aura: AuraConfig { + authorities: initial_authorities, + }, + sudo: SudoConfig { + // Assign network admin rights. + key: root_key, + }, + bioauth: BioauthConfig { + // Add Alice AuraId to StoredAuthTickets for producing blocks + stored_auth_tickets, + robonode_public_key, + }, + } +} diff --git a/crates/humanode-peer/src/cli/root.rs b/crates/humanode-peer/src/cli/root.rs index 151c6a327..7e006702a 100644 --- a/crates/humanode-peer/src/cli/root.rs +++ b/crates/humanode-peer/src/cli/root.rs @@ -45,14 +45,13 @@ impl SubstrateCli for Root { } fn load_spec(&self, id: &str) -> std::result::Result, String> { - if id != "local" && !id.is_empty() { - return Err(format!( - "chain {:?} is not supported, only {:?} is currently available", - id, "local" - )); - } - - Ok(Box::new(chain_spec::local_testnet_config()?)) + Ok(match id { + "dev" => Box::new(chain_spec::development_config()?), + "" | "local" => Box::new(chain_spec::local_testnet_config()?), + path => Box::new(chain_spec::ChainSpec::from_json_file( + std::path::PathBuf::from(path), + )?), + }) } fn native_runtime_version(_chain_spec: &Box) -> &'static RuntimeVersion {