From 2a700101dda1c17550cae720774f934fde8f85be Mon Sep 17 00:00:00 2001 From: Uncle Stretch Date: Sun, 7 Dec 2025 14:11:28 +0300 Subject: [PATCH] show current validators and upcoming validators on top bar Signed-off-by: Uncle Stretch --- Cargo.toml | 2 +- src/action.rs | 2 +- src/components/health.rs | 18 ++++++++++++------ src/network/predefined_calls.rs | 8 ++++++-- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bfc73f5..80eb3a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "ghost-eye" authors = ["str3tch "] description = "Application for interacting with Casper/Ghost nodes that are exposing RPC only to the localhost" -version = "0.3.83" +version = "0.3.84" edition = "2021" homepage = "https://git.ghostchain.io/ghostchain" repository = "https://git.ghostchain.io/ghostchain/ghost-eye" diff --git a/src/action.rs b/src/action.rs index b23b185..ac4c3b0 100644 --- a/src/action.rs +++ b/src/action.rs @@ -77,7 +77,7 @@ pub enum Action { NewFinalizedHash(H256), BestBlockUpdated(u32), ExtrinsicsLength(u32, usize), - ValidatorsNumber(u32), + ValidatorsNumber(u32, u32), NominatorsNumber(u32), Inflation(String), Apy(String), diff --git a/src/components/health.rs b/src/components/health.rs index f5fde87..464e656 100644 --- a/src/components/health.rs +++ b/src/components/health.rs @@ -20,7 +20,8 @@ pub struct Health { is_syncing: bool, should_have_peers: bool, tx_pool_length: usize, - validators_count: u32, + next_validators_count: u32, + current_validators_count: u32, nominators_count: u32, } @@ -38,7 +39,8 @@ impl Health { is_syncing: true, should_have_peers: false, tx_pool_length: 0, - validators_count: 0, + next_validators_count: 0, + current_validators_count: 0, nominators_count: 0, } } @@ -77,7 +79,10 @@ impl Component for Health { Action::SetNodeName(name) => self.name = name, Action::SetPendingExtrinsicsLength(length) => self.tx_pool_length = length, Action::NominatorsNumber(number) => self.nominators_count = number, - Action::ValidatorsNumber(number) => self.validators_count = number, + Action::ValidatorsNumber(current, next) => { + self.current_validators_count = current; + self.next_validators_count = next; + } _ => {} }; Ok(None) @@ -86,13 +91,14 @@ impl Component for Health { fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> { let [place, _] = super::layouts::header_layout(area); - let message = format!("{:^12} | tx.pool: {:^3} | peers: {:^3} | {:^9} | validators {:^4} | nominators {:^4} |", + let message = format!("{:^12} | tx.pool: {:^3} | peers: {:^3} | {:^9} | validators {:^4}({}) | nominators {:^4} |", self.name_as_string(), self.tx_pool_length, self.peers_as_string(), self.is_syncing_as_string(), - self.validators_count + 1, - self.nominators_count + 1); + self.current_validators_count, + self.next_validators_count, + self.nominators_count); let span = Span::styled(message, Style::new().dim()); let paragraph = Paragraph::new(span).left_aligned(); diff --git a/src/network/predefined_calls.rs b/src/network/predefined_calls.rs index 9ad2989..6bf7320 100644 --- a/src/network/predefined_calls.rs +++ b/src/network/predefined_calls.rs @@ -158,10 +158,14 @@ pub async fn get_validators_number( action_tx: &UnboundedSender, api: &OnlineClient, ) -> Result<()> { - let counter_for_validators = super::raw_calls::staking::counter_for_validators(api, None) + let next_validators_count = super::raw_calls::staking::counter_for_validators(api, None) .await? .unwrap_or_default(); - action_tx.send(Action::ValidatorsNumber(counter_for_validators))?; + let current_validators_count = super::raw_calls::session::validators(api, None) + .await? + .map(|validators| validators.len() as u32) + .unwrap_or_default(); + action_tx.send(Action::ValidatorsNumber(current_validators_count, next_validators_count))?; Ok(()) }