Fetch paged storage keys

This commit is contained in:
Andrew Jones
2020-08-03 12:27:31 +01:00
parent d3e7bd2282
commit 663934ca37
5 changed files with 71 additions and 7 deletions
+21
View File
@@ -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)
}
}