new state api state_getKeys to expose storage keys (#1380)

This commit is contained in:
Xiliang Chen
2019-01-12 00:51:19 +13:00
committed by Gav Wood
parent bf51b8a5ad
commit 0e569e6bf2
7 changed files with 56 additions and 0 deletions
+10
View File
@@ -51,6 +51,10 @@ build_rpc_trait! {
#[rpc(name = "state_call", alias = ["state_callAt", ])]
fn call(&self, String, Bytes, Trailing<Hash>) -> Result<Bytes>;
/// Returns the keys with prefix, leave empty to get all the keys
#[rpc(name = "state_getKeys")]
fn storage_keys(&self, StorageKey, Trailing<Hash>) -> Result<Vec<StorageKey>>;
/// Returns a storage entry at a specific block's state.
#[rpc(name = "state_getStorage", alias = ["state_getStorageAt", ])]
fn storage(&self, StorageKey, Trailing<Hash>) -> Result<Option<StorageData>>;
@@ -148,6 +152,12 @@ impl<B, E, Block, RA> StateApi<Block::Hash> for State<B, E, Block, RA> where
Ok(Bytes(return_data))
}
fn storage_keys(&self, key_prefix: StorageKey, block: Trailing<Block::Hash>) -> Result<Vec<StorageKey>> {
let block = self.unwrap_or_best(block)?;
trace!(target: "rpc", "Querying storage keys at {:?}", block);
Ok(self.client.storage_keys(&BlockId::Hash(block), &key_prefix)?)
}
fn storage(&self, key: StorageKey, block: Trailing<Block::Hash>) -> Result<Option<StorageData>> {
let block = self.unwrap_or_best(block)?;
trace!(target: "rpc", "Querying storage at {:?} for key {}", block, HexDisplay::from(&key.0));