Files
pezkuwi-subxt/subxt/examples/storage_iterating_dynamic.rs
T
James Wilson 23c62f3d5d Update to 2024 edition (#2001)
* Update to 2024 edition

* Update to 2024 edition; fmt, use<> and remove refs

* async functions
2025-05-09 16:12:18 +01:00

25 lines
958 B
Rust

#![allow(missing_docs)]
use subxt::{OnlineClient, PolkadotConfig, dynamic::Value};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a new API client, configured to talk to Polkadot nodes.
let api = OnlineClient::<PolkadotConfig>::new().await?;
// Build a dynamic storage query to iterate account information.
// With a dynamic query, we can just provide an empty vector as the keys to iterate over all entries.
let keys: Vec<Value> = vec![];
let storage_query = subxt::dynamic::storage("System", "Account", keys);
// Use that query to return an iterator over the results.
let mut results = api.storage().at_latest().await?.iter(storage_query).await?;
while let Some(Ok(kv)) = results.next().await {
println!("Keys decoded: {:?}", kv.keys);
println!("Key: 0x{}", hex::encode(&kv.key_bytes));
println!("Value: {:?}", kv.value.to_value()?);
}
Ok(())
}