Compare commits
No commits in common. "105ca64dc68fa37a17de250b67362e221c22ba19" and "48eb85efa380e7dea07d5d003ae5ef6b00f937b0" have entirely different histories.
105ca64dc6
...
48eb85efa3
@ -2,7 +2,7 @@
|
||||
name = "ghost-eye"
|
||||
authors = ["str3tch <stretch@ghostchain.io>"]
|
||||
description = "Application for interacting with Casper/Ghost nodes that are exposing RPC only to the localhost"
|
||||
version = "0.3.47"
|
||||
version = "0.3.45"
|
||||
edition = "2021"
|
||||
homepage = "https://git.ghostchain.io/ghostchain"
|
||||
repository = "https://git.ghostchain.io/ghostchain/ghost-eye"
|
||||
|
@ -105,6 +105,7 @@ pub enum Action {
|
||||
GetSlashingSpans([u8; 32], bool),
|
||||
GetValidatorLatestClaim([u8; 32], bool),
|
||||
GetValidatorIsDisabled([u8; 32], bool),
|
||||
GetValidatorInSession([u8; 32], bool),
|
||||
GetCurrentValidatorEraRewards,
|
||||
|
||||
SetNodeName(Option<String>),
|
||||
@ -134,6 +135,7 @@ pub enum Action {
|
||||
SetValidatorEraSlash(u32, u128),
|
||||
SetValidatorEraUnlocking(Vec<UnlockChunk>, [u8; 32]),
|
||||
SetValidatorLatestClaim(u32, [u8; 32]),
|
||||
SetValidatorInSession(bool, [u8; 32]),
|
||||
SetIsBonded(bool, [u8; 32]),
|
||||
SetStakedAmountRatio(Option<u128>, Option<u128>, [u8; 32]),
|
||||
SetStakedRatio(u128, u128, [u8; 32]),
|
||||
|
@ -73,9 +73,9 @@ impl CurrentValidatorDetails {
|
||||
|
||||
fn prepare_state_string(&self) -> String {
|
||||
if self.is_active_validator {
|
||||
"active".to_string()
|
||||
"active staking".to_string()
|
||||
} else {
|
||||
"chilling".to_string()
|
||||
"stop staking".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,10 +163,6 @@ impl Component for CurrentValidatorDetails {
|
||||
Cell::from(Text::from("Forbidden".to_string()).alignment(Alignment::Left)),
|
||||
Cell::from(Text::from(self.is_nomination_disabled.to_string()).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("Total staked".to_string()).alignment(Alignment::Left)),
|
||||
Cell::from(Text::from(self.prepare_u128(self.total_balance)).alignment(Alignment::Right)),
|
||||
@ -176,8 +172,8 @@ impl Component for CurrentValidatorDetails {
|
||||
Cell::from(Text::from(self.prepare_u128(self.own_balance)).alignment(Alignment::Right)),
|
||||
]),
|
||||
Row::new(vec![
|
||||
Cell::from(Text::from("Imbalance".to_string()).alignment(Alignment::Left)),
|
||||
Cell::from(Text::from(self.prepare_stake_imbalance()).alignment(Alignment::Right)),
|
||||
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)),
|
||||
@ -191,6 +187,10 @@ impl Component for CurrentValidatorDetails {
|
||||
Cell::from(Text::from("In next era".to_string()).alignment(Alignment::Left)),
|
||||
Cell::from(Text::from(self.prepare_state_string()).alignment(Alignment::Right)),
|
||||
]),
|
||||
Row::new(vec![
|
||||
Cell::from(Text::from("Imbalance".to_string()).alignment(Alignment::Left)),
|
||||
Cell::from(Text::from(self.prepare_stake_imbalance()).alignment(Alignment::Right)),
|
||||
]),
|
||||
Row::new(vec![
|
||||
Cell::from(Text::from("Last payout".to_string()).alignment(Alignment::Left)),
|
||||
Cell::from(Text::from(format!("{} days ago", self.latest_era_claim)).alignment(Alignment::Right)),
|
||||
|
@ -34,7 +34,6 @@ pub struct CurrentValidators {
|
||||
table_state: TableState,
|
||||
individual: Vec<EraRewardPoints>,
|
||||
known_validators: std::collections::HashMap<[u8; 32], String>,
|
||||
checked_validators: std::collections::HashSet<[u8; 32]>,
|
||||
total_points: u32,
|
||||
era_index: u32,
|
||||
my_stash_id: Option<[u8; 32]>,
|
||||
@ -58,7 +57,6 @@ impl CurrentValidators {
|
||||
table_state: TableState::new(),
|
||||
individual: Default::default(),
|
||||
known_validators: Default::default(),
|
||||
checked_validators: Default::default(),
|
||||
total_points: 0,
|
||||
era_index: 0,
|
||||
my_stash_id: None,
|
||||
@ -80,23 +78,6 @@ impl CurrentValidators {
|
||||
}
|
||||
}
|
||||
|
||||
fn clear_choosen(&mut self) {
|
||||
self.checked_validators.clear();
|
||||
}
|
||||
|
||||
fn flip_validator_check(&mut self) {
|
||||
if let Some(index) = self.table_state.selected() {
|
||||
if let Some(indiv) = self.individual.get(index) {
|
||||
let current_account_id = indiv.account_id;
|
||||
if self.checked_validators.contains(¤t_account_id) {
|
||||
self.checked_validators.remove(¤t_account_id);
|
||||
} else {
|
||||
self.checked_validators.insert(current_account_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
@ -269,8 +250,6 @@ impl Component for CurrentValidators {
|
||||
KeyCode::Char('g') => self.first_row(),
|
||||
KeyCode::Char('G') => self.last_row(),
|
||||
KeyCode::Char('R') => self.update_known_validator_record(),
|
||||
KeyCode::Char('C') => self.clear_choosen(),
|
||||
KeyCode::Enter => self.flip_validator_check(),
|
||||
_ => {},
|
||||
};
|
||||
}
|
||||
@ -287,11 +266,6 @@ impl Component for CurrentValidators {
|
||||
.map(|(index, info)| {
|
||||
let mut address_text = Text::from(info.address.clone()).alignment(Alignment::Center);
|
||||
let mut points_text = Text::from(info.points.to_string()).alignment(Alignment::Right);
|
||||
let is_choosen_text = if self.checked_validators.contains(&info.account_id) {
|
||||
">"
|
||||
} else {
|
||||
""
|
||||
};
|
||||
|
||||
if info.disabled {
|
||||
address_text = address_text.add_modifier(Modifier::CROSSED_OUT);
|
||||
@ -311,7 +285,6 @@ impl Component for CurrentValidators {
|
||||
.cloned()
|
||||
.unwrap_or("My stash".to_string());
|
||||
Row::new(vec![
|
||||
Cell::from(Text::from(is_choosen_text).alignment(Alignment::Left)),
|
||||
Cell::from(Text::from(name).alignment(Alignment::Left)),
|
||||
Cell::from(address_text),
|
||||
Cell::from(points_text),
|
||||
@ -322,7 +295,6 @@ impl Component for CurrentValidators {
|
||||
.cloned()
|
||||
.unwrap_or("Ghostie".to_string());
|
||||
Row::new(vec![
|
||||
Cell::from(Text::from(is_choosen_text).alignment(Alignment::Left)),
|
||||
Cell::from(Text::from(name).alignment(Alignment::Left)),
|
||||
Cell::from(address_text),
|
||||
Cell::from(points_text),
|
||||
@ -330,7 +302,6 @@ impl Component for CurrentValidators {
|
||||
}
|
||||
}),
|
||||
[
|
||||
Constraint::Length(1),
|
||||
Constraint::Length(12),
|
||||
Constraint::Min(0),
|
||||
Constraint::Length(6),
|
||||
|
@ -8,7 +8,6 @@ use ratatui::{
|
||||
};
|
||||
|
||||
use super::{PartialComponent, Component, CurrentTab};
|
||||
use crate::types::EraRewardPoints;
|
||||
use crate::widgets::DotSpinner;
|
||||
use crate::{
|
||||
action::Action,
|
||||
@ -24,10 +23,8 @@ pub struct RewardDetails {
|
||||
inflation: String,
|
||||
stash: [u8; 32],
|
||||
in_staking_validators: bool,
|
||||
in_queued_keys: bool,
|
||||
in_next_keys: bool,
|
||||
in_session_validators: bool,
|
||||
is_disabled: bool,
|
||||
in_rewards: bool,
|
||||
}
|
||||
|
||||
impl Default for RewardDetails {
|
||||
@ -46,10 +43,8 @@ impl RewardDetails {
|
||||
inflation: String::from("0.0%"),
|
||||
stash: [0u8; 32],
|
||||
in_staking_validators: false,
|
||||
in_queued_keys: false,
|
||||
in_next_keys: false,
|
||||
in_session_validators: false,
|
||||
is_disabled: false,
|
||||
in_rewards: false,
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,16 +57,6 @@ impl RewardDetails {
|
||||
None => DotSpinner::default().to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
fn update_individual(&mut self, individual: &Vec<EraRewardPoints>) {
|
||||
let (is_disabled, in_rewards) = individual
|
||||
.iter()
|
||||
.find(|data| data.account_id == self.stash)
|
||||
.map(|data| (data.disabled, true))
|
||||
.unwrap_or((false, false));
|
||||
self.is_disabled = is_disabled;
|
||||
self.in_rewards = in_rewards;
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialComponent for RewardDetails {
|
||||
@ -96,19 +81,18 @@ impl Component for RewardDetails {
|
||||
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
||||
match action {
|
||||
Action::SetStashAccount(stash) => self.stash = stash,
|
||||
Action::SetCurrentValidatorEraRewards(_, _, individual) => self.update_individual(&individual),
|
||||
Action::SetCurrentValidatorEraRewards(_, _, individual) => self.is_disabled = individual
|
||||
.iter()
|
||||
.find(|data| data.account_id == self.stash)
|
||||
.map(|data| data.disabled)
|
||||
.unwrap_or_default(),
|
||||
Action::SetValidatorInSession(in_session_validators, account_id) if self.stash == account_id =>
|
||||
self.in_session_validators = in_session_validators,
|
||||
Action::SetValidatorPrefs(commission, disabled, account_id) if self.stash == account_id => {
|
||||
self.commission = commission;
|
||||
self.in_staking_validators = commission.is_some();
|
||||
self.nominators_blocked = disabled;
|
||||
}
|
||||
Action::SetSessionKey(name, session_key_info) => {
|
||||
if name.starts_with("q_") {
|
||||
self.in_queued_keys = !session_key_info.key.is_empty();
|
||||
} else {
|
||||
self.in_next_keys = !session_key_info.key.is_empty();
|
||||
}
|
||||
},
|
||||
Action::Apy(apy) => self.apy = apy,
|
||||
Action::Inflation(inflation) => self.inflation = inflation,
|
||||
_ => {}
|
||||
@ -120,19 +104,16 @@ impl Component for RewardDetails {
|
||||
let [_, _, place] = super::validator_balance_layout(area);
|
||||
let (border_style, border_type) = self.palette.create_border_style(false);
|
||||
|
||||
let status = if self.is_disabled {
|
||||
"Disabled"
|
||||
let staking_status = if self.is_disabled {
|
||||
"Staking status: Disabled".to_string()
|
||||
} else {
|
||||
let is_fully_in_session = self.in_queued_keys && self.in_next_keys;
|
||||
match (self.in_staking_validators, is_fully_in_session) {
|
||||
(true, true) => "Active",
|
||||
(true, false) => "Rotating",
|
||||
(false, true) if self.in_rewards => { "Stopping" }
|
||||
(false, true) if !self.in_rewards => { "Chill" }
|
||||
_ => "Nothing",
|
||||
match (self.in_staking_validators, self.in_session_validators) {
|
||||
(false, false) => "Staking status: Nothing".to_string(),
|
||||
(true, false) => "Staking status: Stopping".to_string(),
|
||||
(false, true) => "Staking status: Pending".to_string(),
|
||||
(true, true) => "Staking status: Active".to_string(),
|
||||
}
|
||||
};
|
||||
let staking_status = format!("Staking status: {status}");
|
||||
|
||||
let table = Table::new(
|
||||
vec![
|
||||
|
@ -160,6 +160,7 @@ impl StashInfo {
|
||||
let _ = network_tx.send(Action::GetValidatorAllRewards(account_id, true));
|
||||
let _ = network_tx.send(Action::GetSlashingSpans(account_id, true));
|
||||
let _ = network_tx.send(Action::GetValidatorIsDisabled(account_id, true));
|
||||
let _ = network_tx.send(Action::GetValidatorInSession(account_id, true));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -145,7 +145,7 @@ impl Accounts {
|
||||
format!("address {} copied to clipboard", &address),
|
||||
ActionLevel::Warn),
|
||||
_ => self.log_event(
|
||||
"command `xclip` not found, consider installing `xclip` on your machine".to_string(),
|
||||
"could not use `xclip` to copy".to_string(),
|
||||
ActionLevel::Error),
|
||||
}
|
||||
}
|
||||
|
@ -118,6 +118,7 @@ impl Network {
|
||||
predefined_calls::get_is_stash_bonded(&self.action_tx, &self.online_client_api, &stash_to_watch).await?;
|
||||
predefined_calls::get_validators_ledger(&self.action_tx, &self.online_client_api, &stash_to_watch).await?;
|
||||
predefined_calls::get_slashing_spans(&self.action_tx, &self.online_client_api, &stash_to_watch).await?;
|
||||
predefined_calls::get_validator_in_session(&self.action_tx, &self.online_client_api, &stash_to_watch).await?;
|
||||
|
||||
for era_index in self.eras_to_watch.iter() {
|
||||
predefined_calls::get_validator_staking_result(&self.action_tx, &self.online_client_api, &stash_to_watch, *era_index).await?;
|
||||
@ -208,6 +209,10 @@ impl Network {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Action::GetValidatorInSession(account_id, is_stash) => {
|
||||
self.store_stash_or_validator_if_possible(account_id, is_stash);
|
||||
predefined_calls::get_validator_in_session(&self.action_tx, &self.online_client_api, &account_id).await
|
||||
}
|
||||
Action::GetValidatorLatestClaim(account_id, is_stash) => {
|
||||
self.store_stash_or_validator_if_possible(account_id, is_stash);
|
||||
predefined_calls::get_validator_latest_claim(&self.action_tx, &self.online_client_api, &account_id).await
|
||||
|
@ -581,3 +581,18 @@ pub async fn get_validator_latest_claim(
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get_validator_in_session(
|
||||
action_tx: &UnboundedSender<Action>,
|
||||
api: &OnlineClient<CasperConfig>,
|
||||
account_id: &[u8; 32],
|
||||
) -> Result<()> {
|
||||
let in_list = super::raw_calls::session::validators(api, None)
|
||||
.await?
|
||||
.unwrap_or_default()
|
||||
.iter()
|
||||
.position(|validator| validator.0 == *account_id)
|
||||
.is_some();
|
||||
action_tx.send(Action::SetValidatorInSession(in_list, *account_id))?;
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user