simplify Client::filter_traces method (#7936)
This commit is contained in:
parent
e79ade59c9
commit
76a098114f
@ -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) {
|
|
||||||
(Some(s), Some(e)) => {
|
|
||||||
let db_filter = trace::Filter {
|
let db_filter = trace::Filter {
|
||||||
range: s as usize..e as usize,
|
range: start as usize..end as usize,
|
||||||
from_address: From::from(filter.from_address),
|
from_address: filter.from_address.into(),
|
||||||
to_address: From::from(filter.to_address),
|
to_address: filter.to_address.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
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> {
|
||||||
|
Loading…
Reference in New Issue
Block a user