Add ability to iterate over N map storage keys (#537)

* Update polkadot.rs

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update artifacts

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Change CLI default to bytes

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* subxt: Storage query example

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update storage_query example with different alternatives

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc: Make calls with StorageKey instead of the prefix

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Examples: Add double map storage iteration

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* examples: Use tracing_subscriber for logs

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Fix clippy

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
Alexandru Vasile
2022-05-27 17:09:32 +03:00
committed by GitHub
parent ec23283d75
commit 531e40df3d
3 changed files with 169 additions and 6 deletions
+2 -4
View File
@@ -28,7 +28,6 @@ use std::{
use crate::{
error::BasicError,
storage::StorageKeyPrefix,
Config,
Metadata,
PhantomDataSendSync,
@@ -277,13 +276,12 @@ impl<T: Config> Rpc<T> {
/// If `start_key` is passed, return next keys in storage in lexicographic order.
pub async fn storage_keys_paged(
&self,
prefix: Option<StorageKeyPrefix>,
key: Option<StorageKey>,
count: u32,
start_key: Option<StorageKey>,
hash: Option<T::Hash>,
) -> Result<Vec<StorageKey>, BasicError> {
let prefix = prefix.map(|p| p.to_storage_key());
let params = rpc_params![prefix, count, start_key, hash];
let params = rpc_params![key, count, start_key, hash];
let data = self.client.request("state_getKeysPaged", params).await?;
Ok(data)
}
+2 -2
View File
@@ -235,10 +235,10 @@ impl<'a, T: Config> StorageClient<'a, T> {
start_key: Option<StorageKey>,
hash: Option<T::Hash>,
) -> Result<Vec<StorageKey>, BasicError> {
let prefix = StorageKeyPrefix::new::<F>();
let key = StorageKeyPrefix::new::<F>().to_storage_key();
let keys = self
.rpc
.storage_keys_paged(Some(prefix), count, start_key, hash)
.storage_keys_paged(Some(key), count, start_key, hash)
.await?;
Ok(keys)
}