Skip to content

Commit

Permalink
Set get_preset for AssetHubRococo
Browse files Browse the repository at this point in the history
  • Loading branch information
bkontur committed Sep 1, 2024
1 parent b7d5f15 commit b0aed66
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,60 +15,54 @@

//! # Asset Hub Rococo Runtime genesis config presets

use crate::*;
use alloc::{vec, vec::Vec};
use cumulus_primitives_core::ParaId;
use hex_literal::hex;
use parachains_common::{genesis_config_helpers::*, AccountId, AuraId, Balance as AssetHubBalance};
use parachains_common::{genesis_config_helpers::*, AccountId, AuraId};
use sp_core::{crypto::UncheckedInto, sr25519};
use sp_genesis_builder::PresetId;
use testnet_parachains_constants::rococo::xcm_version::SAFE_XCM_VERSION;
use testnet_parachains_constants::rococo::{currency::UNITS as ROC, xcm_version::SAFE_XCM_VERSION};

const ASSET_HUB_ROCOCO_ED: AssetHubBalance = crate::ExistentialDeposit::get();

/// Generate the session keys from individual elements.
///
/// The input must be a tuple of individual keys (a single arg for now since we have just one key).
pub fn asset_hub_rococo_session_keys(keys: AuraId) -> crate::SessionKeys {
crate::SessionKeys { aura: keys }
}
const ASSET_HUB_ROCOCO_ED: Balance = ExistentialDeposit::get();

fn asset_hub_rococo_genesis(
invulnerables: Vec<(AccountId, AuraId)>,
endowed_accounts: Vec<AccountId>,
endowment: AssetHubBalance,
endowment: Balance,
id: ParaId,
) -> serde_json::Value {
serde_json::json!({
"balances": crate::BalancesConfig {
"balances": BalancesConfig {
balances: endowed_accounts
.iter()
.cloned()
.map(|k| (k, endowment))
.collect(),
},
"parachainInfo": crate::ParachainInfoConfig {
"parachainInfo": ParachainInfoConfig {
parachain_id: id,
..Default::default()
},
"collatorSelection": crate::CollatorSelectionConfig {
"collatorSelection": CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: ASSET_HUB_ROCOCO_ED * 16,
..Default::default()
},
"session": crate::SessionConfig {
"session": SessionConfig {
keys: invulnerables
.into_iter()
.map(|(acc, aura)| {
(
acc.clone(), // account id
acc, // validator id
asset_hub_rococo_session_keys(aura), // session keys
SessionKeys { aura }, // session keys
)
})
.collect(),
..Default::default()
},
"polkadotXcm": crate::PolkadotXcmConfig {
"polkadotXcm": PolkadotXcmConfig {
safe_xcm_version: Some(SAFE_XCM_VERSION),
..Default::default()
}
Expand Down Expand Up @@ -144,7 +138,7 @@ pub fn get_preset(id: &PresetId) -> Option<Vec<u8>> {
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
],
testnet_parachains_constants::rococo::currency::UNITS * 1_000_000,
ROC * 1_000_000,
1000.into(),
),
Ok(PRESET_DEVELOPMENT) => asset_hub_rococo_genesis(
Expand All @@ -159,7 +153,7 @@ pub fn get_preset(id: &PresetId) -> Option<Vec<u8>> {
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
],
testnet_parachains_constants::rococo::currency::UNITS * 1_000_000,
ROC * 1_000_000,
1000.into(),
),
Err(_) | Ok(_) => return None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
use cumulus_primitives_core::AggregateMessageOrigin;
use sp_api::impl_runtime_apis;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
use sp_genesis_builder::PresetId;
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{AccountIdConversion, BlakeTwo256, Block as BlockT, Saturating, Verify},
Expand Down Expand Up @@ -1771,11 +1770,11 @@ impl_runtime_apis! {
build_state::<RuntimeGenesisConfig>(config)
}

fn get_preset(id: &Option<PresetId>) -> Option<Vec<u8>> {
fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
get_preset::<RuntimeGenesisConfig>(id, &genesis_config_presets::get_preset)
}

fn preset_names() -> Vec<PresetId> {
fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
genesis_config_presets::preset_names()
}
}
Expand Down

0 comments on commit b0aed66

Please sign in to comment.