referrerpolicy=no-referrer-when-downgrade

glutton_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//! # Glutton Westend Runtime genesis config presets
17
18use crate::*;
19use alloc::vec::Vec;
20use cumulus_primitives_core::ParaId;
21use frame_support::build_struct_json_patch;
22use parachains_common::AuraId;
23use sp_genesis_builder::PresetId;
24use sp_keyring::Sr25519Keyring;
25
26/// Default value, unused in a testnet setup currently because
27/// we want to supply varying para-ids from the CLI for Glutton.
28/// However, the presets does not allow dynamic para-ids currently.
29pub const DEFAULT_GLUTTON_PARA_ID: ParaId = ParaId::new(1300);
30
31pub fn glutton_westend_genesis(
32	authorities: Vec<AuraId>,
33	sudo: Option<AccountId>,
34	id: ParaId,
35) -> serde_json::Value {
36	build_struct_json_patch!(RuntimeGenesisConfig {
37		parachain_info: ParachainInfoConfig { parachain_id: id },
38		aura: AuraConfig { authorities },
39		sudo: SudoConfig { key: sudo }
40	})
41}
42
43/// Provides the JSON representation of predefined genesis config for given `id`.
44pub fn get_preset(id: &PresetId) -> Option<Vec<u8>> {
45	let patch = match id.as_ref() {
46		sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET => glutton_westend_genesis(
47			// initial collators.
48			vec![Sr25519Keyring::Alice.public().into(), Sr25519Keyring::Bob.public().into()],
49			Some(Sr25519Keyring::Alice.to_account_id()),
50			DEFAULT_GLUTTON_PARA_ID,
51		),
52		sp_genesis_builder::DEV_RUNTIME_PRESET => glutton_westend_genesis(
53			// initial collators.
54			vec![Sr25519Keyring::Alice.public().into()],
55			Some(Sr25519Keyring::Alice.to_account_id()),
56			DEFAULT_GLUTTON_PARA_ID,
57		),
58		_ => return None,
59	};
60
61	Some(
62		serde_json::to_string(&patch)
63			.expect("serialization to json is expected to work. qed.")
64			.into_bytes(),
65	)
66}
67
68/// List of supported presets.
69pub fn preset_names() -> Vec<PresetId> {
70	vec![
71		PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET),
72		PresetId::from(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET),
73	]
74}