bridge_hub_rococo_runtime/
genesis_config_presets.rs1use crate::*;
19use alloc::{vec, vec::Vec};
20use cumulus_primitives_core::ParaId;
21use frame_support::build_struct_json_patch;
22use parachains_common::{AccountId, AuraId};
23use sp_genesis_builder::PresetId;
24use sp_keyring::Sr25519Keyring;
25use testnet_parachains_constants::rococo::xcm_version::SAFE_XCM_VERSION;
26use xcm::latest::WESTEND_GENESIS_HASH;
27
28const BRIDGE_HUB_ROCOCO_ED: Balance = ExistentialDeposit::get();
29
30fn bridge_hub_rococo_genesis(
31 invulnerables: Vec<(AccountId, AuraId)>,
32 endowed_accounts: Vec<AccountId>,
33 id: ParaId,
34 bridges_pallet_owner: Option<AccountId>,
35 asset_hub_para_id: ParaId,
36 opened_bridges: Vec<(Location, InteriorLocation, Option<bp_messages::LegacyLaneId>)>,
37) -> serde_json::Value {
38 build_struct_json_patch!(RuntimeGenesisConfig {
39 balances: BalancesConfig {
40 balances: endowed_accounts
41 .iter()
42 .cloned()
43 .map(|k| (k, 1u128 << 60))
44 .collect::<Vec<_>>(),
45 },
46 parachain_info: ParachainInfoConfig { parachain_id: id },
47 collator_selection: CollatorSelectionConfig {
48 invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
49 candidacy_bond: BRIDGE_HUB_ROCOCO_ED * 16,
50 },
51 session: SessionConfig {
52 keys: invulnerables
53 .into_iter()
54 .map(|(acc, aura)| {
55 (
56 acc.clone(), acc, SessionKeys { aura }, )
60 })
61 .collect(),
62 },
63 polkadot_xcm: PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION) },
64 bridge_polkadot_bulletin_grandpa: BridgePolkadotBulletinGrandpaConfig {
65 owner: bridges_pallet_owner.clone(),
66 },
67 bridge_westend_grandpa: BridgeWestendGrandpaConfig { owner: bridges_pallet_owner.clone() },
68 bridge_westend_messages: BridgeWestendMessagesConfig {
69 owner: bridges_pallet_owner.clone(),
70 },
71 xcm_over_polkadot_bulletin: XcmOverPolkadotBulletinConfig {
72 opened_bridges: vec![(
73 Location::new(1, [Parachain(1004)]),
74 Junctions::from([GlobalConsensus(NetworkId::PolkadotBulletin).into()]),
75 Some(bp_messages::LegacyLaneId([0, 0, 0, 0])),
76 )],
77 },
78 xcm_over_bridge_hub_westend: XcmOverBridgeHubWestendConfig { opened_bridges },
79 ethereum_system: EthereumSystemConfig { para_id: id, asset_hub_para_id },
80 })
81}
82
83pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option<sp_std::vec::Vec<u8>> {
85 let patch = match id.as_ref() {
86 sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET => bridge_hub_rococo_genesis(
87 vec![
89 (Sr25519Keyring::Alice.to_account_id(), Sr25519Keyring::Alice.public().into()),
90 (Sr25519Keyring::Bob.to_account_id(), Sr25519Keyring::Bob.public().into()),
91 ],
92 Sr25519Keyring::well_known().map(|k| k.to_account_id()).collect(),
93 1013.into(),
94 Some(Sr25519Keyring::Bob.to_account_id()),
95 rococo_runtime_constants::system_parachain::ASSET_HUB_ID.into(),
96 vec![(
97 Location::new(1, [Parachain(1000)]),
98 Junctions::from([ByGenesis(WESTEND_GENESIS_HASH).into(), Parachain(1000)]),
99 Some(bp_messages::LegacyLaneId([0, 0, 0, 2])),
100 )],
101 ),
102 sp_genesis_builder::DEV_RUNTIME_PRESET => bridge_hub_rococo_genesis(
103 vec![
105 (Sr25519Keyring::Alice.to_account_id(), Sr25519Keyring::Alice.public().into()),
106 (Sr25519Keyring::Bob.to_account_id(), Sr25519Keyring::Bob.public().into()),
107 ],
108 Sr25519Keyring::well_known().map(|k| k.to_account_id()).collect(),
109 1013.into(),
110 Some(Sr25519Keyring::Bob.to_account_id()),
111 rococo_runtime_constants::system_parachain::ASSET_HUB_ID.into(),
112 vec![],
113 ),
114 _ => return None,
115 };
116 Some(
117 serde_json::to_string(&patch)
118 .expect("serialization to json is expected to work. qed.")
119 .into_bytes(),
120 )
121}
122
123pub fn preset_names() -> Vec<PresetId> {
125 vec![
126 PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET),
127 PresetId::from(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET),
128 ]
129}