polkadot_parachain/chain_spec/
people.rs1use polkadot_omni_node_lib::chain_spec::GenericChainSpec;
18use sc_chain_spec::{ChainSpec, ChainType};
19use std::str::FromStr;
20
21#[derive(Debug, PartialEq)]
23pub enum PeopleRuntimeType {
24 Kusama,
25 KusamaLocal,
26 Polkadot,
27 PolkadotLocal,
28 Westend,
29 WestendLocal,
30 WestendDevelopment,
31}
32
33impl FromStr for PeopleRuntimeType {
34 type Err = String;
35
36 fn from_str(value: &str) -> Result<Self, Self::Err> {
37 match value {
38 kusama::PEOPLE_KUSAMA => Ok(PeopleRuntimeType::Kusama),
39 kusama::PEOPLE_KUSAMA_LOCAL => Ok(PeopleRuntimeType::KusamaLocal),
40 polkadot::PEOPLE_POLKADOT => Ok(PeopleRuntimeType::Polkadot),
41 polkadot::PEOPLE_POLKADOT_LOCAL => Ok(PeopleRuntimeType::PolkadotLocal),
42 westend::PEOPLE_WESTEND => Ok(PeopleRuntimeType::Westend),
43 westend::PEOPLE_WESTEND_LOCAL => Ok(PeopleRuntimeType::WestendLocal),
44 westend::PEOPLE_WESTEND_DEVELOPMENT => Ok(PeopleRuntimeType::WestendDevelopment),
45 _ => Err(format!("Value '{}' is not configured yet", value)),
46 }
47 }
48}
49
50impl PeopleRuntimeType {
51 pub const ID_PREFIX: &'static str = "people";
52
53 pub fn load_config(&self) -> Result<Box<dyn ChainSpec>, String> {
54 match self {
55 PeopleRuntimeType::Kusama => Ok(Box::new(GenericChainSpec::from_json_bytes(
56 &include_bytes!("../../chain-specs/people-kusama.json")[..],
57 )?)),
58 PeopleRuntimeType::Polkadot => Ok(Box::new(GenericChainSpec::from_json_bytes(
59 &include_bytes!("../../chain-specs/people-polkadot.json")[..],
60 )?)),
61 PeopleRuntimeType::Westend => Ok(Box::new(GenericChainSpec::from_json_bytes(
62 &include_bytes!("../../chain-specs/people-westend.json")[..],
63 )?)),
64 PeopleRuntimeType::WestendLocal => Ok(Box::new(westend::local_config(
65 westend::PEOPLE_WESTEND_LOCAL,
66 "Westend People Local",
67 "westend-local",
68 ChainType::Local,
69 ))),
70 PeopleRuntimeType::WestendDevelopment => Ok(Box::new(westend::local_config(
71 westend::PEOPLE_WESTEND_DEVELOPMENT,
72 "Westend People Development",
73 "westend-development",
74 ChainType::Development,
75 ))),
76 other => Err(std::format!(
77 "No default config present for {:?}, you should provide a chain-spec as json file!",
78 other
79 )),
80 }
81 }
82}
83
84fn ensure_id(id: &str) -> Result<&str, String> {
86 if id.starts_with(PeopleRuntimeType::ID_PREFIX) {
87 Ok(id)
88 } else {
89 Err(format!(
90 "Invalid 'id' attribute ({}), should start with prefix: {}",
91 id,
92 PeopleRuntimeType::ID_PREFIX
93 ))
94 }
95}
96
97pub mod westend {
99 use polkadot_omni_node_lib::chain_spec::{Extensions, GenericChainSpec};
100 use sc_chain_spec::ChainType;
101
102 pub(crate) const PEOPLE_WESTEND: &str = "people-westend";
103 pub(crate) const PEOPLE_WESTEND_LOCAL: &str = "people-westend-local";
104 pub(crate) const PEOPLE_WESTEND_DEVELOPMENT: &str = "people-westend-dev";
105
106 pub fn local_config(
107 spec_id: &str,
108 chain_name: &str,
109 relay_chain: &str,
110 chain_type: ChainType,
111 ) -> GenericChainSpec {
112 let mut properties = sc_chain_spec::Properties::new();
113 properties.insert("ss58Format".into(), 42.into());
114 properties.insert("tokenSymbol".into(), "WND".into());
115 properties.insert("tokenDecimals".into(), 12.into());
116
117 GenericChainSpec::builder(
118 people_westend_runtime::WASM_BINARY
119 .expect("WASM binary was not built, please build it!"),
120 Extensions::new_with_relay_chain(relay_chain.to_string()),
121 )
122 .with_name(chain_name)
123 .with_id(super::ensure_id(spec_id).expect("invalid id"))
124 .with_chain_type(chain_type.clone())
125 .with_genesis_config_preset_name(match chain_type {
126 ChainType::Development => sp_genesis_builder::DEV_RUNTIME_PRESET,
127 ChainType::Local => sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET,
128 _ => panic!("chain_type: {chain_type:?} not supported here!"),
129 })
130 .with_properties(properties)
131 .build()
132 }
133}
134
135pub mod kusama {
136 pub(crate) const PEOPLE_KUSAMA: &str = "people-kusama";
137 pub(crate) const PEOPLE_KUSAMA_LOCAL: &str = "people-kusama-local";
138}
139
140pub mod polkadot {
141 pub(crate) const PEOPLE_POLKADOT: &str = "people-polkadot";
142 pub(crate) const PEOPLE_POLKADOT_LOCAL: &str = "people-polkadot-local";
143}