referrerpolicy=no-referrer-when-downgrade

parachain_template_node/
chain_spec.rs

1use polkadot_sdk::*;
2
3use parachain_template_runtime as runtime;
4use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
5use sc_service::ChainType;
6use serde::{Deserialize, Serialize};
7
8/// Specialized `ChainSpec` for the normal parachain runtime.
9pub type ChainSpec = sc_service::GenericChainSpec<Extensions>;
10/// The relay chain that you want to configure this parachain to connect to.
11pub const RELAY_CHAIN: &str = "rococo-local";
12
13/// The extensions for the [`ChainSpec`].
14#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)]
15pub struct Extensions {
16	/// The relay chain of the Parachain.
17	#[serde(alias = "relayChain", alias = "RelayChain")]
18	pub relay_chain: String,
19}
20
21impl Extensions {
22	/// Try to get the extension from the given `ChainSpec`.
23	pub fn try_get(chain_spec: &dyn sc_service::ChainSpec) -> Option<&Self> {
24		sc_chain_spec::get_extension(chain_spec.extensions())
25	}
26}
27
28pub fn development_chain_spec() -> ChainSpec {
29	// Give your base currency a unit name and decimal places
30	let mut properties = sc_chain_spec::Properties::new();
31	properties.insert("tokenSymbol".into(), "UNIT".into());
32	properties.insert("tokenDecimals".into(), 12.into());
33	properties.insert("ss58Format".into(), 42.into());
34
35	ChainSpec::builder(
36		runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
37		Extensions { relay_chain: RELAY_CHAIN.into() },
38	)
39	.with_name("Development")
40	.with_id("dev")
41	.with_chain_type(ChainType::Development)
42	.with_genesis_config_preset_name(sp_genesis_builder::DEV_RUNTIME_PRESET)
43	.with_properties(properties)
44	.build()
45}
46
47pub fn local_chain_spec() -> ChainSpec {
48	// Give your base currency a unit name and decimal places
49	let mut properties = sc_chain_spec::Properties::new();
50	properties.insert("tokenSymbol".into(), "UNIT".into());
51	properties.insert("tokenDecimals".into(), 12.into());
52	properties.insert("ss58Format".into(), 42.into());
53
54	ChainSpec::builder(
55		runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
56		Extensions { relay_chain: RELAY_CHAIN.into() },
57	)
58	.with_name("Local Testnet")
59	.with_id("local_testnet")
60	.with_chain_type(ChainType::Local)
61	.with_genesis_config_preset_name(sc_chain_spec::LOCAL_TESTNET_RUNTIME_PRESET)
62	.with_protocol_id("template-local")
63	.with_properties(properties)
64	.build()
65}