robonomics/
cli.rs

1///////////////////////////////////////////////////////////////////////////////
2//
3//  Copyright 2018-2026 Robonomics Network <research@robonomics.network>
4//
5//  Licensed under the Apache License, Version 2.0 (the "License");
6//  you may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at
8//
9//      http://www.apache.org/licenses/LICENSE-2.0
10//
11//  Unless required by applicable law or agreed to in writing, software
12//  distributed under the License is distributed on an "AS IS" BASIS,
13//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14//  See the License for the specific language governing permissions and
15//  limitations under the License.
16//
17///////////////////////////////////////////////////////////////////////////////
18//! Robonomics CLI is based on Polkadot OMNI node
19
20use color_eyre::eyre::Result;
21use polkadot_omni_node_lib::{
22    chain_spec::{ChainSpec, Extensions, 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
49fn robonomics_development_config() -> Result<GenericChainSpec, String> {
50    let config = GenericChainSpec::builder(
51        robonomics_runtime::dev::WASM_BINARY.ok_or("wasm not available")?,
52        Extensions::new("westend-local".into(), 2048),
53    )
54    .with_name("Robonomics Local Develoment")
55    .with_id("robonomics-local-development")
56    .with_genesis_config_preset_name(sp_genesis_builder::DEV_RUNTIME_PRESET)
57    .build();
58    Ok(config)
59}
60
61fn robonomics_localnet_config() -> Result<GenericChainSpec, String> {
62    let config = GenericChainSpec::builder(
63        robonomics_runtime::dev::WASM_BINARY.ok_or("wasm not available")?,
64        Extensions::new("rococo-local".into(), 2000),
65    )
66    .with_name("Robonomics Localnet")
67    .with_id("robonomics-localnet")
68    .with_genesis_config_preset_name(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET)
69    .build();
70    Ok(config)
71}
72
73/// OMNI chain spec loader with buildin robonomics chains.
74struct RobonomicsChainSpecLoader;
75
76impl LoadSpec for RobonomicsChainSpecLoader {
77    fn load_spec(&self, path: &str) -> Result<Box<dyn ChainSpec>, String> {
78        Ok(Box::new(match path {
79            "" | "polkadot" => GenericChainSpec::from_json_bytes(
80                &include_bytes!("../../chains/polkadot-parachain.raw.json")[..],
81            )?,
82            "kusama" => GenericChainSpec::from_json_bytes(
83                &include_bytes!("../../chains/kusama-parachain.raw.json")[..],
84            )?,
85            "local" => robonomics_localnet_config()?,
86            "dev" => robonomics_development_config()?,
87            path => GenericChainSpec::from_json_file(path.into())?,
88        }))
89    }
90}
91
92pub fn run() -> Result<()> {
93    let config = RunConfig::new(
94        Box::new(DefaultRuntimeResolver),
95        Box::new(RobonomicsChainSpecLoader),
96    );
97    Ok(polkadot_omni_node_lib::run::<CliConfig>(config)?)
98}