use crate::chain_spec::SAFE_XCM_VERSION;
use cumulus_primitives_core::ParaId;
use parachains_common::{AccountId, AuraId};
use polkadot_omni_node_lib::chain_spec::{Extensions, GenericChainSpec};
use sc_service::ChainType;
use sp_keyring::Sr25519Keyring;
pub fn get_penpal_chain_spec(id: ParaId, relay_chain: &str) -> GenericChainSpec {
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "UNIT".into());
properties.insert("tokenDecimals".into(), 12u32.into());
properties.insert("ss58Format".into(), 42u32.into());
GenericChainSpec::builder(
penpal_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
Extensions {
relay_chain: relay_chain.into(), para_id: id.into(),
},
)
.with_name("Penpal Parachain")
.with_id(&format!("penpal-{}", relay_chain.replace("-local", "")))
.with_chain_type(ChainType::Development)
.with_genesis_config_patch(penpal_testnet_genesis(
vec![
(Sr25519Keyring::Alice.to_account_id(), Sr25519Keyring::Alice.public().into()),
(Sr25519Keyring::Bob.to_account_id(), Sr25519Keyring::Bob.public().into()),
],
Sr25519Keyring::well_known().map(|k| k.to_account_id()).collect(),
id,
))
.build()
}
fn penpal_testnet_genesis(
invulnerables: Vec<(AccountId, AuraId)>,
endowed_accounts: Vec<AccountId>,
id: ParaId,
) -> serde_json::Value {
serde_json::json!({
"balances": {
"balances": endowed_accounts
.iter()
.cloned()
.map(|k| (k, penpal_runtime::EXISTENTIAL_DEPOSIT * 4096))
.collect::<Vec<_>>(),
},
"parachainInfo": {
"parachainId": id,
},
"collatorSelection": {
"invulnerables": invulnerables.iter().cloned().map(|(acc, _)| acc).collect::<Vec<_>>(),
"candidacyBond": penpal_runtime::EXISTENTIAL_DEPOSIT * 16,
},
"session": {
"keys": invulnerables
.into_iter()
.map(|(acc, aura)| {
(
acc.clone(), acc, penpal_session_keys(aura), )
})
.collect::<Vec<_>>(),
},
"polkadotXcm": {
"safeXcmVersion": Some(SAFE_XCM_VERSION),
},
"sudo": {
"key": Some(Sr25519Keyring::Alice.to_account_id()),
},
})
}
pub fn penpal_session_keys(keys: AuraId) -> penpal_runtime::SessionKeys {
penpal_runtime::SessionKeys { aura: keys }
}