polkadot_parachain/chain_spec/
mod.rs1use cumulus_primitives_core::ParaId;
18use polkadot_omni_node_lib::chain_spec::{GenericChainSpec, LoadSpec};
19use sc_chain_spec::{ChainSpec, ChainType};
20use yet_another_parachain::yet_another_parachain_config;
21
22pub mod asset_hubs;
23pub mod bridge_hubs;
24pub mod collectives;
25pub mod coretime;
26pub mod glutton;
27pub mod penpal;
28pub mod people;
29pub mod yet_another_parachain;
30
31fn extract_parachain_id<'a>(
35 id: &'a str,
36 para_prefixes: &[&str],
37) -> (&'a str, &'a str, Option<ParaId>) {
38 for para_prefix in para_prefixes {
39 if let Some(suffix) = id.strip_prefix(para_prefix) {
40 let para_id: u32 = suffix.parse().expect("Invalid parachain-id suffix");
41 return (&id[..para_prefix.len() - 1], id, Some(para_id.into()));
42 }
43 }
44
45 (id, id, None)
46}
47
48#[derive(Debug)]
49pub(crate) struct ChainSpecLoader;
50
51impl LoadSpec for ChainSpecLoader {
52 fn load_spec(&self, id: &str) -> Result<Box<dyn ChainSpec>, String> {
53 Ok(match id {
54 "staging" => Box::new(penpal::staging_penpal_local_config()),
56 "tick" => Box::new(GenericChainSpec::from_json_bytes(
57 &include_bytes!("../../chain-specs/tick.json")[..],
58 )?),
59 "trick" => Box::new(GenericChainSpec::from_json_bytes(
60 &include_bytes!("../../chain-specs/trick.json")[..],
61 )?),
62 "track" => Box::new(GenericChainSpec::from_json_bytes(
63 &include_bytes!("../../chain-specs/track.json")[..],
64 )?),
65
66 "asset-hub-polkadot" | "statemint" => Box::new(GenericChainSpec::from_json_bytes(
68 &include_bytes!("../../chain-specs/asset-hub-polkadot.json")[..],
69 )?),
70
71 "asset-hub-kusama" | "statemine" => Box::new(GenericChainSpec::from_json_bytes(
73 &include_bytes!("../../chain-specs/asset-hub-kusama.json")[..],
74 )?),
75
76 "asset-hub-rococo-dev" => Box::new(asset_hubs::asset_hub_rococo_development_config()),
78 "asset-hub-rococo-local" => Box::new(asset_hubs::asset_hub_rococo_local_config()),
79 "asset-hub-rococo-genesis" => Box::new(asset_hubs::asset_hub_rococo_genesis_config()),
81 "asset-hub-rococo" => Box::new(GenericChainSpec::from_json_bytes(
82 &include_bytes!("../../chain-specs/asset-hub-rococo.json")[..],
83 )?),
84
85 "asset-hub-westend-dev" | "westmint-dev" => {
87 Box::new(asset_hubs::asset_hub_westend_development_config())
88 },
89 "asset-hub-westend-local" | "westmint-local" => {
90 Box::new(asset_hubs::asset_hub_westend_local_config())
91 },
92 "asset-hub-westend-genesis" | "westmint-genesis" => {
94 Box::new(asset_hubs::asset_hub_westend_config())
95 },
96 "asset-hub-westend" | "westmint" => Box::new(GenericChainSpec::from_json_bytes(
98 &include_bytes!("../../chain-specs/asset-hub-westend.json")[..],
99 )?),
100
101 "collectives-polkadot" => Box::new(GenericChainSpec::from_json_bytes(
103 &include_bytes!("../../chain-specs/collectives-polkadot.json")[..],
104 )?),
105
106 "collectives-westend-dev" => {
108 Box::new(collectives::collectives_westend_development_config())
109 },
110 "collectives-westend-local" => {
111 Box::new(collectives::collectives_westend_local_config())
112 },
113 "collectives-westend" => Box::new(GenericChainSpec::from_json_bytes(
114 &include_bytes!("../../chain-specs/collectives-westend.json")[..],
115 )?),
116
117 bridge_like_id
119 if bridge_like_id.starts_with(bridge_hubs::BridgeHubRuntimeType::ID_PREFIX) =>
120 {
121 bridge_like_id
122 .parse::<bridge_hubs::BridgeHubRuntimeType>()
123 .expect("invalid value")
124 .load_config()?
125 },
126
127 coretime_like_id
129 if coretime_like_id.starts_with(coretime::CoretimeRuntimeType::ID_PREFIX) =>
130 {
131 coretime_like_id
132 .parse::<coretime::CoretimeRuntimeType>()
133 .expect("invalid value")
134 .load_config()?
135 },
136
137 id if id.starts_with("penpal-rococo") => {
139 let (_, _, para_id) = extract_parachain_id(&id, &["penpal-rococo-"]);
140 Box::new(penpal::get_penpal_chain_spec(
141 para_id.expect("Must specify parachain id"),
142 "rococo-local",
143 ))
144 },
145 id if id.starts_with("penpal-westend") => {
146 let (_, _, para_id) = extract_parachain_id(&id, &["penpal-westend-"]);
147 Box::new(penpal::get_penpal_chain_spec(
148 para_id.expect("Must specify parachain id"),
149 "westend-local",
150 ))
151 },
152
153 id if id.starts_with("glutton-westend-dev") => {
155 let (_, _, para_id) = extract_parachain_id(&id, &["glutton-westend-dev-"]);
156 Box::new(glutton::glutton_westend_config(
157 para_id.expect("Must specify parachain id"),
158 ChainType::Development,
159 "westend-dev",
160 ))
161 },
162 id if id.starts_with("glutton-westend-local") => {
163 let (_, _, para_id) = extract_parachain_id(&id, &["glutton-westend-local-"]);
164 Box::new(glutton::glutton_westend_config(
165 para_id.expect("Must specify parachain id"),
166 ChainType::Local,
167 "westend-local",
168 ))
169 },
170 id if id.starts_with("glutton-westend-genesis") => {
172 let (_, _, para_id) = extract_parachain_id(&id, &["glutton-westend-genesis-"]);
173 Box::new(glutton::glutton_westend_config(
174 para_id.expect("Must specify parachain id"),
175 ChainType::Live,
176 "westend",
177 ))
178 },
179
180 id if id.starts_with("yap-") => {
181 let tok: Vec<String> = id.split('-').map(|s| s.to_owned()).collect();
182 assert!(
183 tok.len() == 4,
184 "Invalid YAP chain id, should be 'yap-<relay>-<chaintype>-<para-id>'"
185 );
186 let relay = if &tok[2] == "live" { tok[1].clone() } else { tok[1..=2].join("-") };
187 let chain_type = match tok[2].as_str() {
188 "local" => ChainType::Local,
189 "dev" => ChainType::Development,
190 "live" => ChainType::Live,
191 _ => unimplemented!("Unknown chain type {}", tok[2]),
192 };
193 let para_id: u32 =
194 tok[3].parse().expect(&format!("Illegal para id '{}' provided", tok[3]));
195
196 Box::new(yet_another_parachain_config(relay, chain_type, para_id))
197 },
198
199 people_like_id if people_like_id.starts_with(people::PeopleRuntimeType::ID_PREFIX) => {
201 people_like_id
202 .parse::<people::PeopleRuntimeType>()
203 .expect("invalid value")
204 .load_config()?
205 },
206
207 "" => {
209 log::warn!(
210 "No ChainSpec.id specified, so using default one, based on Penpal runtime"
211 );
212 Box::new(penpal::staging_penpal_local_config())
213 },
214
215 path => Box::new(GenericChainSpec::from_json_file(path.into())?),
217 })
218 }
219}