mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 22:11:06 +00:00
Fetch paged storage keys
This commit is contained in:
+21
@@ -228,6 +228,20 @@ impl<T: Runtime> Client<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Fetch up to `count` keys for a storage map in lexicographic order.
|
||||
///
|
||||
/// Supports pagination by passing a value to `start_key`.
|
||||
pub async fn fetch_keys<F: Store<T>>(
|
||||
&self,
|
||||
count: u32,
|
||||
start_key: Option<StorageKey>,
|
||||
hash: Option<T::Hash>,
|
||||
) -> Result<Vec<StorageKey>, Error> {
|
||||
let prefix = <F as Store<T>>::prefix(&self.metadata)?;
|
||||
let keys = self.rpc.storage_keys_paged(Some(prefix), count, start_key, hash).await?;
|
||||
Ok(keys)
|
||||
}
|
||||
|
||||
/// Query historical storage entries
|
||||
pub async fn query_storage(
|
||||
&self,
|
||||
@@ -612,4 +626,11 @@ mod tests {
|
||||
let mut blocks = client.subscribe_finalized_blocks().await.unwrap();
|
||||
blocks.next().await;
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn test_fetch_keys() {
|
||||
let (client, _) = test_client().await;
|
||||
let keys = client.fetch_keys::<system::AccountStore<_>>(4, None, None).await.unwrap();
|
||||
assert_eq!(keys.len(), 4)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user