Reduce chain_spec and use more accurate naming

This commit is contained in:
Luke Parker
2022-10-21 21:14:33 -04:00
parent 422f7e3e2f
commit 4bfc8d7954

View File

@@ -1,24 +1,18 @@
use sc_service::ChainType;
use sp_runtime::traits::Verify;
use sp_core::{sr25519, Pair, Public};
use sp_runtime::traits::IdentifyAccount;
use sp_core::{Pair as PairTrait, sr25519::Pair};
use serai_runtime::{WASM_BINARY, AccountId, Signature, GenesisConfig, SystemConfig, BalancesConfig};
pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig>;
type AccountPublic = <Signature as Verify>::Signer;
fn get_from_seed<TPublic: Public>(seed: &'static str) -> <TPublic::Pair as Pair>::Public {
TPublic::Pair::from_string(&format!("//{}", seed), None).unwrap().public()
fn insecure_pair_from_name(name: &'static str) -> Pair {
Pair::from_string(&format!("//{}", name), None).unwrap()
}
fn get_account_id_from_seed<TPublic: Public>(seed: &'static str) -> AccountId
where
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
{
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
fn account_id_from_name(name: &'static str) -> AccountId {
insecure_pair_from_name(name).public()
}
fn testnet_genesis(wasm_binary: &[u8], endowed_accounts: Vec<AccountId>) -> GenesisConfig {
@@ -44,18 +38,18 @@ pub fn development_config() -> Result<ChainSpec, &'static str> {
testnet_genesis(
wasm_binary,
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
get_account_id_from_seed::<sr25519::Public>("Dave"),
get_account_id_from_seed::<sr25519::Public>("Eve"),
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
account_id_from_name("Alice"),
account_id_from_name("Bob"),
account_id_from_name("Charlie"),
account_id_from_name("Dave"),
account_id_from_name("Eve"),
account_id_from_name("Ferdie"),
account_id_from_name("Alice//stash"),
account_id_from_name("Bob//stash"),
account_id_from_name("Charlie//stash"),
account_id_from_name("Dave//stash"),
account_id_from_name("Eve//stash"),
account_id_from_name("Ferdie//stash"),
],
)
},