diff --git a/Cargo.toml b/Cargo.toml index d248207..8d3e9d4 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.28" +version = "0.3.29" edition = "2021" [dependencies] diff --git a/src/components/validator/history.rs b/src/components/validator/history.rs index e61ed22..178447b 100644 --- a/src/components/validator/history.rs +++ b/src/components/validator/history.rs @@ -64,17 +64,19 @@ impl History { fn payout_by_era_index(&mut self) { if let Some(index) = self.table_state.selected() { + let length = self.rewards.len() as u32; let era_index = self.rewards .keys() .nth(index) + .map(|i| length - i - 1) .expect("BTreeMap of rewards is indexed; qed"); let is_claimed = self.rewards - .get(era_index) + .get(&era_index) .map(|x| x.is_claimed) .expect("BTreeMap of rewards is indexed; qed"); if let Some(action_tx) = &self.action_tx { let _ = action_tx.send( - Action::PayoutValidatorPopup(*era_index, is_claimed)); + Action::PayoutValidatorPopup(era_index, is_claimed)); } } } @@ -242,6 +244,7 @@ impl Component for History { let table = Table::new( self.rewards .iter() + .rev() .map(|(key, value)| { let mut era_index_text = Text::from(key.to_string()).alignment(Alignment::Left); let mut slash_text = Text::from(self.prepare_u128(value.slash)).alignment(Alignment::Center); diff --git a/src/network/predefined_calls.rs b/src/network/predefined_calls.rs index 11d66be..9065b86 100644 --- a/src/network/predefined_calls.rs +++ b/src/network/predefined_calls.rs @@ -281,20 +281,9 @@ pub async fn get_validator_staking_results( api: &OnlineClient, account_id: &[u8; 32], ) -> Result<()> { - let (start, end) = super::raw_calls::historical::stored_range(api, None) - .await? - .map(|range| { - ( - range.0 - .saturating_div(6) - .saturating_sub(1), - range.1 - .saturating_div(6) - .saturating_sub(1), - ) - }) - .unwrap_or((0, 0)); - for era_index in start..end { + 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?; } Ok(()) diff --git a/src/network/raw_calls/staking.rs b/src/network/raw_calls/staking.rs index 6a62e88..bf10d8d 100644 --- a/src/network/raw_calls/staking.rs +++ b/src/network/raw_calls/staking.rs @@ -194,3 +194,11 @@ pub async fn slashing_spans( let maybe_slashing_spans = super::do_storage_call(online_client, &storage_key, at_hash).await?; Ok(maybe_slashing_spans) } + +pub fn history_depth( + online_client: &OnlineClient, +) -> Result { + let constant_query = casper_network::constants().staking().history_depth(); + let history_depth = super::do_constant_call(online_client, &constant_query)?; + Ok(history_depth) +}