Files
pezkuwi-sdk/vendor/pezkuwi-subxt/subxt/examples/sim_query_state.rs
T
pezkuwichain 6e835151c7 fix(ah-staking): stall detection grace period, MinerPages fix, and simulation tools
- Add 3-session grace period to stall detection to allow RC XCM round-trip
  before triggering era recovery (StallDetectionCount storage added)
- Fix plan_new_era() to always increment CurrentEra regardless of
  ElectionProvider::start() result, preventing infinite retry loops
- Fix MinerPages from 2 to 32 to match Pages config (was causing
  incomplete OCW solutions and election failures)
- Bump AH spec_version to 1_020_007
- Add subxt example scripts for simulation and mainnet operations
- Remove obsolete fix_force_era.rs (replaced by sim_reset_election.rs)
2026-02-19 17:16:43 +03:00

88 lines
2.6 KiB
Rust

//! Query AH staking state using subxt dynamic storage API
//!
//! Run:
//! cargo run --release -p pezkuwi-subxt --example sim_query_state
#![allow(missing_docs)]
use pezkuwi_subxt::dynamic::Value;
use pezkuwi_subxt::{OnlineClient, PezkuwiConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let ah_url = std::env::var("AH_RPC").unwrap_or_else(|_| "ws://127.0.0.1:40944".to_string());
let api = OnlineClient::<PezkuwiConfig>::from_url(&ah_url).await?;
println!("=== AH STAKING STATE ===\n");
let storage = api.storage().at_latest().await?;
let items = [
("Staking", "CurrentEra"),
("Staking", "ActiveEra"),
("Staking", "ForceEra"),
("Staking", "ValidatorCount"),
("Staking", "CounterForValidators"),
("Staking", "CounterForNominators"),
("Staking", "NextElectionPage"),
("Staking", "OutgoingValidatorSet"),
("Staking", "ElectableStashes"),
("Staking", "BondedEras"),
("Staking", "MinimumValidatorCount"),
];
for (pallet, name) in &items {
let addr = pezkuwi_subxt::dynamic::storage::<(), Value>(*pallet, *name);
match storage.entry(addr) {
Ok(entry) => match entry.try_fetch(()).await {
Ok(Some(val)) => {
let decoded = val.decode();
println!("{}.{} = {:?}", pallet, name, decoded);
},
Ok(None) => println!("{}.{} = None", pallet, name),
Err(e) => println!("{}.{} = <fetch error: {}>", pallet, name, e),
},
Err(e) => println!("{}.{} = <entry error: {}>", pallet, name, e),
}
}
println!();
let mbe_items = [
("MultiBlockElection", "CurrentPhase"),
("MultiBlockElection", "Round"),
];
for (pallet, name) in &mbe_items {
let addr = pezkuwi_subxt::dynamic::storage::<(), Value>(*pallet, *name);
match storage.entry(addr) {
Ok(entry) => match entry.try_fetch(()).await {
Ok(Some(val)) => println!("{}.{} = {:?}", pallet, name, val.decode()),
Ok(None) => println!("{}.{} = None", pallet, name),
Err(e) => println!("{}.{} = <fetch error: {}>", pallet, name, e),
},
Err(e) => println!("{}.{} = <entry error: {}>", pallet, name, e),
}
}
println!();
let rc_items = [
("StakingRcClient", "LastSessionReportEndingIndex"),
("StakingRcClient", "Mode"),
];
for (pallet, name) in &rc_items {
let addr = pezkuwi_subxt::dynamic::storage::<(), Value>(*pallet, *name);
match storage.entry(addr) {
Ok(entry) => match entry.try_fetch(()).await {
Ok(Some(val)) => println!("{}.{} = {:?}", pallet, name, val.decode()),
Ok(None) => println!("{}.{} = None", pallet, name),
Err(e) => println!("{}.{} = <fetch error: {}>", pallet, name, e),
},
Err(e) => println!("{}.{} = <entry error: {}>", pallet, name, e),
}
}
Ok(())
}