1use color_eyre::eyre::Result;
21use polkadot_omni_node_lib::{
22 chain_spec::{ChainSpec, GenericChainSpec, LoadSpec},
23 runtime::DefaultRuntimeResolver,
24 CliConfig as CliConfigT, RunConfig, NODE_VERSION,
25};
26
27struct CliConfig;
28
29impl CliConfigT for CliConfig {
30 fn impl_version() -> String {
31 let commit_hash = env!("SUBSTRATE_CLI_COMMIT_HASH");
32 let version = env!("CARGO_PKG_VERSION");
33 format!("{version}({commit_hash}) :: Polkadot {}", NODE_VERSION)
34 }
35
36 fn author() -> String {
37 env!("CARGO_PKG_AUTHORS").into()
38 }
39
40 fn support_url() -> String {
41 "https://github.com/airalab/robonomics/issues/new".into()
42 }
43
44 fn copyright_start_year() -> u16 {
45 2018
46 }
47}
48
49#[cfg(feature = "dev-runtime")]
50fn robonomics_development_config() -> Result<GenericChainSpec, String> {
51 let config = GenericChainSpec::builder(
52 robonomics_runtime::dev::WASM_BINARY.ok_or("wasm not available")?,
53 polkadot_omni_node_lib::chain_spec::Extensions::new("westend-local".into(), 2048),
54 )
55 .with_name("Robonomics Local Development")
56 .with_id("robonomics-local-development")
57 .with_genesis_config_preset_name(sp_genesis_builder::DEV_RUNTIME_PRESET)
58 .build();
59 Ok(config)
60}
61
62#[cfg(feature = "dev-runtime")]
63fn robonomics_localnet_config() -> Result<GenericChainSpec, String> {
64 let config = GenericChainSpec::builder(
65 robonomics_runtime::dev::WASM_BINARY.ok_or("wasm not available")?,
66 polkadot_omni_node_lib::chain_spec::Extensions::new("rococo-local".into(), 2000),
67 )
68 .with_name("Robonomics Localnet")
69 .with_id("robonomics-localnet")
70 .with_genesis_config_preset_name(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET)
71 .build();
72 Ok(config)
73}
74
75struct RobonomicsChainSpecLoader;
77
78impl LoadSpec for RobonomicsChainSpecLoader {
79 fn load_spec(&self, path: &str) -> Result<Box<dyn ChainSpec>, String> {
80 Ok(Box::new(match path {
81 "" | "polkadot" => GenericChainSpec::from_json_bytes(
82 &include_bytes!("../../chains/polkadot-parachain.raw.json")[..],
83 )?,
84 "kusama" => GenericChainSpec::from_json_bytes(
85 &include_bytes!("../../chains/kusama-parachain.raw.json")[..],
86 )?,
87 #[cfg(feature = "dev-runtime")]
88 "local" => robonomics_localnet_config()?,
89 #[cfg(feature = "dev-runtime")]
90 "dev" => robonomics_development_config()?,
91 path => GenericChainSpec::from_json_file(path.into())?,
92 }))
93 }
94}
95
96pub fn run() -> Result<()> {
97 let config = RunConfig::new(
98 Box::new(DefaultRuntimeResolver),
99 Box::new(RobonomicsChainSpecLoader),
100 );
101 Ok(polkadot_omni_node_lib::run::<CliConfig>(config)?)
102}