Compare commits

..

No commits in common. "f8b421554611687697ec69f863037a4f2fc77165" and "ee5640349acb43a82c8cd2fd666ac6f5f49380dd" have entirely different histories.

8 changed files with 22 additions and 141 deletions

View File

@ -2,7 +2,7 @@
name = "ghost-eye" name = "ghost-eye"
authors = ["str3tch <stretch@ghostchain.io>"] authors = ["str3tch <stretch@ghostchain.io>"]
description = "Application for interacting with Casper/Ghost nodes that are exposing RPC only to the localhost" description = "Application for interacting with Casper/Ghost nodes that are exposing RPC only to the localhost"
version = "0.3.42" version = "0.3.41"
edition = "2021" edition = "2021"
homepage = "https://git.ghostchain.io/ghostchain" homepage = "https://git.ghostchain.io/ghostchain"
repository = "https://git.ghostchain.io/ghostchain/ghost-eye" repository = "https://git.ghostchain.io/ghostchain/ghost-eye"

View File

@ -105,8 +105,6 @@ pub enum Action {
GetValidatorPrefs([u8; 32], bool), GetValidatorPrefs([u8; 32], bool),
GetSlashingSpans([u8; 32], bool), GetSlashingSpans([u8; 32], bool),
GetValidatorLatestClaim([u8; 32], bool), GetValidatorLatestClaim([u8; 32], bool),
GetValidatorIsDisabled([u8; 32], bool),
GetValidatorInSession([u8; 32], bool),
GetCurrentValidatorEraRewards, GetCurrentValidatorEraRewards,
SetNodeName(Option<String>), SetNodeName(Option<String>),
@ -137,7 +135,6 @@ pub enum Action {
SetValidatorEraSlash(u32, u128), SetValidatorEraSlash(u32, u128),
SetValidatorEraUnlocking(u32, u128, [u8; 32]), SetValidatorEraUnlocking(u32, u128, [u8; 32]),
SetValidatorLatestClaim(u32, [u8; 32]), SetValidatorLatestClaim(u32, [u8; 32]),
SetValidatorInSession(bool, [u8; 32]),
SetIsBonded(bool), SetIsBonded(bool),
SetStakedAmountRatio(u128, u128, [u8; 32]), SetStakedAmountRatio(u128, u128, [u8; 32]),
SetStakedRatio(u128, u128, [u8; 32]), SetStakedRatio(u128, u128, [u8; 32]),

View File

@ -24,7 +24,6 @@ pub struct RewardDetails {
stash: [u8; 32], stash: [u8; 32],
in_staking_validators: bool, in_staking_validators: bool,
in_session_validators: bool, in_session_validators: bool,
is_disabled: bool,
} }
impl Default for RewardDetails { impl Default for RewardDetails {
@ -44,7 +43,6 @@ impl RewardDetails {
stash: [0u8; 32], stash: [0u8; 32],
in_staking_validators: false, in_staking_validators: false,
in_session_validators: false, in_session_validators: false,
is_disabled: false,
} }
} }
@ -81,13 +79,6 @@ impl Component for RewardDetails {
fn update(&mut self, action: Action) -> Result<Option<Action>> { fn update(&mut self, action: Action) -> Result<Option<Action>> {
match action { match action {
Action::SetStashAccount(stash) => self.stash = stash, Action::SetStashAccount(stash) => self.stash = stash,
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 => { Action::SetValidatorPrefs(commission, disabled, account_id) if self.stash == account_id => {
self.commission = commission; self.commission = commission;
self.in_staking_validators = commission.is_some(); self.in_staking_validators = commission.is_some();
@ -104,15 +95,11 @@ impl Component for RewardDetails {
let [_, _, place] = super::validator_balance_layout(area); let [_, _, place] = super::validator_balance_layout(area);
let (border_style, border_type) = self.palette.create_border_style(false); let (border_style, border_type) = self.palette.create_border_style(false);
let staking_status = if self.is_disabled { let staking_status = match (self.in_staking_validators, self.in_session_validators) {
"Staking status: Disabled".to_string()
} else {
match (self.in_staking_validators, self.in_session_validators) {
(false, false) => "Staking status: Nothing".to_string(), (false, false) => "Staking status: Nothing".to_string(),
(true, false) => "Staking status: Stopping".to_string(), (true, false) => "Staking status: Active".to_string(),
(false, true) => "Staking status: Pending".to_string(), (false, true) => "Staking status: Pending".to_string(),
(true, true) => "Staking status: Active".to_string(), (true, true) => "Staking status: Active".to_string(),
}
}; };
let table = Table::new( let table = Table::new(

View File

@ -159,8 +159,6 @@ impl StashInfo {
let _ = network_tx.send(Action::GetSessionKeys(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::GetValidatorAllRewards(account_id, true));
let _ = network_tx.send(Action::GetSlashingSpans(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));
} }
} }

View File

@ -315,69 +315,6 @@ impl Accounts {
Ok(()) Ok(())
} }
fn load_initial_keys(&mut self) {
self.try_load_and_store_keys("/etc/ghost/wallet-key", "ghostie");
self.try_load_and_store_keys("/etc/ghost/stash-key", "stash");
}
fn try_load_and_store_keys(&mut self, path_to_key: &str, name_for_key: &str) {
match std::fs::read_to_string(path_to_key) {
Ok(content) => {
let content = content.replace("\n", "");
let content = &content[2..];
let seed: [u8; 32] = hex::decode(content)
.expect("stored seed is valid hex string; qed")
.as_slice()
.try_into()
.expect("stored seed is valid length; qed");
let pair = Pair::from_seed(&seed);
let secret_seed = hex::encode(seed);
let account_id = pair.public().0;
let address = AccountId32::from(account_id)
.to_ss58check_with_version(Ss58AddressFormat::custom(1996));
if self.wallet_keys.iter().any(|key| key.seed == secret_seed) {
self.log_event(
format!("{} from `{}` already loaded", name_for_key, path_to_key),
ActionLevel::Warn);
} else {
self.log_event(
format!("{} from `{}` loaded to ghost-eye", name_for_key, path_to_key),
ActionLevel::Warn);
self.send_balance_request(account_id, false);
self.wallet_keys.push(AccountInfo {
name: name_for_key.to_string(),
address,
account_id,
seed: secret_seed,
});
self.save_to_file();
}
}
Err(_) => {
self.log_event(
format!("nothing found inside `{}`", path_to_key),
ActionLevel::Warn);
}
};
}
fn push_to_address_book(&mut self) {
if let Some(index) = self.table_state.selected() {
if let Some(action_tx) = &self.action_tx {
let wallet_key = self.wallet_keys
.get(index)
.expect("wallet key index should be in range; qed");
let _ = action_tx.send(Action::NewAddressBookRecord(
wallet_key.name.clone(),
wallet_key.address.clone()));
}
}
}
fn first_row(&mut self) { fn first_row(&mut self) {
if self.wallet_keys.len() > 0 { if self.wallet_keys.len() > 0 {
self.table_state.select(Some(0)); self.table_state.select(Some(0));
@ -517,8 +454,6 @@ impl Component for Accounts {
KeyCode::Char('D') => self.delete_row(), KeyCode::Char('D') => self.delete_row(),
KeyCode::Char('R') => self.update_account_name(), KeyCode::Char('R') => self.update_account_name(),
KeyCode::Char('Y') => self.copy_to_clipboard(), KeyCode::Char('Y') => self.copy_to_clipboard(),
KeyCode::Char('L') => self.load_initial_keys(),
KeyCode::Char('P') => self.push_to_address_book(),
_ => {}, _ => {},
}; };
} }

View File

@ -196,40 +196,24 @@ impl AddressBook {
ActionLevel::Error); ActionLevel::Error);
} }
match self.address_book.iter().position(|record| record.address == address) {
Some(index) => {
let record = self.address_book
.get(index)
.expect("record should be in range of address book; qed");
self.log_event( self.log_event(
format!("record with name `{}` already stores address {}", &record.name, &record.address), format!("account {} with address {} added to address book", &name, &address),
ActionLevel::Warn); ActionLevel::Info);
self.table_state.select(Some(index));
self.scroll_state = self.scroll_state.position(index);
},
None => {
let seed_vec = account_id.to_raw_vec(); let seed_vec = account_id.to_raw_vec();
let mut account_id = [0u8; 32]; let mut account_id = [0u8; 32];
account_id.copy_from_slice(&seed_vec); account_id.copy_from_slice(&seed_vec);
let seed_str = hex::encode(seed_vec); let seed_str = hex::encode(seed_vec);
self.log_event(
format!("account {} with address {} added to address book", &name, &address),
ActionLevel::Info);
self.address_book.push(BookRecord { self.address_book.push(BookRecord {
name, name,
address, address,
account_id, account_id,
seed: seed_str, seed: seed_str,
}); });
self.scroll_state = self.scroll_state.content_length(self.address_book.len());
self.save_to_file(); self.save_to_file();
self.send_balance_request(account_id, false);
self.last_row(); self.last_row();
}, self.send_balance_request(account_id, false);
}
}, },
Err(_) => self.log_event( Err(_) => self.log_event(
format!("provided account address {} is invalid", &address), format!("provided account address {} is invalid", &address),

View File

@ -118,7 +118,6 @@ impl Network {
predefined_calls::get_is_stash_bonded(&self.action_tx, &self.online_client_api, &stash_to_watch).await?; 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_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_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() { 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?; predefined_calls::get_validator_staking_result(&self.action_tx, &self.online_client_api, &stash_to_watch, *era_index).await?;
@ -207,10 +206,6 @@ impl Network {
Ok(()) 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) => { Action::GetValidatorLatestClaim(account_id, is_stash) => {
self.store_stash_or_validator_if_possible(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 predefined_calls::get_validator_latest_claim(&self.action_tx, &self.online_client_api, &account_id).await

View File

@ -574,18 +574,3 @@ pub async fn get_validator_latest_claim(
Ok(()) 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(())
}