referrerpolicy=no-referrer-when-downgrade

collectives_westend_runtime/
genesis_config_presets.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// SPDX-License-Identifier: Apache-2.0
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// 	http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16//! # Bridge Hub Westend Runtime genesis config presets
17
18use 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::westend::xcm_version::SAFE_XCM_VERSION;
26
27const COLLECTIVES_WESTEND_ED: Balance = ExistentialDeposit::get();
28
29fn collectives_westend_genesis(
30	invulnerables: Vec<(AccountId, AuraId)>,
31	endowed_accounts: Vec<AccountId>,
32	id: ParaId,
33) -> serde_json::Value {
34	build_struct_json_patch!(RuntimeGenesisConfig {
35		balances: BalancesConfig {
36			balances: endowed_accounts
37				.iter()
38				.cloned()
39				.map(|k| (k, COLLECTIVES_WESTEND_ED * 4096))
40				.collect::<Vec<_>>(),
41		},
42		parachain_info: ParachainInfoConfig { parachain_id: id },
43		collator_selection: CollatorSelectionConfig {
44			invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
45			candidacy_bond: COLLECTIVES_WESTEND_ED * 16,
46		},
47		session: SessionConfig {
48			keys: invulnerables
49				.into_iter()
50				.map(|(acc, aura)| {
51					(
52						acc.clone(),          // account id
53						acc,                  // validator id
54						SessionKeys { aura }, // session keys
55					)
56				})
57				.collect(),
58		},
59		polkadot_xcm: PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION) },
60	})
61}
62
63/// Provides the JSON representation of predefined genesis config for given `id`.
64pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option<sp_std::vec::Vec<u8>> {
65	let patch = match id.as_ref() {
66		sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET => collectives_westend_genesis(
67			// initial collators.
68			vec![
69				(Sr25519Keyring::Alice.to_account_id(), Sr25519Keyring::Alice.public().into()),
70				(Sr25519Keyring::Bob.to_account_id(), Sr25519Keyring::Bob.public().into()),
71			],
72			Sr25519Keyring::well_known().map(|k| k.to_account_id()).collect(),
73			1001.into(),
74		),
75		sp_genesis_builder::DEV_RUNTIME_PRESET => collectives_westend_genesis(
76			// initial collators.
77			vec![(Sr25519Keyring::Alice.to_account_id(), Sr25519Keyring::Alice.public().into())],
78			vec![
79				Sr25519Keyring::Alice.to_account_id(),
80				Sr25519Keyring::Bob.to_account_id(),
81				Sr25519Keyring::AliceStash.to_account_id(),
82				Sr25519Keyring::BobStash.to_account_id(),
83			],
84			1001.into(),
85		),
86		_ => return None,
87	};
88	Some(
89		serde_json::to_string(&patch)
90			.expect("serialization to json is expected to work. qed.")
91			.into_bytes(),
92	)
93}
94
95/// List of supported presets.
96pub fn preset_names() -> Vec<PresetId> {
97	vec![
98		PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET),
99		PresetId::from(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET),
100	]
101}