polkadot_service/
chain_spec.rs1#[cfg(feature = "rococo-native")]
20use rococo_runtime as rococo;
21use sc_chain_spec::ChainSpecExtension;
22#[cfg(any(feature = "westend-native", feature = "rococo-native"))]
23use sc_chain_spec::ChainType;
24#[cfg(any(feature = "westend-native", feature = "rococo-native"))]
25use sc_telemetry::TelemetryEndpoints;
26use serde::{Deserialize, Serialize};
27#[cfg(feature = "westend-native")]
28use westend_runtime as westend;
29
30#[cfg(feature = "westend-native")]
31const WESTEND_STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
32#[cfg(feature = "rococo-native")]
33const ROCOCO_STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
34#[cfg(feature = "rococo-native")]
35const VERSI_STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
36#[cfg(any(feature = "westend-native", feature = "rococo-native"))]
37const DEFAULT_PROTOCOL_ID: &str = "dot";
38
39#[derive(Default, Clone, Serialize, Deserialize, ChainSpecExtension)]
44#[serde(rename_all = "camelCase")]
45pub struct Extensions {
46 pub fork_blocks: sc_client_api::ForkBlocks<polkadot_primitives::Block>,
48 pub bad_blocks: sc_client_api::BadBlocks<polkadot_primitives::Block>,
50 pub light_sync_state: sc_sync_state_rpc::LightSyncStateExtension,
54}
55
56pub type GenericChainSpec = sc_service::GenericChainSpec<Extensions>;
58
59#[cfg(feature = "westend-native")]
61pub type WestendChainSpec = sc_service::GenericChainSpec<Extensions>;
62
63#[cfg(not(feature = "westend-native"))]
66pub type WestendChainSpec = GenericChainSpec;
67
68#[cfg(feature = "rococo-native")]
70pub type RococoChainSpec = sc_service::GenericChainSpec<Extensions>;
71
72#[cfg(not(feature = "rococo-native"))]
75pub type RococoChainSpec = GenericChainSpec;
76
77pub fn polkadot_config() -> Result<GenericChainSpec, String> {
78 GenericChainSpec::from_json_bytes(&include_bytes!("../chain-specs/polkadot.json")[..])
79}
80
81pub fn kusama_config() -> Result<GenericChainSpec, String> {
82 GenericChainSpec::from_json_bytes(&include_bytes!("../chain-specs/kusama.json")[..])
83}
84
85pub fn westend_config() -> Result<WestendChainSpec, String> {
86 WestendChainSpec::from_json_bytes(&include_bytes!("../chain-specs/westend.json")[..])
87}
88
89pub fn paseo_config() -> Result<GenericChainSpec, String> {
90 GenericChainSpec::from_json_bytes(&include_bytes!("../chain-specs/paseo.json")[..])
91}
92
93pub fn rococo_config() -> Result<RococoChainSpec, String> {
94 RococoChainSpec::from_json_bytes(&include_bytes!("../chain-specs/rococo.json")[..])
95}
96
97#[cfg(feature = "westend-native")]
99pub fn westend_staging_testnet_config() -> Result<WestendChainSpec, String> {
100 Ok(WestendChainSpec::builder(
101 westend::WASM_BINARY.ok_or("Westend development wasm not available")?,
102 Default::default(),
103 )
104 .with_name("Westend Staging Testnet")
105 .with_id("westend_staging_testnet")
106 .with_chain_type(ChainType::Live)
107 .with_genesis_config_preset_name("staging_testnet")
108 .with_telemetry_endpoints(
109 TelemetryEndpoints::new(vec![(WESTEND_STAGING_TELEMETRY_URL.to_string(), 0)])
110 .expect("Westend Staging telemetry url is valid; qed"),
111 )
112 .with_protocol_id(DEFAULT_PROTOCOL_ID)
113 .build())
114}
115
116#[cfg(feature = "rococo-native")]
118pub fn rococo_staging_testnet_config() -> Result<RococoChainSpec, String> {
119 Ok(RococoChainSpec::builder(
120 rococo::WASM_BINARY.ok_or("Rococo development wasm not available")?,
121 Default::default(),
122 )
123 .with_name("Rococo Staging Testnet")
124 .with_id("rococo_staging_testnet")
125 .with_chain_type(ChainType::Live)
126 .with_genesis_config_preset_name("staging_testnet")
127 .with_telemetry_endpoints(
128 TelemetryEndpoints::new(vec![(ROCOCO_STAGING_TELEMETRY_URL.to_string(), 0)])
129 .expect("Rococo Staging telemetry url is valid; qed"),
130 )
131 .with_protocol_id(DEFAULT_PROTOCOL_ID)
132 .build())
133}
134
135pub fn versi_chain_spec_properties() -> serde_json::map::Map<String, serde_json::Value> {
136 serde_json::json!({
137 "ss58Format": 42,
138 "tokenDecimals": 12,
139 "tokenSymbol": "VRS",
140 })
141 .as_object()
142 .expect("Map given; qed")
143 .clone()
144}
145
146#[cfg(feature = "rococo-native")]
148pub fn versi_staging_testnet_config() -> Result<RococoChainSpec, String> {
149 Ok(RococoChainSpec::builder(
150 rococo::WASM_BINARY.ok_or("Versi development wasm not available")?,
151 Default::default(),
152 )
153 .with_name("Versi Staging Testnet")
154 .with_id("versi_staging_testnet")
155 .with_chain_type(ChainType::Live)
156 .with_genesis_config_preset_name("staging_testnet")
157 .with_telemetry_endpoints(
158 TelemetryEndpoints::new(vec![(VERSI_STAGING_TELEMETRY_URL.to_string(), 0)])
159 .expect("Versi Staging telemetry url is valid; qed"),
160 )
161 .with_protocol_id("versi")
162 .with_properties(versi_chain_spec_properties())
163 .build())
164}
165
166#[cfg(feature = "westend-native")]
168pub fn westend_development_config() -> Result<WestendChainSpec, String> {
169 Ok(WestendChainSpec::builder(
170 westend::WASM_BINARY.ok_or("Westend development wasm not available")?,
171 Default::default(),
172 )
173 .with_name("Development")
174 .with_id("westend_dev")
175 .with_chain_type(ChainType::Development)
176 .with_genesis_config_preset_name(sp_genesis_builder::DEV_RUNTIME_PRESET)
177 .with_protocol_id(DEFAULT_PROTOCOL_ID)
178 .build())
179}
180
181#[cfg(feature = "rococo-native")]
183pub fn rococo_development_config() -> Result<RococoChainSpec, String> {
184 Ok(RococoChainSpec::builder(
185 rococo::WASM_BINARY.ok_or("Rococo development wasm not available")?,
186 Default::default(),
187 )
188 .with_name("Development")
189 .with_id("rococo_dev")
190 .with_chain_type(ChainType::Development)
191 .with_genesis_config_preset_name(sp_genesis_builder::DEV_RUNTIME_PRESET)
192 .with_protocol_id(DEFAULT_PROTOCOL_ID)
193 .build())
194}
195
196#[cfg(feature = "rococo-native")]
198pub fn versi_development_config() -> Result<RococoChainSpec, String> {
199 Ok(RococoChainSpec::builder(
200 rococo::WASM_BINARY.ok_or("Versi development wasm not available")?,
201 Default::default(),
202 )
203 .with_name("Development")
204 .with_id("versi_dev")
205 .with_chain_type(ChainType::Development)
206 .with_genesis_config_preset_name(sp_genesis_builder::DEV_RUNTIME_PRESET)
207 .with_protocol_id("versi")
208 .build())
209}
210
211#[cfg(feature = "westend-native")]
213pub fn westend_local_testnet_config() -> Result<WestendChainSpec, String> {
214 Ok(WestendChainSpec::builder(
215 westend::fast_runtime_binary::WASM_BINARY
216 .ok_or("Westend development wasm not available")?,
217 Default::default(),
218 )
219 .with_name("Westend Local Testnet")
220 .with_id("westend_local_testnet")
221 .with_chain_type(ChainType::Local)
222 .with_genesis_config_preset_name(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET)
223 .with_protocol_id(DEFAULT_PROTOCOL_ID)
224 .build())
225}
226
227#[cfg(feature = "rococo-native")]
229pub fn rococo_local_testnet_config() -> Result<RococoChainSpec, String> {
230 Ok(RococoChainSpec::builder(
231 rococo::fast_runtime_binary::WASM_BINARY.ok_or("Rococo development wasm not available")?,
232 Default::default(),
233 )
234 .with_name("Rococo Local Testnet")
235 .with_id("rococo_local_testnet")
236 .with_chain_type(ChainType::Local)
237 .with_genesis_config_preset_name(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET)
238 .with_protocol_id(DEFAULT_PROTOCOL_ID)
239 .build())
240}
241
242#[cfg(feature = "rococo-native")]
244pub fn versi_local_testnet_config() -> Result<RococoChainSpec, String> {
245 Ok(RococoChainSpec::builder(
246 rococo::WASM_BINARY.ok_or("Rococo development wasm (used for versi) not available")?,
247 Default::default(),
248 )
249 .with_name("Versi Local Testnet")
250 .with_id("versi_local_testnet")
251 .with_chain_type(ChainType::Local)
252 .with_genesis_config_preset_name("versi_local_testnet")
253 .with_protocol_id("versi")
254 .build())
255}