Chain type field (#3790)

* Adding chain type field into get_status rpc

* formatting
This commit is contained in:
aglkm 2024-09-12 23:03:51 +03:00 committed by GitHub
parent 9a23cfe483
commit 01b25650e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 6 additions and 1 deletions

View file

@ -49,6 +49,7 @@ pub trait OwnerRpc: Sync + Send {
"jsonrpc": "2.0", "jsonrpc": "2.0",
"result": { "result": {
"Ok": { "Ok": {
"chain": "main",
"protocol_version": "2", "protocol_version": "2",
"user_agent": "MW/Grin 2.x.x", "user_agent": "MW/Grin 2.x.x",
"connections": "8", "connections": "8",

View file

@ -16,7 +16,7 @@ use crate::chain;
use crate::core::core::hash::Hashed; use crate::core::core::hash::Hashed;
use crate::core::core::merkle_proof::MerkleProof; use crate::core::core::merkle_proof::MerkleProof;
use crate::core::core::{FeeFields, KernelFeatures, TxKernel}; use crate::core::core::{FeeFields, KernelFeatures, TxKernel};
use crate::core::{core, ser}; use crate::core::{core, global, ser};
use crate::p2p; use crate::p2p;
use crate::util::secp::pedersen; use crate::util::secp::pedersen;
use crate::util::{self, ToHex}; use crate::util::{self, ToHex};
@ -68,6 +68,8 @@ impl Tip {
/// Status page containing different server information /// Status page containing different server information
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Status { pub struct Status {
// The chain type
pub chain: String,
// The protocol version // The protocol version
pub protocol_version: u32, pub protocol_version: u32,
// The user user agent // The user user agent
@ -91,6 +93,7 @@ impl Status {
sync_info: Option<serde_json::Value>, sync_info: Option<serde_json::Value>,
) -> Status { ) -> Status {
Status { Status {
chain: global::get_chain_type().shortname(),
protocol_version: ser::ProtocolVersion::local().into(), protocol_version: ser::ProtocolVersion::local().into(),
user_agent: p2p::msg::USER_AGENT.to_string(), user_agent: p2p::msg::USER_AGENT.to_string(),
connections: connections, connections: connections,

View file

@ -92,6 +92,7 @@ impl HTTPNodeClient {
t.reset().unwrap(); t.reset().unwrap();
match self.send_json_request::<Status>("get_status", &serde_json::Value::Null) { match self.send_json_request::<Status>("get_status", &serde_json::Value::Null) {
Ok(status) => { Ok(status) => {
writeln!(e, "Chain type: {}", status.chain).unwrap();
writeln!(e, "Protocol version: {:?}", status.protocol_version).unwrap(); writeln!(e, "Protocol version: {:?}", status.protocol_version).unwrap();
writeln!(e, "User agent: {}", status.user_agent).unwrap(); writeln!(e, "User agent: {}", status.user_agent).unwrap();
writeln!(e, "Connections: {}", status.connections).unwrap(); writeln!(e, "Connections: {}", status.connections).unwrap();