simplify Client::filter_traces method (#7936)

This commit is contained in:
Marek Kotewicz 2018-02-18 23:02:02 +01:00 committed by Rando
parent e79ade59c9
commit 76a098114f

View File

@ -1692,30 +1692,22 @@ impl BlockChainClient for Client {
} }
fn filter_traces(&self, filter: TraceFilter) -> Option<Vec<LocalizedTrace>> { fn filter_traces(&self, filter: TraceFilter) -> Option<Vec<LocalizedTrace>> {
let start = self.block_number(filter.range.start); let start = self.block_number(filter.range.start)?;
let end = self.block_number(filter.range.end); let end = self.block_number(filter.range.end)?;
match (start, end) { let db_filter = trace::Filter {
(Some(s), Some(e)) => { range: start as usize..end as usize,
let db_filter = trace::Filter { from_address: filter.from_address.into(),
range: s as usize..e as usize, to_address: filter.to_address.into(),
from_address: From::from(filter.from_address), };
to_address: From::from(filter.to_address),
};
let traces = self.tracedb.read().filter(&db_filter); let traces = self.tracedb.read()
if traces.is_empty() { .filter(&db_filter)
return Some(vec![]); .into_iter()
} .skip(filter.after.unwrap_or(0))
.take(filter.count.unwrap_or(usize::max_value()))
let traces_iter = traces.into_iter().skip(filter.after.unwrap_or(0)); .collect();
Some(match filter.count { Some(traces)
Some(count) => traces_iter.take(count).collect(),
None => traces_iter.collect(),
})
},
_ => None,
}
} }
fn trace(&self, trace: TraceId) -> Option<LocalizedTrace> { fn trace(&self, trace: TraceId) -> Option<LocalizedTrace> {