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 session: Default::default(),
62 governed_map: GovernedMapConfig {
63 main_chain_scripts: Some(sp_governed_map::MainChainScriptsV1::default()),
64 ..Default::default()
65 },
66 bridge: Default::default(),
67 };
68
69 serde_json::to_value(config).expect("Could not build genesis config.")
70}
71
72pub fn development_config_genesis() -> Value {
74 testnet_genesis(
75 vec![(
76 sp_keyring::Sr25519Keyring::Alice.public().into(),
77 sp_keyring::Ed25519Keyring::Alice.public().into(),
78 )],
79 vec![
80 Sr25519Keyring::Alice.to_account_id(),
81 Sr25519Keyring::Bob.to_account_id(),
82 Sr25519Keyring::AliceStash.to_account_id(),
83 Sr25519Keyring::BobStash.to_account_id(),
84 ],
85 sp_keyring::Sr25519Keyring::Alice.to_account_id(),
86 )
87}
88
89pub fn local_config_genesis() -> Value {
91 testnet_genesis(
92 vec![
93 (
94 sp_keyring::Sr25519Keyring::Alice.public().into(),
95 sp_keyring::Ed25519Keyring::Alice.public().into(),
96 ),
97 (
98 sp_keyring::Sr25519Keyring::Bob.public().into(),
99 sp_keyring::Ed25519Keyring::Bob.public().into(),
100 ),
101 ],
102 Sr25519Keyring::iter()
103 .filter(|v| v != &Sr25519Keyring::One && v != &Sr25519Keyring::Two)
104 .map(|v| v.to_account_id())
105 .collect::<Vec<_>>(),
106 Sr25519Keyring::Alice.to_account_id(),
107 )
108}
109
110pub fn get_preset(id: &PresetId) -> Option<Vec<u8>> {
112 let patch = match id.as_ref() {
113 sp_genesis_builder::DEV_RUNTIME_PRESET => development_config_genesis(),
114 sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET => local_config_genesis(),
115 _ => return None,
116 };
117 Some(
118 serde_json::to_string(&patch)
119 .expect("serialization to json is expected to work. qed.")
120 .into_bytes(),
121 )
122}
123
124pub fn preset_names() -> Vec<PresetId> {
126 vec![
127 PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET),
128 PresetId::from(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET),
129 ]
130}