From 76a098114f512644fb97405d952e80b527c454ea Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Sun, 18 Feb 2018 23:02:02 +0100 Subject: [PATCH] simplify Client::filter_traces method (#7936) --- ethcore/src/client/client.rs | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 08faf286f..96fae13d7 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -1692,30 +1692,22 @@ impl BlockChainClient for Client { } fn filter_traces(&self, filter: TraceFilter) -> Option> { - let start = self.block_number(filter.range.start); - let end = self.block_number(filter.range.end); + let start = self.block_number(filter.range.start)?; + let end = self.block_number(filter.range.end)?; - match (start, end) { - (Some(s), Some(e)) => { - let db_filter = trace::Filter { - range: s as usize..e as usize, - from_address: From::from(filter.from_address), - to_address: From::from(filter.to_address), - }; + let db_filter = trace::Filter { + range: start as usize..end as usize, + from_address: filter.from_address.into(), + to_address: filter.to_address.into(), + }; - let traces = self.tracedb.read().filter(&db_filter); - if traces.is_empty() { - return Some(vec![]); - } - - let traces_iter = traces.into_iter().skip(filter.after.unwrap_or(0)); - Some(match filter.count { - Some(count) => traces_iter.take(count).collect(), - None => traces_iter.collect(), - }) - }, - _ => None, - } + let traces = self.tracedb.read() + .filter(&db_filter) + .into_iter() + .skip(filter.after.unwrap_or(0)) + .take(filter.count.unwrap_or(usize::max_value())) + .collect(); + Some(traces) } fn trace(&self, trace: TraceId) -> Option {