minimization of rpc calls based on the responses
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
This commit is contained in:
parent
33027f96d5
commit
2635792dab
@ -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.37"
|
||||
version = "0.3.38"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
@ -94,17 +94,20 @@ impl CurrentValidatorDetails {
|
||||
}
|
||||
|
||||
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) * 100.0,
|
||||
};
|
||||
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));
|
||||
let _ = network_tx.send(Action::GetValidatorLedger(account_id, false));
|
||||
let _ = network_tx.send(Action::GetValidatorLatestClaim(account_id, false));
|
||||
|
||||
if self.choosen != account_id {
|
||||
self.choosen = account_id;
|
||||
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));
|
||||
let _ = network_tx.send(Action::GetValidatorLedger(account_id, false));
|
||||
let _ = network_tx.send(Action::GetValidatorLatestClaim(account_id, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -127,6 +127,7 @@ impl Network {
|
||||
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?;
|
||||
predefined_calls::get_validator_latest_claim(&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?;
|
||||
|
@ -284,7 +284,9 @@ pub async fn get_validator_staking_results(
|
||||
let current_era = super::raw_calls::staking::current_era(api, None).await?.unwrap_or(0);
|
||||
let era_depth = super::raw_calls::staking::history_depth(api).unwrap_or(0);
|
||||
for era_index in current_era.saturating_sub(era_depth)..current_era {
|
||||
get_validator_staking_result(action_tx, api, account_id, era_index).await?;
|
||||
if get_validator_staking_result(action_tx, api, account_id, era_index).await? {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@ -294,11 +296,11 @@ pub async fn get_validator_staking_result(
|
||||
api: &OnlineClient<CasperConfig>,
|
||||
account_id: &[u8; 32],
|
||||
era_index: u32,
|
||||
) -> Result<()> {
|
||||
get_validator_reward_in_era(action_tx, api, account_id, era_index).await?;
|
||||
) -> Result<bool> {
|
||||
let no_more_rewards = get_validator_reward_in_era(action_tx, api, account_id, era_index).await?;
|
||||
get_validator_claims_in_era(action_tx, api, account_id, era_index).await?;
|
||||
get_validator_slashes_in_era(action_tx, api, account_id, era_index).await?;
|
||||
Ok(())
|
||||
Ok(no_more_rewards)
|
||||
}
|
||||
|
||||
pub async fn get_current_validator_reward_in_era(
|
||||
@ -351,13 +353,9 @@ async fn get_validator_reward_in_era(
|
||||
api: &OnlineClient<CasperConfig>,
|
||||
account_id: &[u8; 32],
|
||||
era_index: u32,
|
||||
) -> Result<()> {
|
||||
let maybe_era_reward_points = super::raw_calls::staking::eras_reward_points(api, None, era_index)
|
||||
.await?;
|
||||
|
||||
let era_reward = super::raw_calls::staking::eras_validator_reward(api, None, era_index)
|
||||
.await?
|
||||
.unwrap_or_default();
|
||||
) -> Result<bool> {
|
||||
let maybe_era_reward_points = super::raw_calls::staking::eras_reward_points(api, None, era_index).await?;
|
||||
let era_reward = super::raw_calls::staking::eras_validator_reward(api, None, era_index).await?.unwrap_or_default();
|
||||
|
||||
let my_reward = match maybe_era_reward_points {
|
||||
Some(era_reward_points) => {
|
||||
@ -373,9 +371,14 @@ async fn get_validator_reward_in_era(
|
||||
None => 0u128,
|
||||
};
|
||||
|
||||
action_tx.send(Action::SetValidatorEraReward(era_index, my_reward))?;
|
||||
let no_more_rewards = if my_reward > 0 {
|
||||
action_tx.send(Action::SetValidatorEraReward(era_index, my_reward))?;
|
||||
false
|
||||
} else {
|
||||
true
|
||||
};
|
||||
|
||||
Ok(())
|
||||
Ok(no_more_rewards)
|
||||
}
|
||||
|
||||
async fn get_validator_claims_in_era(
|
||||
|
Loading…
Reference in New Issue
Block a user