Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit d066c02

Browse files
committed
Add a runtime_version function to SubstrateCli
1 parent 0ad4e40 commit d066c02

File tree

7 files changed

+29
-19
lines changed

7 files changed

+29
-19
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/node-template/node/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ sp-finality-grandpa = { version = "2.0.0-rc3", path = "../../../primitives/final
3838
sc-client-api = { version = "2.0.0-rc3", path = "../../../client/api" }
3939
sp-runtime = { version = "2.0.0-rc3", path = "../../../primitives/runtime" }
4040
sc-basic-authorship = { path = "../../../client/basic-authorship", version = "0.8.0-rc3"}
41+
sp-version = { version = "2.0.0-rc3", path = "../../../primitives/version" }
4142

4243
node-template-runtime = { version = "2.0.0-rc3", path = "../runtime" }
4344

bin/node-template/node/src/command.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::cli::Cli;
2020
use crate::service;
2121
use sc_cli::SubstrateCli;
2222
use sc_service::Role;
23+
use sp_version::RuntimeVersion;
2324

2425
impl SubstrateCli for Cli {
2526
fn impl_name() -> &'static str {
@@ -59,6 +60,10 @@ impl SubstrateCli for Cli {
5960
)?),
6061
})
6162
}
63+
64+
fn runtime_version() -> &'static RuntimeVersion {
65+
&node_template_runtime::VERSION
66+
}
6267
}
6368

6469
/// Parse and run command line arguments
@@ -72,13 +77,10 @@ pub fn run() -> sc_cli::Result<()> {
7277
}
7378
None => {
7479
let runner = cli.create_runner(&cli.run)?;
75-
runner.run_node_until_exit(
76-
|config| match config.role {
77-
Role::Light => service::new_light(config),
78-
_ => service::new_full(config),
79-
},
80-
node_template_runtime::VERSION,
81-
)
80+
runner.run_node_until_exit(|config| match config.role {
81+
Role::Light => service::new_light(config),
82+
_ => service::new_full(config),
83+
})
8284
}
8385
}
8486
}

bin/node/cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ sp-keyring = { version = "2.0.0-rc3", path = "../../../primitives/keyring" }
5858
sp-io = { version = "2.0.0-rc3", path = "../../../primitives/io" }
5959
sp-consensus = { version = "0.8.0-rc3", path = "../../../primitives/consensus/common" }
6060
sp-transaction-pool = { version = "2.0.0-rc3", path = "../../../primitives/transaction-pool" }
61+
sp-version = { version = "2.0.0-rc3", path = "../../../primitives/version" }
6162

6263
# client dependencies
6364
sc-client-api = { version = "2.0.0-rc3", path = "../../../client/api" }

bin/node/cli/src/command.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use node_executor::Executor;
2121
use node_runtime::{Block, RuntimeApi};
2222
use sc_cli::{Result, SubstrateCli};
2323
use sc_service::Role;
24+
use sp_version::RuntimeVersion;
2425

2526
impl SubstrateCli for Cli {
2627
fn impl_name() -> &'static str {
@@ -62,6 +63,10 @@ impl SubstrateCli for Cli {
6263
)?),
6364
})
6465
}
66+
67+
fn runtime_version() -> &'static RuntimeVersion {
68+
&node_runtime::VERSION
69+
}
6570
}
6671

6772
/// Parse command line arguments into service configuration.
@@ -71,13 +76,10 @@ pub fn run() -> Result<()> {
7176
match &cli.subcommand {
7277
None => {
7378
let runner = cli.create_runner(&cli.run)?;
74-
runner.run_node_until_exit(
75-
|config| match config.role {
76-
Role::Light => service::new_light(config),
77-
_ => service::new_full(config),
78-
},
79-
node_runtime::VERSION,
80-
)
79+
runner.run_node_until_exit(|config| match config.role {
80+
Role::Light => service::new_light(config),
81+
_ => service::new_full(config),
82+
})
8183
}
8284
Some(Subcommand::Inspect(cmd)) => {
8385
let runner = cli.create_runner(cmd)?;

client/cli/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pub use params::*;
3838
use regex::Regex;
3939
pub use runner::*;
4040
use sc_service::{ChainSpec, Configuration, TaskExecutor};
41+
use sp_version::RuntimeVersion;
4142
use std::io::Write;
4243
pub use structopt;
4344
use structopt::{
@@ -207,6 +208,9 @@ pub trait SubstrateCli: Sized {
207208
command.init::<Self>()?;
208209
Runner::new(self, command)
209210
}
211+
212+
/// Runtime version.
213+
fn runtime_version() -> &'static RuntimeVersion;
210214
}
211215

212216
/// Initialize the logger

client/cli/src/runner.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ use log::info;
2828
use sc_service::{Configuration, ServiceBuilderCommand, TaskType, TaskManager};
2929
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
3030
use sp_utils::metrics::{TOKIO_THREADS_ALIVE, TOKIO_THREADS_TOTAL};
31-
use sp_version::RuntimeVersion;
3231
use std::{fmt::Debug, marker::PhantomData, str::FromStr};
3332

3433
#[cfg(target_family = "unix")]
@@ -153,7 +152,7 @@ impl<C: SubstrateCli> Runner<C> {
153152
/// 2020-06-03 16:14:21 💾 Database: RocksDb at /tmp/c/chains/flamingfir7/db
154153
/// 2020-06-03 16:14:21 ⛓ Native runtime: node-251 (substrate-node-1.tx1.au10)
155154
/// ```
156-
fn print_node_infos(&self, runtime_version: RuntimeVersion) {
155+
fn print_node_infos(&self) {
157156
info!("{}", C::impl_name());
158157
info!("✌️ version {}", C::impl_version());
159158
info!(
@@ -169,7 +168,7 @@ impl<C: SubstrateCli> Runner<C> {
169168
self.config.database,
170169
self.config.database.path().map_or_else(|| "<unknown>".to_owned(), |p| p.display().to_string())
171170
);
172-
info!("⛓ Native runtime: {}", runtime_version);
171+
info!("⛓ Native runtime: {}", C::runtime_version());
173172
}
174173

175174
/// A helper function that runs a future with tokio and stops if the process receives the signal
@@ -205,9 +204,8 @@ impl<C: SubstrateCli> Runner<C> {
205204
pub fn run_node_until_exit(
206205
mut self,
207206
initialise: impl FnOnce(Configuration) -> sc_service::error::Result<TaskManager>,
208-
runtime_version: RuntimeVersion,
209207
) -> Result<()> {
210-
self.print_node_infos(runtime_version);
208+
self.print_node_infos();
211209
let mut task_manager = initialise(self.config)?;
212210
self.tokio_runtime.block_on(main(task_manager.future().fuse()))
213211
.map_err(|e| e.to_string())?;

0 commit comments

Comments
 (0)