1use 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
73struct 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}