mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 19:17:58 +00:00
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:
@@ -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())
|
||||
}
|
||||
|
||||
|
||||
@@ -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(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user