|
| 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 | +//! # Asset Hub Rococo Runtime genesis config presets |
| 17 | +
|
| 18 | +use alloc::{vec, vec::Vec}; |
| 19 | +use cumulus_primitives_core::ParaId; |
| 20 | +use hex_literal::hex; |
| 21 | +use parachains_common::{genesis_config_helpers::*, AccountId, AuraId, Balance as AssetHubBalance}; |
| 22 | +use sp_core::{crypto::UncheckedInto, sr25519}; |
| 23 | +use sp_genesis_builder::PresetId; |
| 24 | +use testnet_parachains_constants::rococo::xcm_version::SAFE_XCM_VERSION; |
| 25 | + |
| 26 | +const ASSET_HUB_ROCOCO_ED: AssetHubBalance = crate::ExistentialDeposit::get(); |
| 27 | + |
| 28 | +/// Generate the session keys from individual elements. |
| 29 | +/// |
| 30 | +/// The input must be a tuple of individual keys (a single arg for now since we have just one key). |
| 31 | +pub fn asset_hub_rococo_session_keys(keys: AuraId) -> crate::SessionKeys { |
| 32 | + crate::SessionKeys { aura: keys } |
| 33 | +} |
| 34 | + |
| 35 | +fn asset_hub_rococo_genesis( |
| 36 | + invulnerables: Vec<(AccountId, AuraId)>, |
| 37 | + endowed_accounts: Vec<AccountId>, |
| 38 | + endowment: AssetHubBalance, |
| 39 | + id: ParaId, |
| 40 | +) -> serde_json::Value { |
| 41 | + serde_json::json!({ |
| 42 | + "balances": crate::BalancesConfig { |
| 43 | + balances: endowed_accounts |
| 44 | + .iter() |
| 45 | + .cloned() |
| 46 | + .map(|k| (k, endowment)) |
| 47 | + .collect(), |
| 48 | + }, |
| 49 | + "parachainInfo": crate::ParachainInfoConfig { |
| 50 | + parachain_id: id, |
| 51 | + ..Default::default() |
| 52 | + }, |
| 53 | + "collatorSelection": crate::CollatorSelectionConfig { |
| 54 | + invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), |
| 55 | + candidacy_bond: ASSET_HUB_ROCOCO_ED * 16, |
| 56 | + ..Default::default() |
| 57 | + }, |
| 58 | + "session": crate::SessionConfig { |
| 59 | + keys: invulnerables |
| 60 | + .into_iter() |
| 61 | + .map(|(acc, aura)| { |
| 62 | + ( |
| 63 | + acc.clone(), // account id |
| 64 | + acc, // validator id |
| 65 | + asset_hub_rococo_session_keys(aura), // session keys |
| 66 | + ) |
| 67 | + }) |
| 68 | + .collect(), |
| 69 | + ..Default::default() |
| 70 | + }, |
| 71 | + "polkadotXcm": crate::PolkadotXcmConfig { |
| 72 | + safe_xcm_version: Some(SAFE_XCM_VERSION), |
| 73 | + ..Default::default() |
| 74 | + } |
| 75 | + }) |
| 76 | +} |
| 77 | + |
| 78 | +/// Encapsulates names of predefined presets. |
| 79 | +mod preset_names { |
| 80 | + pub const PRESET_DEVELOPMENT: &str = "development"; |
| 81 | + pub const PRESET_LOCAL: &str = "local"; |
| 82 | + pub const PRESET_GENESIS: &str = "genesis"; |
| 83 | +} |
| 84 | + |
| 85 | +/// Provides the JSON representation of predefined genesis config for given `id`. |
| 86 | +pub fn get_preset(id: &PresetId) -> Option<Vec<u8>> { |
| 87 | + use preset_names::*; |
| 88 | + let patch = match id.try_into() { |
| 89 | + Ok(PRESET_GENESIS) => asset_hub_rococo_genesis( |
| 90 | + // initial collators. |
| 91 | + vec![ |
| 92 | + // E8XC6rTJRsioKCp6KMy6zd24ykj4gWsusZ3AkSeyavpVBAG |
| 93 | + ( |
| 94 | + hex!("44cb62d1d6cdd2fff2a5ef3bb7ef827be5b3e117a394ecaa634d8dd9809d5608").into(), |
| 95 | + hex!("44cb62d1d6cdd2fff2a5ef3bb7ef827be5b3e117a394ecaa634d8dd9809d5608") |
| 96 | + .unchecked_into(), |
| 97 | + ), |
| 98 | + // G28iWEybndgGRbhfx83t7Q42YhMPByHpyqWDUgeyoGF94ri |
| 99 | + ( |
| 100 | + hex!("9864b85e23aa4506643db9879c3dbbeabaa94d269693a4447f537dd6b5893944").into(), |
| 101 | + hex!("9864b85e23aa4506643db9879c3dbbeabaa94d269693a4447f537dd6b5893944") |
| 102 | + .unchecked_into(), |
| 103 | + ), |
| 104 | + // G839e2eMiq7UXbConsY6DS1XDAYG2XnQxAmLuRLGGQ3Px9c |
| 105 | + ( |
| 106 | + hex!("9ce5741ee2f1ac3bdedbde9f3339048f4da2cb88ddf33a0977fa0b4cf86e2948").into(), |
| 107 | + hex!("9ce5741ee2f1ac3bdedbde9f3339048f4da2cb88ddf33a0977fa0b4cf86e2948") |
| 108 | + .unchecked_into(), |
| 109 | + ), |
| 110 | + // GLao4ukFUW6qhexuZowdFrKa2NLCfnEjZMftSXXfvGv1vvt |
| 111 | + ( |
| 112 | + hex!("a676ed15f5a325eab49ed8d5f8c00f3f814b19bb58cda14ad10894c078dd337f").into(), |
| 113 | + hex!("a676ed15f5a325eab49ed8d5f8c00f3f814b19bb58cda14ad10894c078dd337f") |
| 114 | + .unchecked_into(), |
| 115 | + ), |
| 116 | + ], |
| 117 | + Vec::new(), |
| 118 | + ASSET_HUB_ROCOCO_ED * 524_288, |
| 119 | + 1000.into(), |
| 120 | + ), |
| 121 | + Ok(PRESET_LOCAL) => asset_hub_rococo_genesis( |
| 122 | + // initial collators. |
| 123 | + vec![ |
| 124 | + ( |
| 125 | + get_account_id_from_seed::<sr25519::Public>("Alice"), |
| 126 | + get_collator_keys_from_seed::<AuraId>("Alice"), |
| 127 | + ), |
| 128 | + ( |
| 129 | + get_account_id_from_seed::<sr25519::Public>("Bob"), |
| 130 | + get_collator_keys_from_seed::<AuraId>("Bob"), |
| 131 | + ), |
| 132 | + ], |
| 133 | + vec![ |
| 134 | + get_account_id_from_seed::<sr25519::Public>("Alice"), |
| 135 | + get_account_id_from_seed::<sr25519::Public>("Bob"), |
| 136 | + get_account_id_from_seed::<sr25519::Public>("Charlie"), |
| 137 | + get_account_id_from_seed::<sr25519::Public>("Dave"), |
| 138 | + get_account_id_from_seed::<sr25519::Public>("Eve"), |
| 139 | + get_account_id_from_seed::<sr25519::Public>("Ferdie"), |
| 140 | + get_account_id_from_seed::<sr25519::Public>("Alice//stash"), |
| 141 | + get_account_id_from_seed::<sr25519::Public>("Bob//stash"), |
| 142 | + get_account_id_from_seed::<sr25519::Public>("Charlie//stash"), |
| 143 | + get_account_id_from_seed::<sr25519::Public>("Dave//stash"), |
| 144 | + get_account_id_from_seed::<sr25519::Public>("Eve//stash"), |
| 145 | + get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"), |
| 146 | + ], |
| 147 | + testnet_parachains_constants::rococo::currency::UNITS * 1_000_000, |
| 148 | + 1000.into(), |
| 149 | + ), |
| 150 | + Ok(PRESET_DEVELOPMENT) => asset_hub_rococo_genesis( |
| 151 | + // initial collators. |
| 152 | + vec![( |
| 153 | + get_account_id_from_seed::<sr25519::Public>("Alice"), |
| 154 | + get_collator_keys_from_seed::<AuraId>("Alice"), |
| 155 | + )], |
| 156 | + vec![ |
| 157 | + get_account_id_from_seed::<sr25519::Public>("Alice"), |
| 158 | + get_account_id_from_seed::<sr25519::Public>("Bob"), |
| 159 | + get_account_id_from_seed::<sr25519::Public>("Alice//stash"), |
| 160 | + get_account_id_from_seed::<sr25519::Public>("Bob//stash"), |
| 161 | + ], |
| 162 | + testnet_parachains_constants::rococo::currency::UNITS * 1_000_000, |
| 163 | + 1000.into(), |
| 164 | + ), |
| 165 | + Err(_) | Ok(_) => return None, |
| 166 | + }; |
| 167 | + |
| 168 | + Some( |
| 169 | + serde_json::to_string(&patch) |
| 170 | + .expect("serialization to json is expected to work. qed.") |
| 171 | + .into_bytes(), |
| 172 | + ) |
| 173 | +} |
| 174 | + |
| 175 | +/// List of supported presets. |
| 176 | +pub fn preset_names() -> Vec<PresetId> { |
| 177 | + use preset_names::*; |
| 178 | + vec![ |
| 179 | + PresetId::from(PRESET_GENESIS), |
| 180 | + PresetId::from(PRESET_DEVELOPMENT), |
| 181 | + PresetId::from(PRESET_LOCAL), |
| 182 | + ] |
| 183 | +} |
0 commit comments