From c7cdafe3b61d8bc37bc8c2b083a175811383e888 Mon Sep 17 00:00:00 2001 From: Uncle Stretch Date: Fri, 14 Feb 2025 16:39:27 +0300 Subject: [PATCH] validator details from nominator page added Signed-off-by: Uncle Stretch --- Cargo.toml | 2 +- src/action.rs | 25 +-- .../nominator/current_validator_details.rs | 154 ++++++++++++++++++ .../nominator/current_validators.rs | 53 +++--- src/components/nominator/event_log.rs | 2 +- src/components/nominator/mod.rs | 7 +- .../nominator/rename_known_validator.rs | 2 +- src/components/validator/nominators.rs | 6 +- src/components/validator/reward_details.rs | 5 +- src/components/validator/staking_details.rs | 5 +- src/components/validator/stash_info.rs | 18 +- src/network/mod.rs | 76 +++++---- src/network/predefined_calls.rs | 6 +- 13 files changed, 276 insertions(+), 85 deletions(-) create mode 100644 src/components/nominator/current_validator_details.rs diff --git a/Cargo.toml b/Cargo.toml index be001cc..aa808ea 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.23" +version = "0.3.24" edition = "2021" [dependencies] diff --git a/src/action.rs b/src/action.rs index 51a8452..f77686d 100644 --- a/src/action.rs +++ b/src/action.rs @@ -84,8 +84,8 @@ pub enum Action { GetChainVersion, GetPendingExtrinsics, GetConnectedPeers, - GetSessionKeys([u8; 32]), - GetQueuedSessionKeys([u8; 32]), + GetSessionKeys([u8; 32], bool), + GetQueuedSessionKeys([u8; 32], bool), GetListenAddresses, GetLocalIdentity, @@ -97,13 +97,13 @@ pub enum Action { GetValidatorsNumber, GetNominatorsNumber, GetInflation, - GetNominatorsByValidator([u8; 32]), - GetValidatorAllRewards([u8; 32]), - GetValidatorLedger([u8; 32]), - GetIsStashBonded([u8; 32]), - GetErasStakersOverview([u8; 32]), - GetValidatorPrefs([u8; 32]), - GetSlashingSpans([u8; 32]), + GetNominatorsByValidator([u8; 32], bool), + GetValidatorAllRewards([u8; 32], bool), + GetValidatorLedger([u8; 32], bool), + GetIsStashBonded([u8; 32], bool), + GetErasStakersOverview([u8; 32], bool), + GetValidatorPrefs([u8; 32], bool), + GetSlashingSpans([u8; 32], bool), GetCurrentValidatorEraRewards, SetNodeName(Option), @@ -113,6 +113,7 @@ pub enum Action { SetChainVersion(Option), SetStashAccount([u8; 32]), SetStashSecret([u8; 32]), + SetChoosenValidator([u8; 32], u32, u32), SetSlashingSpansLength(usize), SetUnlockingIsEmpty(bool), @@ -127,15 +128,15 @@ pub enum Action { SetSessionKey(String, SessionKeyInfo), SetListenAddresses(Vec), SetLocalIdentity(String), - SetNominatorsByValidator(Vec), + SetNominatorsByValidator(Vec, [u8; 32]), SetValidatorEraReward(u32, u128), SetValidatorEraClaimed(u32, bool), SetValidatorEraSlash(u32, u128), SetValidatorEraUnlocking(u32, u128), SetIsBonded(bool), SetStakedAmountRatio(u128, u128), - SetStakedRatio(u128, u128), - SetValidatorPrefs(u32, bool), + SetStakedRatio(u128, u128, [u8; 32]), + SetValidatorPrefs(u32, bool, [u8; 32]), SetCurrentValidatorEraRewards(u32, u32, Vec), GetTotalIssuance, diff --git a/src/components/nominator/current_validator_details.rs b/src/components/nominator/current_validator_details.rs new file mode 100644 index 0000000..16f5cb6 --- /dev/null +++ b/src/components/nominator/current_validator_details.rs @@ -0,0 +1,154 @@ +use std::sync::mpsc::Sender; + +use color_eyre::Result; +use ratatui::{ + layout::{Alignment, Constraint, Rect}, + text::Text, + widgets::{Block, Cell, Row, Table}, + Frame +}; + +use super::{Component, PartialComponent, CurrentTab}; +use crate::{action::Action, config::Config, palette::StylePalette}; + +#[derive(Debug)] +pub struct CurrentValidatorDetails { + network_tx: Option>, + is_active: bool, + palette: StylePalette, + choosen: [u8; 32], + total_balance: u128, + own_balance: u128, + others_len: usize, + commission: f64, + points_ratio: f64, +} + +impl Default for CurrentValidatorDetails { + fn default() -> Self { + Self::new() + } +} + +impl CurrentValidatorDetails { + const TICKER: &str = " CSPR"; + const DECIMALS: usize = 5; + + pub fn new() -> Self { + CurrentValidatorDetails { + network_tx: None, + is_active: false, + choosen: [0u8; 32], + total_balance: 0, + own_balance: 0, + others_len: 0, + commission: 0.0, + points_ratio: 0.0, + palette: Default::default(), + } + } + + fn prepare_u128(&self, value: u128) -> String { + let value = value as f64 / 10f64.powi(18); + let after = Self::DECIMALS; + format!("{:.after$}{}", value, Self::TICKER) + } + + fn update_choosen_validator(&mut self, account_id: [u8; 32], individual: u32, total: u32) { + self.choosen = account_id; + self.points_ratio = match total { + 0 => 0.0, + _ => individual as f64 / total as f64, + }; + if let Some(network_tx) = &self.network_tx { + let _ = network_tx.send(Action::GetErasStakersOverview(account_id, false)); + let _ = network_tx.send(Action::GetNominatorsByValidator(account_id, false)); + let _ = network_tx.send(Action::GetValidatorPrefs(account_id, false)); + } + } +} + +impl PartialComponent for CurrentValidatorDetails { + fn set_active(&mut self, _current_tab: CurrentTab) {} +} + +impl Component for CurrentValidatorDetails { + fn register_network_handler(&mut self, tx: Sender) -> Result<()> { + self.network_tx = Some(tx); + Ok(()) + } + + fn register_config_handler(&mut self, config: Config) -> Result<()> { + if let Some(style) = config.styles.get(&crate::app::Mode::Nominator) { + self.palette.with_normal_style(style.get("normal_style").copied()); + self.palette.with_hover_style(style.get("hover_style").copied()); + self.palette.with_normal_border_style(style.get("normal_border_style").copied()); + self.palette.with_hover_border_style(style.get("hover_border_style").copied()); + self.palette.with_normal_title_style(style.get("normal_title_style").copied()); + self.palette.with_hover_title_style(style.get("hover_title_style").copied()); + self.palette.with_highlight_style(style.get("highlight_style").copied()); + self.palette.with_scrollbar_style(style.get("scrollbar_style").copied()); + } + Ok(()) + } + + fn update(&mut self, action: Action) -> Result> { + match action { + Action::SetChoosenValidator(account_id, individual, total) => self.update_choosen_validator(account_id, individual, total), + Action::SetNominatorsByValidator(noms, account_id) if self.choosen == account_id => self.others_len = noms.len(), + Action::SetValidatorPrefs(commission, _, account_id) if self.choosen == account_id => + self.commission = commission as f64 / 1_000_000_000.0, + Action::SetStakedRatio(total, own, account_id) if self.choosen == account_id => { + self.total_balance = total; + self.own_balance = own; + }, + _ => {} + }; + Ok(None) + } + + fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> { + let [_, place] = super::validator_details_layout(area); + let (border_style, border_type) = self.palette.create_border_style(self.is_active); + + let table = Table::new( + vec![ + Row::new(vec![ + Cell::from(Text::from("Total staked".to_string()).alignment(Alignment::Left)), + Cell::from(Text::from(self.prepare_u128(self.total_balance)).alignment(Alignment::Right)), + ]), + Row::new(vec![ + Cell::from(Text::from("Own stake".to_string()).alignment(Alignment::Left)), + Cell::from(Text::from(self.prepare_u128(self.own_balance)).alignment(Alignment::Right)), + ]), + Row::new(vec![ + Cell::from(Text::from("Nominators".to_string()).alignment(Alignment::Left)), + Cell::from(Text::from(self.others_len.to_string()).alignment(Alignment::Right)), + ]), + Row::new(vec![ + Cell::from(Text::from("Commission".to_string()).alignment(Alignment::Left)), + Cell::from(Text::from(format!("{:.4}%", self.commission)).alignment(Alignment::Right)), + ]), + Row::new(vec![ + Cell::from(Text::from("Points ratio".to_string()).alignment(Alignment::Left)), + Cell::from(Text::from(format!("{:.4}%", self.points_ratio)).alignment(Alignment::Right)), + ]), + ], + [ + Constraint::Max(12), + Constraint::Min(0), + ], + ) + .column_spacing(1) + .highlight_style(self.palette.create_highlight_style()) + .block(Block::bordered() + .border_style(border_style) + .border_type(border_type) + .title_alignment(Alignment::Right) + .title_style(self.palette.create_title_style(false)) + .title("Validator details")); + + frame.render_widget(table, place); + Ok(()) + } +} diff --git a/src/components/nominator/current_validators.rs b/src/components/nominator/current_validators.rs index be792a7..0664c98 100644 --- a/src/components/nominator/current_validators.rs +++ b/src/components/nominator/current_validators.rs @@ -64,6 +64,15 @@ impl CurrentValidators { } } + fn update_choosen_details(&self, index: usize) { + if let Some(action_tx) = &self.action_tx { + let _ = action_tx.send(Action::SetChoosenValidator( + self.individual[index].account_id, + self.individual[index].points, + self.total_points)); + } + } + fn save_validator_name(&mut self, new_name: String) { if let Some(index) = self.table_state.selected() { let account_id = self.individual[index].account_id; @@ -88,25 +97,22 @@ impl CurrentValidators { } fn read_known_validators(&mut self, file_path: &PathBuf) -> Result<()> { - match File::open(file_path) { - Ok(file) => { - let reader = BufReader::new(file); - for line in reader.lines() { - let line = line?.replace("\n", ""); - let line_split_at = line.find(":").unwrap_or(line.len()); - let (name, seed) = line.split_at(line_split_at); - let seed_str = &seed[3..]; + if let Ok(file) = File::open(file_path) { + let reader = BufReader::new(file); + for line in reader.lines() { + let line = line?.replace("\n", ""); + let line_split_at = line.find(":").unwrap_or(line.len()); + let (name, seed) = line.split_at(line_split_at); + let seed_str = &seed[3..]; - let account_id: [u8; 32] = hex::decode(seed_str) - .expect("stored seed is valid hex string; qed") - .as_slice() - .try_into() - .expect("stored seed is valid length; qed"); + let account_id: [u8; 32] = hex::decode(seed_str) + .expect("stored seed is valid hex string; qed") + .as_slice() + .try_into() + .expect("stored seed is valid length; qed"); - let _ = self.known_validators.insert(account_id, name.to_string()); - } - }, - Err(_) => { } + let _ = self.known_validators.insert(account_id, name.to_string()); + } } Ok(()) } @@ -115,6 +121,7 @@ impl CurrentValidators { if self.individual.len() > 0 { self.table_state.select(Some(0)); self.scroll_state = self.scroll_state.position(0); + self.update_choosen_details(0); } } @@ -131,6 +138,7 @@ impl CurrentValidators { }; self.table_state.select(Some(i)); self.scroll_state = self.scroll_state.position(i); + self.update_choosen_details(i); } fn last_row(&mut self) { @@ -138,6 +146,7 @@ impl CurrentValidators { let last = self.individual.len() - 1; self.table_state.select(Some(last)); self.scroll_state = self.scroll_state.position(last); + self.update_choosen_details(last); } } @@ -154,6 +163,7 @@ impl CurrentValidators { }; self.table_state.select(Some(i)); self.scroll_state = self.scroll_state.position(i); + self.update_choosen_details(i); } fn update_era_rewards( @@ -176,11 +186,10 @@ impl CurrentValidators { } } - let index = self.table_state - .selected() - .unwrap_or_default(); self.scroll_state = self.scroll_state.content_length(self.individual.len()); - self.scroll_state = self.scroll_state.position(index); + if let Some(index) = self.table_state.selected() { + self.update_choosen_details(index); + } } } @@ -200,7 +209,7 @@ impl Component for CurrentValidators { } fn register_config_handler(&mut self, config: Config) -> Result<()> { - if let Some(style) = config.styles.get(&crate::app::Mode::Validator) { + if let Some(style) = config.styles.get(&crate::app::Mode::Nominator) { self.palette.with_normal_style(style.get("normal_style").copied()); self.palette.with_hover_style(style.get("hover_style").copied()); self.palette.with_normal_border_style(style.get("normal_border_style").copied()); diff --git a/src/components/nominator/event_log.rs b/src/components/nominator/event_log.rs index 17fcc73..a5c7b42 100644 --- a/src/components/nominator/event_log.rs +++ b/src/components/nominator/event_log.rs @@ -130,7 +130,7 @@ impl PartialComponent for EventLogs { impl Component for EventLogs { fn register_config_handler(&mut self, config: Config) -> Result<()> { - if let Some(style) = config.styles.get(&crate::app::Mode::Validator) { + if let Some(style) = config.styles.get(&crate::app::Mode::Nominator) { self.palette.with_normal_style(style.get("normal_style").copied()); self.palette.with_hover_style(style.get("hover_style").copied()); self.palette.with_normal_border_style(style.get("normal_border_style").copied()); diff --git a/src/components/nominator/mod.rs b/src/components/nominator/mod.rs index ec38568..79197c4 100644 --- a/src/components/nominator/mod.rs +++ b/src/components/nominator/mod.rs @@ -14,9 +14,11 @@ use crate::{action::Action, app::Mode, config::Config}; mod event_log; mod current_validators; mod rename_known_validator; +mod current_validator_details; use event_log::EventLogs; use current_validators::CurrentValidators; +use current_validator_details::CurrentValidatorDetails; use rename_known_validator::RenameKnownValidator; #[derive(Debug, Clone, PartialEq)] @@ -44,6 +46,7 @@ impl Default for Nominator { current_tab: CurrentTab::Nothing, components: vec![ Box::new(CurrentValidators::default()), + Box::new(CurrentValidatorDetails::default()), Box::new(EventLogs::default()), Box::new(RenameKnownValidator::default()), ], @@ -176,7 +179,7 @@ pub fn nominator_layout(area: Rect) -> [Rect; 3] { pub fn validator_details_layout(area: Rect) -> [Rect; 2] { let [place, _, _] = nominator_layout(area); Layout::horizontal([ - Constraint::Percentage(70), - Constraint::Percentage(30), + Constraint::Percentage(60), + Constraint::Percentage(40), ]).areas(place) } diff --git a/src/components/nominator/rename_known_validator.rs b/src/components/nominator/rename_known_validator.rs index 36a0eba..c9df1fe 100644 --- a/src/components/nominator/rename_known_validator.rs +++ b/src/components/nominator/rename_known_validator.rs @@ -84,7 +84,7 @@ impl Component for RenameKnownValidator { } fn register_config_handler(&mut self, config: Config) -> Result<()> { - if let Some(style) = config.styles.get(&crate::app::Mode::Wallet) { + if let Some(style) = config.styles.get(&crate::app::Mode::Nominator) { self.palette.with_normal_style(style.get("normal_style").copied()); self.palette.with_normal_border_style(style.get("normal_border_style").copied()); self.palette.with_normal_title_style(style.get("normal_title_style").copied()); diff --git a/src/components/validator/nominators.rs b/src/components/validator/nominators.rs index c68a76d..eac336c 100644 --- a/src/components/validator/nominators.rs +++ b/src/components/validator/nominators.rs @@ -27,6 +27,7 @@ pub struct NominatorsByValidator { scroll_state: ScrollbarState, table_state: TableState, nominators: Vec, + stash: [u8; 32], } impl Default for NominatorsByValidator { @@ -46,6 +47,7 @@ impl NominatorsByValidator { scroll_state: ScrollbarState::new(0), table_state: TableState::new(), nominators: Vec::new(), + stash: [0u8; 32], palette: StylePalette::default(), } } @@ -147,7 +149,9 @@ impl Component for NominatorsByValidator { fn update(&mut self, action: Action) -> Result> { match action { - Action::SetNominatorsByValidator(nominators) => self.update_nominators(nominators), + Action::SetStashAccount(stash) => self.stash = stash, + Action::SetNominatorsByValidator(nominators, account_id) if self.stash == account_id => + self.update_nominators(nominators), _ => {} }; Ok(None) diff --git a/src/components/validator/reward_details.rs b/src/components/validator/reward_details.rs index 5c23860..1263265 100644 --- a/src/components/validator/reward_details.rs +++ b/src/components/validator/reward_details.rs @@ -20,6 +20,7 @@ pub struct RewardDetails { nominators_blocked: bool, apy: String, inflation: String, + stash: [u8; 32], } impl Default for RewardDetails { @@ -36,6 +37,7 @@ impl RewardDetails { nominators_blocked: false, apy: String::from("0.0%"), inflation: String::from("0.0%"), + stash: [0u8; 32], } } @@ -70,7 +72,8 @@ impl Component for RewardDetails { fn update(&mut self, action: Action) -> Result> { match action { - Action::SetValidatorPrefs(commission, disabled) => { + Action::SetStashAccount(stash) => self.stash = stash, + Action::SetValidatorPrefs(commission, disabled, account_id) if self.stash == account_id => { self.commission = commission; self.nominators_blocked = disabled; } diff --git a/src/components/validator/staking_details.rs b/src/components/validator/staking_details.rs index ad190ff..6854386 100644 --- a/src/components/validator/staking_details.rs +++ b/src/components/validator/staking_details.rs @@ -18,6 +18,7 @@ pub struct StakingDetails { palette: StylePalette, staked_own: u128, staked_total: u128, + stash: [u8; 32], } impl Default for StakingDetails { @@ -35,6 +36,7 @@ impl StakingDetails { palette: StylePalette::default(), staked_own: 0, staked_total: 0, + stash: [0u8; 32], } } @@ -66,7 +68,8 @@ impl Component for StakingDetails { fn update(&mut self, action: Action) -> Result> { match action { - Action::SetStakedRatio(total, own) => { + Action::SetStashAccount(account_id) => self.stash = account_id, + Action::SetStakedRatio(total, own, account_id) if self.stash == account_id => { self.staked_total = total; self.staked_own = own; } diff --git a/src/components/validator/stash_info.rs b/src/components/validator/stash_info.rs index 3f750da..c069d3f 100644 --- a/src/components/validator/stash_info.rs +++ b/src/components/validator/stash_info.rs @@ -203,15 +203,15 @@ impl StashInfo { if let Some(network_tx) = &self.network_tx { let _ = network_tx.send(Action::BalanceRequest(account_id, false)); - let _ = network_tx.send(Action::GetValidatorLedger(account_id)); - let _ = network_tx.send(Action::GetIsStashBonded(account_id)); - let _ = network_tx.send(Action::GetErasStakersOverview(account_id)); - let _ = network_tx.send(Action::GetValidatorPrefs(account_id)); - let _ = network_tx.send(Action::GetNominatorsByValidator(account_id)); - let _ = network_tx.send(Action::GetQueuedSessionKeys(account_id)); - let _ = network_tx.send(Action::GetSessionKeys(account_id)); - let _ = network_tx.send(Action::GetValidatorAllRewards(account_id)); - let _ = network_tx.send(Action::GetSlashingSpans(account_id)); + let _ = network_tx.send(Action::GetValidatorLedger(account_id, true)); + let _ = network_tx.send(Action::GetIsStashBonded(account_id, true)); + let _ = network_tx.send(Action::GetErasStakersOverview(account_id, true)); + let _ = network_tx.send(Action::GetValidatorPrefs(account_id, true)); + let _ = network_tx.send(Action::GetNominatorsByValidator(account_id, true)); + let _ = network_tx.send(Action::GetQueuedSessionKeys(account_id, true)); + let _ = network_tx.send(Action::GetSessionKeys(account_id, true)); + let _ = network_tx.send(Action::GetValidatorAllRewards(account_id, true)); + let _ = network_tx.send(Action::GetSlashingSpans(account_id, true)); } } diff --git a/src/network/mod.rs b/src/network/mod.rs index f7ebc8e..88a52a2 100644 --- a/src/network/mod.rs +++ b/src/network/mod.rs @@ -37,6 +37,7 @@ pub struct Network { best_hash: Option, finalized_hash: Option, stash_to_watch: Option<[u8; 32]>, + validator_details_to_watch: Option<[u8; 32]>, accounts_to_watch: std::collections::HashSet<[u8; 32]>, transactions_to_watch: Vec, eras_to_watch: std::collections::HashSet, @@ -56,6 +57,7 @@ impl Network { best_hash: None, finalized_hash: None, stash_to_watch: None, + validator_details_to_watch: None, accounts_to_watch: Default::default(), transactions_to_watch: Default::default(), eras_to_watch: Default::default(), @@ -63,10 +65,17 @@ impl Network { } } - fn store_stash_if_possible(&mut self, new_stash: [u8; 32]) { - match self.stash_to_watch { - Some(stash) if stash == new_stash => {}, - _ => self.stash_to_watch = Some(new_stash), + fn store_stash_or_validator_if_possible(&mut self, account_id: [u8; 32], is_stash: bool) { + if is_stash { + match self.stash_to_watch { + Some(stash) if stash == account_id => {}, + _ => self.stash_to_watch = Some(account_id), + } + } else { + match self.validator_details_to_watch { + Some(stash) if stash == account_id => {}, + _ => self.validator_details_to_watch = Some(account_id), + } } } @@ -114,6 +123,11 @@ impl Network { predefined_calls::get_validator_staking_result(&self.action_tx, &self.online_client_api, &stash_to_watch, *era_index).await?; } } + if let Some(validator_details_to_watch) = self.validator_details_to_watch { + predefined_calls::get_nominators_by_validator(&self.action_tx, &self.online_client_api, &validator_details_to_watch).await?; + predefined_calls::get_validator_prefs(&self.action_tx, &self.online_client_api, &validator_details_to_watch).await?; + predefined_calls::get_staking_value_ratio(&self.action_tx, &self.online_client_api, &validator_details_to_watch).await?; + } for account_id in self.accounts_to_watch.iter() { predefined_calls::get_balance(&self.action_tx, &self.online_client_api, &account_id).await?; } @@ -191,41 +205,41 @@ impl Network { Ok(()) } - Action::GetSlashingSpans(stash) => { - self.store_stash_if_possible(stash); - predefined_calls::get_slashing_spans(&self.action_tx, &self.online_client_api, &stash).await + Action::GetSlashingSpans(account_id, is_stash) => { + self.store_stash_or_validator_if_possible(account_id, is_stash); + predefined_calls::get_slashing_spans(&self.action_tx, &self.online_client_api, &account_id).await } - Action::GetValidatorLedger(stash) => { - self.store_stash_if_possible(stash); - predefined_calls::get_validators_ledger(&self.action_tx, &self.online_client_api, &stash).await + Action::GetValidatorLedger(account_id, is_stash) => { + self.store_stash_or_validator_if_possible(account_id, is_stash); + predefined_calls::get_validators_ledger(&self.action_tx, &self.online_client_api, &account_id).await } - Action::GetIsStashBonded(stash) => { - self.store_stash_if_possible(stash); - predefined_calls::get_is_stash_bonded(&self.action_tx, &self.online_client_api, &stash).await + Action::GetIsStashBonded(account_id, is_stash) => { + self.store_stash_or_validator_if_possible(account_id, is_stash); + predefined_calls::get_is_stash_bonded(&self.action_tx, &self.online_client_api, &account_id).await }, - Action::GetErasStakersOverview(stash) => { - self.store_stash_if_possible(stash); - predefined_calls::get_staking_value_ratio(&self.action_tx, &self.online_client_api, &stash).await + Action::GetErasStakersOverview(account_id, is_stash) => { + self.store_stash_or_validator_if_possible(account_id, is_stash); + predefined_calls::get_staking_value_ratio(&self.action_tx, &self.online_client_api, &account_id).await }, - Action::GetValidatorPrefs(stash) => { - self.store_stash_if_possible(stash); - predefined_calls::get_validator_prefs(&self.action_tx, &self.online_client_api, &stash).await + Action::GetValidatorPrefs(account_id, is_stash) => { + self.store_stash_or_validator_if_possible(account_id, is_stash); + predefined_calls::get_validator_prefs(&self.action_tx, &self.online_client_api, &account_id).await }, - Action::GetValidatorAllRewards(stash) => { - self.store_stash_if_possible(stash); - predefined_calls::get_validator_staking_results(&self.action_tx, &self.online_client_api, &stash).await + Action::GetNominatorsByValidator(account_id, is_stash) => { + self.store_stash_or_validator_if_possible(account_id, is_stash); + predefined_calls::get_nominators_by_validator(&self.action_tx, &self.online_client_api, &account_id).await }, - Action::GetNominatorsByValidator(stash) => { - self.store_stash_if_possible(stash); - predefined_calls::get_nominators_by_validator(&self.action_tx, &self.online_client_api, &stash).await + Action::GetValidatorAllRewards(account_id, is_stash) => { + self.store_stash_or_validator_if_possible(account_id, is_stash); + predefined_calls::get_validator_staking_results(&self.action_tx, &self.online_client_api, &account_id).await }, - Action::GetQueuedSessionKeys(stash) => { - self.store_stash_if_possible(stash); - predefined_calls::get_queued_session_keys(&self.action_tx, &self.online_client_api, &self.rpc_client, &stash).await + Action::GetQueuedSessionKeys(account_id, is_stash) => { + self.store_stash_or_validator_if_possible(account_id, is_stash); + predefined_calls::get_queued_session_keys(&self.action_tx, &self.online_client_api, &self.rpc_client, &account_id).await }, - Action::GetSessionKeys(stash) => { - self.store_stash_if_possible(stash); - predefined_calls::get_session_keys(&self.action_tx, &self.online_client_api, &self.rpc_client, &stash).await + Action::GetSessionKeys(account_id, is_stash) => { + self.store_stash_or_validator_if_possible(account_id, is_stash); + predefined_calls::get_session_keys(&self.action_tx, &self.online_client_api, &self.rpc_client, &account_id).await }, Action::BalanceRequest(account_id, remove) => { if remove { diff --git a/src/network/predefined_calls.rs b/src/network/predefined_calls.rs index d4fb164..66e5828 100644 --- a/src/network/predefined_calls.rs +++ b/src/network/predefined_calls.rs @@ -472,7 +472,7 @@ pub async fn get_nominators_by_validator( None => Vec::new(), }; - action_tx.send(Action::SetNominatorsByValidator(nominators))?; + action_tx.send(Action::SetNominatorsByValidator(nominators, *account_id))?; Ok(()) } @@ -503,7 +503,7 @@ pub async fn get_staking_value_ratio( Some(overview) => (overview.total, overview.own), None => (0, 0), }; - action_tx.send(Action::SetStakedRatio(total, own))?; + action_tx.send(Action::SetStakedRatio(total, own, *account_id))?; Ok(()) } @@ -519,7 +519,7 @@ pub async fn get_validator_prefs( None => (0, false), }; - action_tx.send(Action::SetValidatorPrefs(comission, blocked))?; + action_tx.send(Action::SetValidatorPrefs(comission, blocked, *account_id))?; Ok(()) }