polkadot_parachain/chain_spec/
coretime.rs1use polkadot_omni_node_lib::chain_spec::GenericChainSpec;
18use sc_chain_spec::{ChainSpec, ChainType};
19use std::{borrow::Cow, str::FromStr};
20
21#[derive(Debug, PartialEq, Clone, Copy)]
23pub enum CoretimeRuntimeType {
24 Kusama,
25 KusamaLocal,
26
27 Polkadot,
28 PolkadotLocal,
29
30 Westend,
32 WestendLocal,
34 WestendDevelopment,
36}
37
38impl FromStr for CoretimeRuntimeType {
39 type Err = String;
40
41 fn from_str(value: &str) -> Result<Self, Self::Err> {
42 match value {
43 kusama::CORETIME_KUSAMA => Ok(CoretimeRuntimeType::Kusama),
44 kusama::CORETIME_KUSAMA_LOCAL => Ok(CoretimeRuntimeType::KusamaLocal),
45 polkadot::CORETIME_POLKADOT => Ok(CoretimeRuntimeType::Polkadot),
46 polkadot::CORETIME_POLKADOT_LOCAL => Ok(CoretimeRuntimeType::PolkadotLocal),
47 westend::CORETIME_WESTEND => Ok(CoretimeRuntimeType::Westend),
48 westend::CORETIME_WESTEND_LOCAL => Ok(CoretimeRuntimeType::WestendLocal),
49 westend::CORETIME_WESTEND_DEVELOPMENT => Ok(CoretimeRuntimeType::WestendDevelopment),
50 _ => Err(format!("Value '{}' is not configured yet", value)),
51 }
52 }
53}
54
55impl From<CoretimeRuntimeType> for &str {
56 fn from(runtime_type: CoretimeRuntimeType) -> Self {
57 match runtime_type {
58 CoretimeRuntimeType::Kusama => kusama::CORETIME_KUSAMA,
59 CoretimeRuntimeType::KusamaLocal => kusama::CORETIME_KUSAMA_LOCAL,
60 CoretimeRuntimeType::Polkadot => polkadot::CORETIME_POLKADOT,
61 CoretimeRuntimeType::PolkadotLocal => polkadot::CORETIME_POLKADOT_LOCAL,
62 CoretimeRuntimeType::Westend => westend::CORETIME_WESTEND,
63 CoretimeRuntimeType::WestendLocal => westend::CORETIME_WESTEND_LOCAL,
64 CoretimeRuntimeType::WestendDevelopment => westend::CORETIME_WESTEND_DEVELOPMENT,
65 }
66 }
67}
68
69impl From<CoretimeRuntimeType> for ChainType {
70 fn from(runtime_type: CoretimeRuntimeType) -> Self {
71 match runtime_type {
72 CoretimeRuntimeType::Kusama |
73 CoretimeRuntimeType::Polkadot |
74 CoretimeRuntimeType::Westend => ChainType::Live,
75 CoretimeRuntimeType::KusamaLocal |
76 CoretimeRuntimeType::PolkadotLocal |
77 CoretimeRuntimeType::WestendLocal => ChainType::Local,
78 CoretimeRuntimeType::WestendDevelopment => ChainType::Development,
79 }
80 }
81}
82
83impl CoretimeRuntimeType {
84 pub const ID_PREFIX: &'static str = "coretime";
85
86 pub fn load_config(&self) -> Result<Box<dyn ChainSpec>, String> {
87 match self {
88 CoretimeRuntimeType::Kusama => Ok(Box::new(GenericChainSpec::from_json_bytes(
89 &include_bytes!("../../chain-specs/coretime-kusama.json")[..],
90 )?)),
91 CoretimeRuntimeType::Polkadot => Ok(Box::new(GenericChainSpec::from_json_bytes(
92 &include_bytes!("../../chain-specs/coretime-polkadot.json")[..],
93 )?)),
94 CoretimeRuntimeType::Westend => Ok(Box::new(GenericChainSpec::from_json_bytes(
95 &include_bytes!("../../../parachains/chain-specs/coretime-westend.json")[..],
96 )?)),
97 CoretimeRuntimeType::WestendLocal => {
98 Ok(Box::new(westend::local_config(*self, "westend-local")))
99 },
100 CoretimeRuntimeType::WestendDevelopment => {
101 Ok(Box::new(westend::local_config(*self, "westend-dev")))
102 },
103 other => Err(std::format!(
104 "No default config present for {:?}, you should provide a chain-spec as json file!",
105 other
106 )),
107 }
108 }
109}
110
111pub fn chain_type_name(chain_type: &ChainType) -> Cow<'_, str> {
113 match chain_type {
114 ChainType::Development => "Development",
115 ChainType::Local => "Local",
116 ChainType::Live => "Live",
117 ChainType::Custom(name) => name,
118 }
119 .into()
120}
121
122pub mod westend {
124 use super::{chain_type_name, CoretimeRuntimeType, GenericChainSpec};
125 use polkadot_omni_node_lib::chain_spec::Extensions;
126 use sc_chain_spec::ChainType;
127
128 pub(crate) const CORETIME_WESTEND: &str = "coretime-westend";
129 pub(crate) const CORETIME_WESTEND_LOCAL: &str = "coretime-westend-local";
130 pub(crate) const CORETIME_WESTEND_DEVELOPMENT: &str = "coretime-westend-dev";
131
132 pub fn local_config(runtime_type: CoretimeRuntimeType, relay_chain: &str) -> GenericChainSpec {
133 let mut properties = sc_chain_spec::Properties::new();
135 properties.insert("ss58Format".into(), 42.into());
136 properties.insert("tokenSymbol".into(), "WND".into());
137 properties.insert("tokenDecimals".into(), 12.into());
138
139 let chain_type = runtime_type.into();
140 let chain_name = format!("Coretime Westend {}", chain_type_name(&chain_type));
141
142 GenericChainSpec::builder(
143 coretime_westend_runtime::WASM_BINARY
144 .expect("WASM binary was not built, please build it!"),
145 Extensions::new_with_relay_chain(relay_chain.to_string()),
146 )
147 .with_name(&chain_name)
148 .with_id(runtime_type.into())
149 .with_chain_type(chain_type.clone())
150 .with_genesis_config_preset_name(match chain_type {
151 ChainType::Development => sp_genesis_builder::DEV_RUNTIME_PRESET,
152 ChainType::Local => sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET,
153 _ => panic!("chain_type: {chain_type:?} not supported here!"),
154 })
155 .with_properties(properties)
156 .build()
157 }
158}
159
160pub mod kusama {
161 pub(crate) const CORETIME_KUSAMA: &str = "coretime-kusama";
162 pub(crate) const CORETIME_KUSAMA_LOCAL: &str = "coretime-kusama-local";
163}
164
165pub mod polkadot {
166 pub(crate) const CORETIME_POLKADOT: &str = "coretime-polkadot";
167 pub(crate) const CORETIME_POLKADOT_LOCAL: &str = "coretime-polkadot-local";
168}