partner_chains_demo_runtime/
genesis_config_presets.rs1use crate::{
19 AccountId, BalancesConfig, GovernedMapConfig, RuntimeGenesisConfig, SudoConfig,
20 test_helper_pallet,
21};
22use alloc::{vec, vec::Vec};
23use serde_json::Value;
24use sp_consensus_aura::sr25519::AuthorityId as AuraId;
25use sp_consensus_grandpa::AuthorityId as GrandpaId;
26use sp_genesis_builder::{self, PresetId};
27use sp_keyring::Sr25519Keyring;
28
29fn testnet_genesis(
31 initial_authorities: Vec<(AuraId, GrandpaId)>,
32 endowed_accounts: Vec<AccountId>,
33 root: AccountId,
34) -> Value {
35 let config = RuntimeGenesisConfig {
36 balances: BalancesConfig {
37 balances: endowed_accounts
38 .iter()
39 .cloned()
40 .map(|k| (k, 1u128 << 60))
41 .collect::<Vec<_>>(),
42 dev_accounts: None,
43 },
44 aura: pallet_aura::GenesisConfig {
45 authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect::<Vec<_>>(),
46 },
47 grandpa: pallet_grandpa::GenesisConfig {
48 authorities: initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect::<Vec<_>>(),
49 ..Default::default()
50 },
51 sudo: SudoConfig { key: Some(root) },
52 test_helper_pallet: test_helper_pallet::GenesisConfig {
53 participation_data_release_period:
54 test_helper_pallet::DEFAULT_PARTICIPATION_DATA_RELEASE_PERIOD,
55 _phantom: core::marker::PhantomData,
56 },
57 system: Default::default(),
58 transaction_payment: Default::default(),
59 sidechain: Default::default(),
60 session_committee_management: Default::default(),
61 pallet_session: Default::default(),
62 session: Default::default(),
63 native_token_management: Default::default(),
64 governed_map: GovernedMapConfig {
65 main_chain_scripts: Some(sp_governed_map::MainChainScriptsV1::default()),
66 ..Default::default()
67 },
68 };
69
70 serde_json::to_value(config).expect("Could not build genesis config.")
71}
72
73pub fn development_config_genesis() -> Value {
75 testnet_genesis(
76 vec![(
77 sp_keyring::Sr25519Keyring::Alice.public().into(),
78 sp_keyring::Ed25519Keyring::Alice.public().into(),
79 )],
80 vec![
81 Sr25519Keyring::Alice.to_account_id(),
82 Sr25519Keyring::Bob.to_account_id(),
83 Sr25519Keyring::AliceStash.to_account_id(),
84 Sr25519Keyring::BobStash.to_account_id(),
85 ],
86 sp_keyring::Sr25519Keyring::Alice.to_account_id(),
87 )
88}
89
90pub fn local_config_genesis() -> Value {
92 testnet_genesis(
93 vec![
94 (
95 sp_keyring::Sr25519Keyring::Alice.public().into(),
96 sp_keyring::Ed25519Keyring::Alice.public().into(),
97 ),
98 (
99 sp_keyring::Sr25519Keyring::Bob.public().into(),
100 sp_keyring::Ed25519Keyring::Bob.public().into(),
101 ),
102 ],
103 Sr25519Keyring::iter()
104 .filter(|v| v != &Sr25519Keyring::One && v != &Sr25519Keyring::Two)
105 .map(|v| v.to_account_id())
106 .collect::<Vec<_>>(),
107 Sr25519Keyring::Alice.to_account_id(),
108 )
109}
110
111pub fn get_preset(id: &PresetId) -> Option<Vec<u8>> {
113 let patch = match id.as_ref() {
114 sp_genesis_builder::DEV_RUNTIME_PRESET => development_config_genesis(),
115 sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET => local_config_genesis(),
116 _ => return None,
117 };
118 Some(
119 serde_json::to_string(&patch)
120 .expect("serialization to json is expected to work. qed.")
121 .into_bytes(),
122 )
123}
124
125pub fn preset_names() -> Vec<PresetId> {
127 vec![
128 PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET),
129 PresetId::from(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET),
130 ]
131}