You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// The bytes that make up the address of the storage entry.
pubkey_bytes:Vec<u8>,
/// The keys that can be used to construct the address of this storage entry.
pubkeys:T::Keys,
/// The value of the storage entry.
pubvalue:T::Target,
}
From the user's perspective, the keys field makes it a bit harder to reason about the final key we provide.
In this example, keys field does not return the account ID part of the key.
In codegen, we pass () as keys to the account_iter fn. However, we know that the keys field in this case is similar to the account fn:
#![allow(missing_docs)]use std::str::FromStr;use subxt::ext::codec::Decode;use subxt::utils::{AccountId32,H256};use subxt::{Config,OnlineClient,SubstrateConfig};typeChainConfig = SubstrateConfig;#[subxt::subxt(runtime_metadata_insecure_url = "wss://rococo-asset-hub-rpc.polkadot.io")]pubmod asset_hub {}#[tokio::main]asyncfnmain() -> Result<(),Box<dyn std::error::Error>>{let client =
OnlineClient::<ChainConfig>::from_url("wss://rococo-asset-hub-rpc.polkadot.io").await?;let storage = client.storage().at_latest().await.unwrap();// Build a storage query to iterate over account information.let storage_query = asset_hub::storage().system().account_iter();// Get back an iterator of results (here, we are fetching 10 items at// a time from the node, but we always iterate over one at a time).letmut results = storage.iter(storage_query.clone()).await?;whileletSome(Ok(kv)) = results.next().await{println!("Decoded key(s): {:?}", kv.keys);println!("Decoded key_bytes: {:?}", hex::encode(kv.key_bytes));println!("Value: {:?}", kv.value);}Ok(())}
The text was updated successfully, but these errors were encountered:
You get the decoded keys back in the above example already, is kv.keys. Subxt doesn't currently provide an easy way to decode the key bytes into something different, but one possibility is to use frame-decode to give more control over how to decode the key bytes ie using https://docs.rs/frame-decode/latest/frame_decode/storage/fn.decode_storage_key.html.
I expect that this will be integrated into Subxt at some point ie #1801, at which point we should probably expose some nicer methods for accessing and decoding storage keys.
Fetching a query of all systems' accounts
storage().system().account_iter()
returns a key value struct:()
twox System twox AccountIter [remaining-key-of-the-account]
subxt/subxt/src/storage/storage_type.rs
Lines 313 to 323 in b076f4c
From the user's perspective, the
keys
field makes it a bit harder to reason about the final key we provide.In this example, keys field does not return the account ID part of the key.
In codegen, we pass
()
as keys to the account_iter fn. However, we know that the keys field in this case is similar to theaccount
fn:Example to reproduce this:
The text was updated successfully, but these errors were encountered: