mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-01 13:37:57 +00:00
7af0bcd262
- Replace PolkadotConfig with PezkuwiConfig - Replace SubstrateConfig with BizinikiwConfig - Rename config module files (polkadot.rs→pezkuwi.rs, substrate.rs→bizinikiwi.rs) - Update all documentation and examples - All 165 files updated, cargo check passes
42 lines
1.6 KiB
Rust
42 lines
1.6 KiB
Rust
#![allow(missing_docs)]
|
|
use pezkuwi_subxt::{OnlineClient, PezkuwiConfig, ext::futures::StreamExt};
|
|
|
|
// Generate an interface that we can use from the node's metadata.
|
|
#[pezkuwi_subxt::subxt(runtime_metadata_path = "../artifacts/pezkuwi_metadata_small.scale")]
|
|
pub mod pezkuwi {}
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
// Create a new API client, configured to talk to Pezkuwi nodes.
|
|
let api = OnlineClient::<PezkuwiConfig>::new().await?;
|
|
|
|
// Build a storage query to access account information. Same as if we were
|
|
// fetching a single value from this entry.
|
|
let storage_query = pezkuwi::storage().system().account();
|
|
|
|
// Use that query to access a storage entry, iterate over it and decode values.
|
|
let client_at = api.storage().at_latest().await?;
|
|
|
|
// We provide an empty tuple when iterating. If the storage entry had been an N map with
|
|
// multiple keys, then we could provide any prefix of those keys to iterate over. This is
|
|
// statically type checked, so only a valid number/type of keys in the tuple is accepted.
|
|
let mut values = client_at.entry(storage_query)?.iter(()).await?;
|
|
|
|
while let Some(kv) = values.next().await {
|
|
let kv = kv?;
|
|
|
|
// The key decodes into the type that the static address knows about, in this case a
|
|
// tuple of one entry, because the only part of the key that we can decode is the
|
|
// AccountId32 for each user.
|
|
let (account_id32,) = kv.key()?.decode()?;
|
|
|
|
// The value decodes into a statically generated type which holds account information.
|
|
let value = kv.value().decode()?;
|
|
|
|
let value_data = value.data;
|
|
println!("{account_id32}:\n {value_data:?}");
|
|
}
|
|
|
|
Ok(())
|
|
}
|