use super::{
AccountId, AuraConfig, AuraId, BalancesConfig, ParachainInfoConfig, RuntimeGenesisConfig,
SudoConfig,
};
use alloc::{vec, vec::Vec};
use cumulus_primitives_core::ParaId;
use frame_support::build_struct_json_patch;
use sp_genesis_builder::PresetId;
use sp_keyring::Sr25519Keyring;
fn cumulus_test_runtime(
invulnerables: Vec<AuraId>,
endowed_accounts: Vec<AccountId>,
id: ParaId,
) -> serde_json::Value {
build_struct_json_patch!(RuntimeGenesisConfig {
balances: BalancesConfig {
balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(),
},
sudo: SudoConfig { key: Some(Sr25519Keyring::Alice.public().into()) },
parachain_info: ParachainInfoConfig { parachain_id: id },
aura: AuraConfig { authorities: invulnerables },
})
}
fn testnet_genesis_with_default_endowed(self_para_id: ParaId) -> serde_json::Value {
let endowed = Sr25519Keyring::well_known().map(|x| x.to_account_id()).collect::<Vec<_>>();
let invulnerables =
Sr25519Keyring::invulnerable().map(|x| x.public().into()).collect::<Vec<_>>();
cumulus_test_runtime(invulnerables, endowed, self_para_id)
}
pub fn preset_names() -> Vec<PresetId> {
vec![
PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET),
PresetId::from(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET),
]
}
pub fn get_preset(id: &PresetId) -> Option<Vec<u8>> {
let patch = match id.as_ref() {
sp_genesis_builder::DEV_RUNTIME_PRESET |
sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET =>
testnet_genesis_with_default_endowed(100.into()),
_ => return None,
};
Some(
serde_json::to_string(&patch)
.expect("serialization to json is expected to work. qed.")
.into_bytes(),
)
}