use massa_models::amount::Amount;
use massa_models::node::NodeId;
use massa_models::stats::{ConsensusStats, ExecutionStats, NetworkStats};
use massa_models::{config::CompactConfig, slot::Slot, version::Version};
use massa_time::MassaTime;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
use std::net::IpAddr;
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct NodeStatus {
pub node_id: NodeId,
pub node_ip: Option<IpAddr>,
pub version: Version,
pub current_time: MassaTime,
pub current_cycle: u64,
pub current_cycle_time: MassaTime,
pub next_cycle_time: MassaTime,
pub connected_nodes: BTreeMap<NodeId, (IpAddr, bool)>,
pub last_slot: Option<Slot>,
pub next_slot: Slot,
pub consensus_stats: ConsensusStats,
pub pool_stats: (usize, usize),
pub network_stats: NetworkStats,
pub execution_stats: ExecutionStats,
pub config: CompactConfig,
pub chain_id: u64,
pub minimal_fees: Amount,
pub current_mip_version: u32,
}
impl std::fmt::Display for NodeStatus {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "Node's ID: {}", self.node_id)?;
if self.node_ip.is_some() {
writeln!(f, "Node's IP: {}", self.node_ip.unwrap())?;
} else {
writeln!(f, "No routable IP set")?;
}
writeln!(f)?;
writeln!(f, "Version: {}", self.version)?;
writeln!(f, "Config:\n{}", self.config)?;
writeln!(f)?;
writeln!(f, "Current time: {}", self.current_time.format_instant())?;
writeln!(f, "Current cycle: {}", self.current_cycle)?;
if self.last_slot.is_some() {
writeln!(f, "Last slot: {}", self.last_slot.unwrap())?;
}
writeln!(f, "Next slot: {}", self.next_slot)?;
writeln!(f)?;
writeln!(f, "{}", self.consensus_stats)?;
writeln!(f, "Pool stats:")?;
writeln!(f, "\tOperations count: {}", self.pool_stats.0)?;
writeln!(f, "\tEndorsements count: {}", self.pool_stats.1)?;
writeln!(f)?;
writeln!(f, "{}", self.network_stats)?;
writeln!(f, "{}", self.execution_stats)?;
writeln!(f, "Connected nodes:")?;
for (node_id, (ip_addr, is_outgoing)) in &self.connected_nodes {
writeln!(
f,
"Node's ID: {} / IP address: {} / {} connection",
node_id,
ip_addr,
if *is_outgoing { "Out" } else { "In" }
)?
}
Ok(())
}
}