mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-01 15:57:55 +00:00
Paged keys rpc for child storage. (#9100)
* childstate_getKeysPaged rpc * Rename `v` to `iter`. * Update client/api/src/backend.rs Co-authored-by: Alexander Popiak <alexander.popiak@gmail.com> * Update client/api/src/backend.rs Co-authored-by: Alexander Popiak <alexander.popiak@gmail.com> Co-authored-by: Alexander Popiak <alexander.popiak@gmail.com>
This commit is contained in:
@@ -402,6 +402,16 @@ pub trait ChildStateBackend<Block: BlockT, Client>: Send + Sync + 'static
|
||||
prefix: StorageKey,
|
||||
) -> FutureResult<Vec<StorageKey>>;
|
||||
|
||||
/// Returns the keys with prefix from a child storage with pagination support.
|
||||
fn storage_keys_paged(
|
||||
&self,
|
||||
block: Option<Block::Hash>,
|
||||
storage_key: PrefixedStorageKey,
|
||||
prefix: Option<StorageKey>,
|
||||
count: u32,
|
||||
start_key: Option<StorageKey>,
|
||||
) -> FutureResult<Vec<StorageKey>>;
|
||||
|
||||
/// Returns a child storage entry at a specific block's state.
|
||||
fn storage(
|
||||
&self,
|
||||
@@ -469,6 +479,17 @@ impl<Block, Client> ChildStateApi<Block::Hash> for ChildState<Block, Client>
|
||||
self.backend.storage_keys(block, storage_key, key_prefix)
|
||||
}
|
||||
|
||||
fn storage_keys_paged(
|
||||
&self,
|
||||
storage_key: PrefixedStorageKey,
|
||||
prefix: Option<StorageKey>,
|
||||
count: u32,
|
||||
start_key: Option<StorageKey>,
|
||||
block: Option<Block::Hash>,
|
||||
) -> FutureResult<Vec<StorageKey>> {
|
||||
self.backend.storage_keys_paged(block, storage_key, prefix, count, start_key)
|
||||
}
|
||||
|
||||
fn storage_hash(
|
||||
&self,
|
||||
storage_key: PrefixedStorageKey,
|
||||
|
||||
@@ -296,7 +296,7 @@ impl<BE, Block, Client> StateBackend<Block, Client> for FullState<BE, Block, Cli
|
||||
&BlockId::Hash(block), prefix.as_ref(), start_key.as_ref()
|
||||
)
|
||||
)
|
||||
.map(|v| v.take(count as usize).collect())
|
||||
.map(|iter| iter.take(count as usize).collect())
|
||||
.map_err(client_err)))
|
||||
}
|
||||
|
||||
@@ -618,6 +618,29 @@ impl<BE, Block, Client> ChildStateBackend<Block, Client> for FullState<BE, Block
|
||||
.map_err(client_err)))
|
||||
}
|
||||
|
||||
fn storage_keys_paged(
|
||||
&self,
|
||||
block: Option<Block::Hash>,
|
||||
storage_key: PrefixedStorageKey,
|
||||
prefix: Option<StorageKey>,
|
||||
count: u32,
|
||||
start_key: Option<StorageKey>,
|
||||
) -> FutureResult<Vec<StorageKey>> {
|
||||
Box::new(result(
|
||||
self.block_or_best(block)
|
||||
.and_then(|block| {
|
||||
let child_info = match ChildType::from_prefixed_key(&storage_key) {
|
||||
Some((ChildType::ParentKeyId, storage_key)) => ChildInfo::new_default(storage_key),
|
||||
None => return Err(sp_blockchain::Error::InvalidChildStorageKey),
|
||||
};
|
||||
self.client.child_storage_keys_iter(
|
||||
&BlockId::Hash(block), child_info, prefix.as_ref(), start_key.as_ref(),
|
||||
)
|
||||
})
|
||||
.map(|iter| iter.take(count as usize).collect())
|
||||
.map_err(client_err)))
|
||||
}
|
||||
|
||||
fn storage(
|
||||
&self,
|
||||
block: Option<Block::Hash>,
|
||||
|
||||
@@ -509,6 +509,17 @@ impl<Block, F, Client> ChildStateBackend<Block, Client> for LightState<Block, F,
|
||||
Box::new(result(Err(client_err(ClientError::NotAvailableOnLightClient))))
|
||||
}
|
||||
|
||||
fn storage_keys_paged(
|
||||
&self,
|
||||
_block: Option<Block::Hash>,
|
||||
_storage_key: PrefixedStorageKey,
|
||||
_prefix: Option<StorageKey>,
|
||||
_count: u32,
|
||||
_start_key: Option<StorageKey>,
|
||||
) -> FutureResult<Vec<StorageKey>> {
|
||||
Box::new(result(Err(client_err(ClientError::NotAvailableOnLightClient))))
|
||||
}
|
||||
|
||||
fn storage(
|
||||
&self,
|
||||
block: Option<Block::Hash>,
|
||||
|
||||
Reference in New Issue
Block a user