storage: Decode keys of storage entry iterations
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 489
- Forks
- 293
- Avg merge
- 18h 35m
- Merged PRs (30d)
- 3
Description
Fetching a query of all systems' accounts storage().system().account_iter() returns a key value struct:
- keys contain
() - key_bytes contains
twox System twox AccountIter [remaining-key-of-the-account] - value contains the account value
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:
:subxt::ext::subxt_core::storage::address::StaticStorageKey::new(
::subxt::ext::subxt_core::utils::AccountId32(pub [u8; 32])
)
Example to reproduce this:
#![allow(missing_docs)]
use std::str::FromStr;
use subxt::ext::codec::Decode;
use subxt::utils::{AccountId32, H256};
use subxt::{Config, OnlineClient, SubstrateConfig};
type ChainConfig = SubstrateConfig;
#[subxt::subxt(runtime_metadata_insecure_url = "wss://rococo-asset-hub-rpc.polkadot.io")]
pub mod asset_hub {}
#[tokio::main]
async fn main() -> 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).
let mut results = storage.iter(storage_query.clone()).await?;
while let Some(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(())
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with subxt/src/storage/storage_type.rs at lines 313-323 and the generated storage().system().account_iter() entry point shown in the issue. Run the provided Rococo Asset Hub reproduction and inspect how the codegen currently passes () as the key type. Done means iteration keys expose the account ID rather than an empty tuple, while key_bytes and the account value remain available.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100