partner_chains_demo_node/
template_chain_spec.rs

1use crate::chain_spec::*;
2use partner_chains_demo_runtime::{
3	AuraConfig, BalancesConfig, BridgeConfig, GovernedMapConfig, GrandpaConfig,
4	RuntimeGenesisConfig, SLOT_DURATION, SessionCommitteeManagementConfig, SessionConfig,
5	SidechainConfig, SudoConfig, SystemConfig, TestHelperPalletConfig,
6};
7use sc_service::ChainType;
8use sidechain_domain::ScEpochDuration;
9
10/// Produces template chain spec for Partner Chains.
11/// This code should be run by `partner-chains-node wizards chain-spec`, to produce JSON chain spec file.
12/// `initial_validators` fields should be updated by the `partner-chains-node wizards chain-spec`.
13/// Add and modify other fields of `ChainSpec` accordingly to the needs of your chain.
14pub fn chain_spec() -> Result<ChainSpec, envy::Error> {
15	let genesis_utxo = sp_sidechain::read_genesis_utxo_from_env_with_defaults()?;
16	let runtime_genesis_config = RuntimeGenesisConfig {
17		system: SystemConfig { ..Default::default() },
18		balances: BalancesConfig {
19			// Update if any endowed accounts are required.
20			balances: vec![],
21			dev_accounts: None,
22		},
23		aura: AuraConfig { authorities: vec![] },
24		grandpa: GrandpaConfig { authorities: vec![], ..Default::default() },
25		sudo: SudoConfig {
26			// No sudo account by default, please update with your preferences.
27			key: None,
28		},
29		transaction_payment: Default::default(),
30		session: SessionConfig {
31			// Keys are meant to be updated in the chain spec file, so it is empty here.
32			keys: vec![],
33			non_authority_keys: Default::default(),
34		},
35		sidechain: SidechainConfig {
36			genesis_utxo,
37			epoch_duration: ScEpochDuration::from_millis(
38				SLOT_DURATION * read_slots_per_epoch_from_env(),
39			),
40			..Default::default()
41		},
42		session_committee_management: SessionCommitteeManagementConfig {
43			// Same as SessionConfig
44			initial_authorities: vec![],
45			main_chain_scripts: sp_session_validator_management::MainChainScripts::read_from_env()?,
46		},
47		governed_map: GovernedMapConfig {
48			main_chain_scripts: Some(sp_governed_map::MainChainScriptsV1::read_from_env()?),
49			..Default::default()
50		},
51		test_helper_pallet: TestHelperPalletConfig {
52			participation_data_release_period: 30,
53			..Default::default()
54		},
55		bridge: BridgeConfig {
56			main_chain_scripts: Some(sp_partner_chains_bridge::MainChainScripts::read_from_env()?),
57			initial_checkpoint: Some(genesis_utxo),
58			..Default::default()
59		},
60	};
61	let genesis_json = serde_json::to_value(runtime_genesis_config)
62		.expect("Genesis config must be serialized correctly");
63	Ok(ChainSpec::builder(runtime_wasm(), None)
64		.with_name("Partner Chains Template")
65		.with_id("partner_chains_template")
66		.with_chain_type(ChainType::Live)
67		.with_genesis_config(genesis_json)
68		.build())
69}