This commit is contained in:
Artem Vorotnikov
2021-12-24 03:03:01 +03:00
parent fbeadc919d
commit e016e11bff
2 changed files with 33 additions and 7 deletions

View File

@@ -188,6 +188,34 @@ where
}
}
/// Walk over duplicates for some specific key.
pub fn walk_dup<'tx: 'cur, 'cur, C, T>(
cursor: &'cur mut C,
start_key: T::Key,
) -> impl Stream<Item = anyhow::Result<(T::Key, T::Value)>> + 'cur
where
C: CursorDupSort<'tx, T>,
T: DupSort,
T::Key: TableDecode,
'tx: 'cur,
{
try_stream! {
let start = cursor.seek_exact(start_key).await?;
if let Some(mut fv) = start {
loop {
yield fv;
match cursor.next_dup().await? {
Some(fv1) => {
fv = fv1;
}
None => break,
}
}
}
}
}
pub fn ttw<'a, T, E>(f: impl Fn(&T) -> bool + 'a) -> impl Fn(&Result<T, E>) -> bool + 'a {
move |res| match res {
Ok(v) => (f)(v),

View File

@@ -16,6 +16,7 @@ use async_trait::async_trait;
use ethereum_types::*;
use rlp::RlpStream;
use std::{cmp, collections::BTreeMap};
use tokio_stream::StreamExt;
use tracing::*;
fn hex_prefix(nibbles: &[u8], user_flag: bool) -> Vec<u8> {
@@ -476,13 +477,10 @@ where
&mut self,
address_hash: H256,
) -> anyhow::Result<Vec<(H256, U256)>> {
let mut storage = Vec::<(H256, U256)>::new();
let mut found = self.storage_cursor.seek_exact(address_hash).await?;
while let Some((_, storage_entry)) = found {
storage.push((storage_entry.0, storage_entry.1));
found = self.storage_cursor.next_dup().await?;
}
Ok(storage)
walk_dup(&mut self.storage_cursor, address_hash)
.map(|res| res.map(|(_, storage_entry)| storage_entry))
.collect()
.await
}
async fn visit_storage(&mut self, address_hash: H256) -> anyhow::Result<H256> {