Refactor parity_listStorageKeys with count parameter optional (#11124)

This commit is contained in:
Juan Aguilar 2019-10-04 14:38:57 +02:00 committed by Andronik Ordian
parent 79aeb95272
commit 4fd1ec643f
7 changed files with 17 additions and 10 deletions

View File

@ -274,7 +274,7 @@ pub trait BlockChainClient:
/// Get a list of all storage keys in the block `id`, if fat DB is in operation, otherwise `None`.
/// If `after` is set the list starts with the following item.
fn list_storage(&self, id: BlockId, account: &Address, after: Option<&H256>, count: u64) -> Option<Vec<H256>>;
fn list_storage(&self, id: BlockId, account: &Address, after: Option<&H256>, count: Option<u64>) -> Option<Vec<H256>>;
/// Get transaction with given hash.
fn transaction(&self, id: TransactionId) -> Option<LocalizedTransaction>;

View File

@ -1805,7 +1805,7 @@ impl BlockChainClient for Client {
Some(accounts)
}
fn list_storage(&self, id: BlockId, account: &Address, after: Option<&H256>, count: u64) -> Option<Vec<H256>> {
fn list_storage(&self, id: BlockId, account: &Address, after: Option<&H256>, count: Option<u64>) -> Option<Vec<H256>> {
if !self.factories.trie.is_fat() {
trace!(target: "fatdb", "list_storage: Not a fat DB");
return None;
@ -1846,9 +1846,16 @@ impl BlockChainClient for Client {
}
}
let keys = iter.filter_map(|item| {
item.ok().map(|(key, _)| H256::from_slice(&key))
}).take(count as usize).collect();
let keys = {
let f = iter.filter_map(|item| {
item.ok().map(|(key, _)| H256::from_slice(&key))
});
if let Some(count) = count {
f.take(count as usize).collect()
} else {
f.collect()
}
};
Some(keys)
}

View File

@ -735,7 +735,7 @@ impl BlockChainClient for TestBlockChainClient {
None
}
fn list_storage(&self, _id: BlockId, _account: &Address, _after: Option<&H256>, _count: u64) -> Option<Vec<H256>> {
fn list_storage(&self, _id: BlockId, _account: &Address, _after: Option<&H256>, _count: Option<u64>) -> Option<Vec<H256>> {
None
}
fn transaction(&self, _id: TransactionId) -> Option<LocalizedTransaction> {

View File

@ -609,7 +609,7 @@ fn execute_export_state(cmd: ExportState) -> Result<(), String> {
out.write_fmt(format_args!(", \"storage\": {{")).expect("Write error");
let mut last_storage: Option<H256> = None;
loop {
let keys = client.list_storage(at, &account, last_storage.as_ref(), 1000).ok_or("Specified block not found")?;
let keys = client.list_storage(at, &account, last_storage.as_ref(), Some(1000)).ok_or("Specified block not found")?;
if keys.is_empty() {
break;
}

View File

@ -203,7 +203,7 @@ where
Err(errors::light_unimplemented(None))
}
fn list_storage_keys(&self, _: H160, _: u64, _: Option<H256>, _: Option<BlockNumber>) -> Result<Option<Vec<H256>>> {
fn list_storage_keys(&self, _: H160, _: Option<u64>, _: Option<H256>, _: Option<BlockNumber>) -> Result<Option<Vec<H256>>> {
Err(errors::light_unimplemented(None))
}

View File

@ -222,7 +222,7 @@ impl<C, M, U, S> Parity for ParityClient<C, M, U> where
.map(|a| a.into_iter().map(Into::into).collect()))
}
fn list_storage_keys(&self, address: H160, count: u64, after: Option<H256>, block_number: Option<BlockNumber>) -> Result<Option<Vec<H256>>> {
fn list_storage_keys(&self, address: H160, count: Option<u64>, after: Option<H256>, block_number: Option<BlockNumber>) -> Result<Option<Vec<H256>>> {
let number = match block_number.unwrap_or_default() {
BlockNumber::Pending => {
warn!("BlockNumber::Pending is unsupported");

View File

@ -117,7 +117,7 @@ pub trait Parity {
/// Returns all storage keys of the given address (first parameter) if Fat DB is enabled (`--fat-db`),
/// or null if not.
#[rpc(name = "parity_listStorageKeys")]
fn list_storage_keys(&self, H160, u64, Option<H256>, Option<BlockNumber>) -> Result<Option<Vec<H256>>>;
fn list_storage_keys(&self, H160, Option<u64>, Option<H256>, Option<BlockNumber>) -> Result<Option<Vec<H256>>>;
/// Encrypt some data with a public key under ECIES.
/// First parameter is the 512-byte destination public key, second is the message.