ghost-eye/src/network/raw_calls/staking.rs
Uncle Stretch ba79a4cba8
current validators table in nominators tab added
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-01-23 17:06:27 +03:00

174 lines
6.5 KiB
Rust

use color_eyre::Result;
use subxt::{
client::OnlineClient,
utils::{AccountId32, H256},
};
use crate::{
casper_network::{
self,
runtime_types::{
pallet_staking::{ActiveEraInfo, EraRewardPoints, StakingLedger, ValidatorPrefs},
sp_arithmetic::per_things::Perbill,
sp_staking::{Exposure, PagedExposureMetadata},
},
},
CasperConfig,
};
pub async fn current_era(
online_client: &OnlineClient<CasperConfig>,
at_hash: Option<&H256>,
) -> Result<Option<u32>> {
let storage_key = casper_network::storage().staking().current_era();
let maybe_current_era = super::do_storage_call(online_client, &storage_key, at_hash).await?;
Ok(maybe_current_era)
}
pub async fn active_era(
online_client: &OnlineClient<CasperConfig>,
at_hash: Option<&H256>,
) -> Result<Option<ActiveEraInfo>> {
let storage_key = casper_network::storage().staking().active_era();
let maybe_active_era = super::do_storage_call(online_client, &storage_key, at_hash).await?;
Ok(maybe_active_era)
}
pub async fn counter_for_validators(
online_client: &OnlineClient<CasperConfig>,
at_hash: Option<&H256>,
) -> Result<Option<u32>> {
let storage_key = casper_network::storage().staking().counter_for_validators();
let maybe_counter_for_validators = super::do_storage_call(online_client, &storage_key, at_hash).await?;
Ok(maybe_counter_for_validators)
}
pub async fn counter_for_nominators(
online_client: &OnlineClient<CasperConfig>,
at_hash: Option<&H256>,
) -> Result<Option<u32>> {
let storage_key = casper_network::storage().staking().counter_for_nominators();
let maybe_counter_for_nominators = super::do_storage_call(online_client, &storage_key, at_hash).await?;
Ok(maybe_counter_for_nominators)
}
pub async fn eras_total_stake(
online_client: &OnlineClient<CasperConfig>,
at_hash: Option<&H256>,
era_index: u32,
) -> Result<Option<u128>> {
let storage_key = casper_network::storage().staking().eras_total_stake(era_index);
let maybe_eras_total_stake = super::do_storage_call(online_client, &storage_key, at_hash).await?;
Ok(maybe_eras_total_stake)
}
pub async fn eras_validator_reward(
online_client: &OnlineClient<CasperConfig>,
at_hash: Option<&H256>,
era_index: u32,
) -> Result<Option<u128>> {
let storage_key = casper_network::storage().staking().eras_validator_reward(era_index);
let maybe_eras_validator_reward = super::do_storage_call(online_client, &storage_key, at_hash).await?;
Ok(maybe_eras_validator_reward)
}
pub async fn eras_reward_points(
online_client: &OnlineClient<CasperConfig>,
at_hash: Option<&H256>,
era_index: u32,
) -> Result<Option<EraRewardPoints<AccountId32>>> {
let storage_key = casper_network::storage().staking().eras_reward_points(era_index);
let maybe_eras_reward_points = super::do_storage_call(online_client, &storage_key, at_hash).await?;
Ok(maybe_eras_reward_points)
}
pub async fn claimed_rewards(
online_client: &OnlineClient<CasperConfig>,
at_hash: Option<&H256>,
era_index: u32,
account: &[u8; 32],
) -> Result<Option<Vec<u32>>> {
let account_id = super::convert_array_to_account_id(account);
let storage_key = casper_network::storage().staking().claimed_rewards(era_index, account_id);
let maybe_claimed_rewards = super::do_storage_call(online_client, &storage_key, at_hash).await?;
Ok(maybe_claimed_rewards)
}
pub async fn validator_slash_in_era(
online_client: &OnlineClient<CasperConfig>,
at_hash: Option<&H256>,
era_index: u32,
account: &[u8; 32],
) -> Result<Option<(Perbill, u128)>> {
let account_id = super::convert_array_to_account_id(account);
let storage_key = casper_network::storage().staking().validator_slash_in_era(era_index, account_id);
let maybe_validator_slash_in_era = super::do_storage_call(online_client, &storage_key, at_hash).await?;
Ok(maybe_validator_slash_in_era)
}
pub async fn ledger(
online_client: &OnlineClient<CasperConfig>,
at_hash: Option<&H256>,
account: &[u8; 32],
) -> Result<Option<StakingLedger>> {
let account_id = super::convert_array_to_account_id(account);
let storage_key = casper_network::storage().staking().ledger(account_id);
let maybe_ledger = super::do_storage_call(online_client, &storage_key, at_hash).await?;
Ok(maybe_ledger)
}
pub async fn eras_stakers(
online_client: &OnlineClient<CasperConfig>,
at_hash: Option<&H256>,
era_index: u32,
account: &[u8; 32],
) -> Result<Option<Exposure<AccountId32, u128>>> {
let account_id = super::convert_array_to_account_id(account);
let storage_key = casper_network::storage().staking().eras_stakers(era_index, account_id);
let maybe_eras_stakers = super::do_storage_call(online_client, &storage_key, at_hash).await?;
Ok(maybe_eras_stakers)
}
pub async fn bonded(
online_client: &OnlineClient<CasperConfig>,
at_hash: Option<&H256>,
account: &[u8; 32],
) -> Result<Option<AccountId32>> {
let account_id = super::convert_array_to_account_id(account);
let storage_key = casper_network::storage().staking().bonded(account_id);
let maybe_bonded = super::do_storage_call(online_client, &storage_key, at_hash).await?;
Ok(maybe_bonded)
}
pub async fn eras_stakers_overview(
online_client: &OnlineClient<CasperConfig>,
at_hash: Option<&H256>,
era_index: u32,
account: &[u8; 32],
) -> Result<Option<PagedExposureMetadata<u128>>> {
let account_id = super::convert_array_to_account_id(account);
let storage_key = casper_network::storage().staking().eras_stakers_overview(era_index, account_id);
let maybe_eras_stakers_overview = super::do_storage_call(online_client, &storage_key, at_hash).await?;
Ok(maybe_eras_stakers_overview)
}
pub async fn validators(
online_client: &OnlineClient<CasperConfig>,
at_hash: Option<&H256>,
account: &[u8; 32],
) -> Result<Option<ValidatorPrefs>> {
let account_id = super::convert_array_to_account_id(account);
let storage_key = casper_network::storage().staking().validators(account_id);
let maybe_validators = super::do_storage_call(online_client, &storage_key, at_hash).await?;
Ok(maybe_validators)
}
pub async fn disabled_validators(
online_client: &OnlineClient<CasperConfig>,
at_hash: Option<&H256>,
) -> Result<Option<Vec<u32>>> {
let storage_key = casper_network::storage().staking().disabled_validators();
let maybe_disabled_validators = super::do_storage_call(online_client, &storage_key, at_hash).await?;
Ok(maybe_disabled_validators)
}