use color_eyre::Result; use subxt::{ client::OnlineClient, utils::{AccountId32, H256}, }; use crate::{ casper_network::{ self, runtime_types::{ pallet_staking::{ slashing::SlashingSpans, ActiveEraInfo, EraRewardPoints, RewardDestination, StakingLedger, ValidatorPrefs, Nominations, }, sp_arithmetic::per_things::Perbill, sp_staking::{ExposurePage, PagedExposureMetadata}, }, }, CasperConfig, }; pub async fn current_era( online_client: &OnlineClient, at_hash: Option<&H256>, ) -> Result> { 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, at_hash: Option<&H256>, ) -> Result> { 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, at_hash: Option<&H256>, ) -> Result> { 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, at_hash: Option<&H256>, ) -> Result> { 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 nominators( online_client: &OnlineClient, at_hash: Option<&H256>, account: &[u8; 32], ) -> Result> { let account_id = super::convert_array_to_account_id(account); let storage_key = casper_network::storage().staking().nominators(account_id); let maybe_nominators = super::do_storage_call(online_client, &storage_key, at_hash).await.unwrap(); Ok(maybe_nominators) } pub async fn eras_total_stake( online_client: &OnlineClient, at_hash: Option<&H256>, era_index: u32, ) -> Result> { 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, at_hash: Option<&H256>, era_index: u32, ) -> Result> { 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, at_hash: Option<&H256>, era_index: u32, ) -> Result>> { 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, at_hash: Option<&H256>, era_index: u32, account: &[u8; 32], ) -> Result>> { 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, at_hash: Option<&H256>, era_index: u32, account: &[u8; 32], ) -> Result> { 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, at_hash: Option<&H256>, account: &[u8; 32], ) -> Result> { 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_paged( online_client: &OnlineClient, at_hash: Option<&H256>, era_index: u32, page_index: u32, account: &[u8; 32], ) -> Result>> { let account_id = super::convert_array_to_account_id(account); let storage_key = casper_network::storage().staking().eras_stakers_paged(era_index, account_id, page_index); let maybe_eras_stakers_paged = super::do_storage_call(online_client, &storage_key, at_hash).await?; Ok(maybe_eras_stakers_paged) } pub async fn bonded( online_client: &OnlineClient, at_hash: Option<&H256>, account: &[u8; 32], ) -> Result> { 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, at_hash: Option<&H256>, era_index: u32, account: &[u8; 32], ) -> Result>> { 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, at_hash: Option<&H256>, account: &[u8; 32], ) -> Result> { 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, at_hash: Option<&H256>, ) -> Result>> { 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) } pub async fn min_validator_bond( online_client: &OnlineClient, at_hash: Option<&H256>, ) -> Result> { let storage_key = casper_network::storage().staking().min_validator_bond(); let maybe_min_validator_bond = super::do_storage_call(online_client, &storage_key, at_hash).await?; Ok(maybe_min_validator_bond) } pub async fn slashing_spans( online_client: &OnlineClient, at_hash: Option<&H256>, account: &[u8; 32], ) -> Result> { let account_id = super::convert_array_to_account_id(account); let storage_key = casper_network::storage().staking().slashing_spans(account_id); let maybe_slashing_spans = super::do_storage_call(online_client, &storage_key, at_hash).await?; Ok(maybe_slashing_spans) } pub async fn payee( online_client: &OnlineClient, at_hash: Option<&H256>, account: &[u8; 32], ) -> Result>> { let account_id = super::convert_array_to_account_id(account); let storage_key = casper_network::storage().staking().payee(account_id); let maybe_payee = super::do_storage_call(online_client, &storage_key, at_hash).await?; Ok(maybe_payee) } 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) }