robonomics/
main.rs

1///////////////////////////////////////////////////////////////////////////////
2//
3//  Copyright 2018-2025 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#![warn(unused_extern_crates)]
19
20use polkadot_omni_node_lib::{
21    chain_spec::{ChainSpec, Extensions, GenericChainSpec, LoadSpec},
22    run,
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        format!(
33            "robonomics-{commit_hash} :: polkadot omni node v{}",
34            NODE_VERSION
35        )
36    }
37
38    fn author() -> String {
39        env!("CARGO_PKG_AUTHORS").into()
40    }
41
42    fn support_url() -> String {
43        "https://github.com/airalab/robonomics/issues/new".into()
44    }
45
46    fn copyright_start_year() -> u16 {
47        2018
48    }
49}
50
51fn robonomics_development_config() -> Result<GenericChainSpec, String> {
52    let config = GenericChainSpec::builder(
53        robonomics_runtime::WASM_BINARY.ok_or("wasm not available")?,
54        Extensions::new("westend-local".into(), 2048),
55    )
56    .with_name("Robonomics Local Develoment")
57    .with_id("robonomics-local-development")
58    .with_genesis_config_preset_name(sp_genesis_builder::DEV_RUNTIME_PRESET)
59    .build();
60    Ok(config)
61}
62
63/// OMNI chain spec loader with buildin robonomics chains.
64struct RobonomicsChainSpecLoader;
65
66impl LoadSpec for RobonomicsChainSpecLoader {
67    fn load_spec(&self, path: &str) -> Result<Box<dyn ChainSpec>, String> {
68        Ok(Box::new(match path {
69            "" | "polkadot" => GenericChainSpec::from_json_bytes(
70                &include_bytes!("../chains/polkadot-parachain.raw.json")[..],
71            )?,
72            "kusama" => GenericChainSpec::from_json_bytes(
73                &include_bytes!("../chains/kusama-parachain.raw.json")[..],
74            )?,
75            "dev" => robonomics_development_config()?,
76            path => GenericChainSpec::from_json_file(path.into())?,
77        }))
78    }
79}
80
81fn main() -> color_eyre::eyre::Result<()> {
82    color_eyre::install()?;
83
84    let config = RunConfig::new(
85        Box::new(DefaultRuntimeResolver),
86        Box::new(RobonomicsChainSpecLoader),
87    );
88    Ok(run::<CliConfig>(config)?)
89}