solochain_template_runtime/
genesis_config_presets.rs1use crate::{AccountId, BalancesConfig, RuntimeGenesisConfig, SudoConfig};
19use alloc::{vec, vec::Vec};
20use frame_support::build_struct_json_patch;
21use serde_json::Value;
22use sp_consensus_aura::sr25519::AuthorityId as AuraId;
23use sp_consensus_grandpa::AuthorityId as GrandpaId;
24use sp_genesis_builder::{self, PresetId};
25use sp_keyring::Sr25519Keyring;
26
27fn testnet_genesis(
29 initial_authorities: Vec<(AuraId, GrandpaId)>,
30 endowed_accounts: Vec<AccountId>,
31 root: AccountId,
32) -> Value {
33 build_struct_json_patch!(RuntimeGenesisConfig {
34 balances: BalancesConfig {
35 balances: endowed_accounts
36 .iter()
37 .cloned()
38 .map(|k| (k, 1u128 << 60))
39 .collect::<Vec<_>>(),
40 },
41 aura: pallet_aura::GenesisConfig {
42 authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect::<Vec<_>>(),
43 },
44 grandpa: pallet_grandpa::GenesisConfig {
45 authorities: initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect::<Vec<_>>(),
46 },
47 sudo: SudoConfig { key: Some(root) },
48 })
49}
50
51pub fn development_config_genesis() -> Value {
53 testnet_genesis(
54 vec![(
55 sp_keyring::Sr25519Keyring::Alice.public().into(),
56 sp_keyring::Ed25519Keyring::Alice.public().into(),
57 )],
58 vec![
59 Sr25519Keyring::Alice.to_account_id(),
60 Sr25519Keyring::Bob.to_account_id(),
61 Sr25519Keyring::AliceStash.to_account_id(),
62 Sr25519Keyring::BobStash.to_account_id(),
63 ],
64 sp_keyring::Sr25519Keyring::Alice.to_account_id(),
65 )
66}
67
68pub fn local_config_genesis() -> Value {
70 testnet_genesis(
71 vec![
72 (
73 sp_keyring::Sr25519Keyring::Alice.public().into(),
74 sp_keyring::Ed25519Keyring::Alice.public().into(),
75 ),
76 (
77 sp_keyring::Sr25519Keyring::Bob.public().into(),
78 sp_keyring::Ed25519Keyring::Bob.public().into(),
79 ),
80 ],
81 Sr25519Keyring::iter()
82 .filter(|v| v != &Sr25519Keyring::One && v != &Sr25519Keyring::Two)
83 .map(|v| v.to_account_id())
84 .collect::<Vec<_>>(),
85 Sr25519Keyring::Alice.to_account_id(),
86 )
87}
88
89pub fn get_preset(id: &PresetId) -> Option<Vec<u8>> {
91 let patch = match id.as_ref() {
92 sp_genesis_builder::DEV_RUNTIME_PRESET => development_config_genesis(),
93 sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET => local_config_genesis(),
94 _ => return None,
95 };
96 Some(
97 serde_json::to_string(&patch)
98 .expect("serialization to json is expected to work. qed.")
99 .into_bytes(),
100 )
101}
102
103pub fn preset_names() -> Vec<PresetId> {
105 vec![
106 PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET),
107 PresetId::from(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET),
108 ]
109}