Add new RPC method to get the chain type (#5576)

* Add new RPC method to get the chain type

This adds a new RPC method to get the chain type of the running chain.
The chain type needs to be specified in the chain spec. This should make
it easier for tools/UI to display extra information without needing to
rely on parsing the chain name.

* Update client/rpc-api/src/system/mod.rs

Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com>

* Primitive crate

* Feedback

Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
This commit is contained in:
Bastian Köcher
2020-04-08 20:41:51 +02:00
committed by GitHub
parent 1d2cbfbdf9
commit 7cdfaff12b
19 changed files with 135 additions and 26 deletions
+6 -2
View File
@@ -28,7 +28,7 @@ use sp_runtime::traits::{self, Header as HeaderT};
use self::error::Result;
pub use sc_rpc_api::system::*;
pub use self::helpers::{Properties, SystemInfo, Health, PeerInfo, NodeRole};
pub use self::helpers::{SystemInfo, Health, PeerInfo, NodeRole};
pub use self::gen_client::Client as SystemClient;
/// System API implementation
@@ -82,7 +82,11 @@ impl<B: traits::Block> SystemApi<B::Hash, <B::Header as HeaderT>::Number> for Sy
Ok(self.info.chain_name.clone())
}
fn system_properties(&self) -> Result<Properties> {
fn system_type(&self) -> Result<sp_chain_spec::ChainType> {
Ok(self.info.chain_type.clone())
}
fn system_properties(&self) -> Result<sp_chain_spec::Properties> {
Ok(self.info.properties.clone())
}
+13 -4
View File
@@ -105,6 +105,7 @@ fn api<T: Into<Option<Status>>>(sync: T) -> System<Block> {
impl_version: "0.2.0".into(),
chain_name: "testchain".into(),
properties: Default::default(),
chain_type: Default::default(),
}, tx)
}
@@ -117,7 +118,7 @@ fn wait_receiver<T>(rx: Receiver<T>) -> T {
fn system_name_works() {
assert_eq!(
api(None).system_name().unwrap(),
"testclient".to_owned()
"testclient".to_owned(),
);
}
@@ -125,7 +126,7 @@ fn system_name_works() {
fn system_version_works() {
assert_eq!(
api(None).system_version().unwrap(),
"0.2.0".to_owned()
"0.2.0".to_owned(),
);
}
@@ -133,7 +134,7 @@ fn system_version_works() {
fn system_chain_works() {
assert_eq!(
api(None).system_chain().unwrap(),
"testchain".to_owned()
"testchain".to_owned(),
);
}
@@ -141,7 +142,15 @@ fn system_chain_works() {
fn system_properties_works() {
assert_eq!(
api(None).system_properties().unwrap(),
serde_json::map::Map::new()
serde_json::map::Map::new(),
);
}
#[test]
fn system_type_works() {
assert_eq!(
api(None).system_type().unwrap(),
Default::default(),
);
}