frequency_service/
chain_spec.rs

1#![allow(missing_docs)]
2use common_primitives::node::{AccountId, Signature};
3use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
4use sc_service::Properties;
5use serde::{Deserialize, Serialize};
6pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
7use sp_core::{Pair, Public};
8use sp_runtime::traits::{IdentifyAccount, Verify};
9
10/// Dummy chain spec for building and checking
11pub type DummyChainSpec = sc_service::GenericChainSpec<Extensions>;
12
13#[cfg(feature = "frequency")]
14pub mod frequency;
15
16#[cfg(feature = "frequency-testnet")]
17pub mod frequency_paseo;
18
19#[cfg(feature = "frequency-westend")]
20pub mod frequency_westend;
21
22#[cfg(any(feature = "frequency-local", feature = "frequency-no-relay"))]
23pub mod frequency_paseo_local;
24
25#[cfg(feature = "frequency-bridging")]
26pub mod frequency_westend_local;
27
28#[cfg(feature = "frequency-no-relay")]
29pub mod frequency_dev;
30
31#[allow(clippy::expect_used)]
32/// Helper function to generate a crypto pair from seed
33pub fn get_public_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
34	TPublic::Pair::from_string(&format!("//{seed}"), None)
35		.expect("static values are valid; qed")
36		.public()
37}
38
39type AccountPublic = <Signature as Verify>::Signer;
40
41/// Generate collator keys from seed.
42///
43/// This function's return type must always match the session keys of the chain in tuple format.
44pub fn get_collator_keys_from_seed(seed: &str) -> AuraId {
45	get_public_from_seed::<AuraId>(seed)
46}
47
48/// Helper function to generate an account ID from seed
49pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
50where
51	AccountPublic: From<<TPublic::Pair as Pair>::Public>,
52{
53	AccountPublic::from(get_public_from_seed::<TPublic>(seed)).into_account()
54}
55
56/// The extensions for the [`sc_service::ChainSpec`].
57#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)]
58#[serde(deny_unknown_fields)]
59pub struct Extensions {
60	/// The relay chain of the Parachain.
61	pub relay_chain: String,
62	/// The id of the Parachain.
63	pub para_id: u32,
64}
65
66impl Extensions {
67	/// Try to get the extension from the given `ChainSpec`.
68	pub fn try_get(chain_spec: &dyn sc_service::ChainSpec) -> Option<&Self> {
69		sc_chain_spec::get_extension(chain_spec.extensions())
70	}
71}
72
73pub fn get_properties(symbol: &str, decimals: u32, ss58format: u32) -> Properties {
74	let mut properties = Properties::new();
75	properties.insert("tokenSymbol".into(), symbol.into());
76	properties.insert("tokenDecimals".into(), decimals.into());
77	properties.insert("ss58Format".into(), ss58format.into());
78
79	properties
80}