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 Rococo,
29 RococoLocal,
30 RococoDevelopment,
31 Westend,
32 WestendLocal,
33 WestendDevelopment,
34}
35
36impl FromStr for PeopleRuntimeType {
37 type Err = String;
38
39 fn from_str(value: &str) -> Result<Self, Self::Err> {
40 match value {
41 kusama::PEOPLE_KUSAMA => Ok(PeopleRuntimeType::Kusama),
42 kusama::PEOPLE_KUSAMA_LOCAL => Ok(PeopleRuntimeType::KusamaLocal),
43 polkadot::PEOPLE_POLKADOT => Ok(PeopleRuntimeType::Polkadot),
44 polkadot::PEOPLE_POLKADOT_LOCAL => Ok(PeopleRuntimeType::PolkadotLocal),
45 rococo::PEOPLE_ROCOCO => Ok(PeopleRuntimeType::Rococo),
46 rococo::PEOPLE_ROCOCO_LOCAL => Ok(PeopleRuntimeType::RococoLocal),
47 rococo::PEOPLE_ROCOCO_DEVELOPMENT => Ok(PeopleRuntimeType::RococoDevelopment),
48 westend::PEOPLE_WESTEND => Ok(PeopleRuntimeType::Westend),
49 westend::PEOPLE_WESTEND_LOCAL => Ok(PeopleRuntimeType::WestendLocal),
50 westend::PEOPLE_WESTEND_DEVELOPMENT => Ok(PeopleRuntimeType::WestendDevelopment),
51 _ => Err(format!("Value '{}' is not configured yet", value)),
52 }
53 }
54}
55
56impl PeopleRuntimeType {
57 pub const ID_PREFIX: &'static str = "people";
58
59 pub fn load_config(&self) -> Result<Box<dyn ChainSpec>, String> {
60 match self {
61 PeopleRuntimeType::Kusama => Ok(Box::new(GenericChainSpec::from_json_bytes(
62 &include_bytes!("../../chain-specs/people-kusama.json")[..],
63 )?)),
64 PeopleRuntimeType::Polkadot => Ok(Box::new(GenericChainSpec::from_json_bytes(
65 &include_bytes!("../../chain-specs/people-polkadot.json")[..],
66 )?)),
67 PeopleRuntimeType::Rococo => Ok(Box::new(GenericChainSpec::from_json_bytes(
68 &include_bytes!("../../chain-specs/people-rococo.json")[..],
69 )?)),
70 PeopleRuntimeType::RococoLocal => Ok(Box::new(rococo::local_config(
71 rococo::PEOPLE_ROCOCO_LOCAL,
72 "Rococo People Local",
73 "rococo-local",
74 ChainType::Local,
75 ))),
76 PeopleRuntimeType::RococoDevelopment => Ok(Box::new(rococo::local_config(
77 rococo::PEOPLE_ROCOCO_DEVELOPMENT,
78 "Rococo People Development",
79 "rococo-development",
80 ChainType::Development,
81 ))),
82 PeopleRuntimeType::Westend => Ok(Box::new(GenericChainSpec::from_json_bytes(
83 &include_bytes!("../../chain-specs/people-westend.json")[..],
84 )?)),
85 PeopleRuntimeType::WestendLocal => Ok(Box::new(westend::local_config(
86 westend::PEOPLE_WESTEND_LOCAL,
87 "Westend People Local",
88 "westend-local",
89 ChainType::Local,
90 ))),
91 PeopleRuntimeType::WestendDevelopment => Ok(Box::new(westend::local_config(
92 westend::PEOPLE_WESTEND_DEVELOPMENT,
93 "Westend People Development",
94 "westend-development",
95 ChainType::Development,
96 ))),
97 other => Err(std::format!(
98 "No default config present for {:?}, you should provide a chain-spec as json file!",
99 other
100 )),
101 }
102 }
103}
104
105fn ensure_id(id: &str) -> Result<&str, String> {
107 if id.starts_with(PeopleRuntimeType::ID_PREFIX) {
108 Ok(id)
109 } else {
110 Err(format!(
111 "Invalid 'id' attribute ({}), should start with prefix: {}",
112 id,
113 PeopleRuntimeType::ID_PREFIX
114 ))
115 }
116}
117
118pub mod rococo {
120 use polkadot_omni_node_lib::chain_spec::{Extensions, GenericChainSpec};
121 use sc_chain_spec::ChainType;
122
123 pub(crate) const PEOPLE_ROCOCO: &str = "people-rococo";
124 pub(crate) const PEOPLE_ROCOCO_LOCAL: &str = "people-rococo-local";
125 pub(crate) const PEOPLE_ROCOCO_DEVELOPMENT: &str = "people-rococo-dev";
126
127 pub fn local_config(
128 spec_id: &str,
129 chain_name: &str,
130 relay_chain: &str,
131 chain_type: ChainType,
132 ) -> GenericChainSpec {
133 let mut properties = sc_chain_spec::Properties::new();
134 properties.insert("ss58Format".into(), 42.into());
135 properties.insert("tokenSymbol".into(), "ROC".into());
136 properties.insert("tokenDecimals".into(), 12.into());
137
138 GenericChainSpec::builder(
139 people_rococo_runtime::WASM_BINARY
140 .expect("WASM binary was not built, please build it!"),
141 Extensions::new_with_relay_chain(relay_chain.to_string()),
142 )
143 .with_name(chain_name)
144 .with_id(super::ensure_id(spec_id).expect("invalid id"))
145 .with_chain_type(chain_type.clone())
146 .with_genesis_config_preset_name(match chain_type {
147 ChainType::Development => sp_genesis_builder::DEV_RUNTIME_PRESET,
148 ChainType::Local => sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET,
149 _ => panic!("chain_type: {chain_type:?} not supported here!"),
150 })
151 .with_properties(properties)
152 .build()
153 }
154}
155
156pub mod westend {
158 use polkadot_omni_node_lib::chain_spec::{Extensions, GenericChainSpec};
159 use sc_chain_spec::ChainType;
160
161 pub(crate) const PEOPLE_WESTEND: &str = "people-westend";
162 pub(crate) const PEOPLE_WESTEND_LOCAL: &str = "people-westend-local";
163 pub(crate) const PEOPLE_WESTEND_DEVELOPMENT: &str = "people-westend-dev";
164
165 pub fn local_config(
166 spec_id: &str,
167 chain_name: &str,
168 relay_chain: &str,
169 chain_type: ChainType,
170 ) -> GenericChainSpec {
171 let mut properties = sc_chain_spec::Properties::new();
172 properties.insert("ss58Format".into(), 42.into());
173 properties.insert("tokenSymbol".into(), "WND".into());
174 properties.insert("tokenDecimals".into(), 12.into());
175
176 GenericChainSpec::builder(
177 people_westend_runtime::WASM_BINARY
178 .expect("WASM binary was not built, please build it!"),
179 Extensions::new_with_relay_chain(relay_chain.to_string()),
180 )
181 .with_name(chain_name)
182 .with_id(super::ensure_id(spec_id).expect("invalid id"))
183 .with_chain_type(chain_type.clone())
184 .with_genesis_config_preset_name(match chain_type {
185 ChainType::Development => sp_genesis_builder::DEV_RUNTIME_PRESET,
186 ChainType::Local => sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET,
187 _ => panic!("chain_type: {chain_type:?} not supported here!"),
188 })
189 .with_properties(properties)
190 .build()
191 }
192}
193
194pub mod kusama {
195 pub(crate) const PEOPLE_KUSAMA: &str = "people-kusama";
196 pub(crate) const PEOPLE_KUSAMA_LOCAL: &str = "people-kusama-local";
197}
198
199pub mod polkadot {
200 pub(crate) const PEOPLE_POLKADOT: &str = "people-polkadot";
201 pub(crate) const PEOPLE_POLKADOT_LOCAL: &str = "people-polkadot-local";
202}