referrerpolicy=no-referrer-when-downgrade

coretime_rococo_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//! # Coretime Rococo 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::rococo::{currency::UNITS as ROC, xcm_version::SAFE_XCM_VERSION};
26
27const CORETIME_ROCOCO_ED: Balance = ExistentialDeposit::get();
28pub const CORETIME_PARA_ID: ParaId = ParaId::new(1005);
29
30fn coretime_rococo_genesis(
31	invulnerables: Vec<(AccountId, AuraId)>,
32	endowed_accounts: Vec<AccountId>,
33	endowment: Balance,
34	id: ParaId,
35) -> serde_json::Value {
36	build_struct_json_patch!(RuntimeGenesisConfig {
37		balances: BalancesConfig {
38			balances: endowed_accounts.iter().cloned().map(|k| (k, endowment)).collect(),
39		},
40		parachain_info: ParachainInfoConfig { parachain_id: id },
41		collator_selection: CollatorSelectionConfig {
42			invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
43			candidacy_bond: CORETIME_ROCOCO_ED * 16,
44		},
45		session: SessionConfig {
46			keys: invulnerables
47				.into_iter()
48				.map(|(acc, aura)| {
49					(
50						acc.clone(),          // account id
51						acc,                  // validator id
52						SessionKeys { aura }, // session keys
53					)
54				})
55				.collect(),
56		},
57		polkadot_xcm: PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION) },
58		sudo: SudoConfig { key: Some(Sr25519Keyring::Alice.to_account_id()) }
59	})
60}
61
62/// Provides the JSON representation of predefined genesis config for given `id`.
63pub fn get_preset(id: &PresetId) -> Option<Vec<u8>> {
64	let patch = match id.as_ref() {
65		sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET => coretime_rococo_genesis(
66			// initial collators.
67			vec![
68				(Sr25519Keyring::Alice.to_account_id(), Sr25519Keyring::Alice.public().into()),
69				(Sr25519Keyring::Bob.to_account_id(), Sr25519Keyring::Bob.public().into()),
70			],
71			Sr25519Keyring::well_known().map(|x| x.to_account_id()).collect(),
72			ROC * 1_000_000,
73			CORETIME_PARA_ID,
74		),
75		sp_genesis_builder::DEV_RUNTIME_PRESET => coretime_rococo_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			ROC * 1_000_000,
85			CORETIME_PARA_ID,
86		),
87		_ => return None,
88	};
89
90	Some(
91		serde_json::to_string(&patch)
92			.expect("serialization to json is expected to work. qed.")
93			.into_bytes(),
94	)
95}
96
97/// List of supported presets.
98pub fn preset_names() -> Vec<PresetId> {
99	vec![
100		PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET),
101		PresetId::from(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET),
102	]
103}