Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Offset and count moved into filter object
Browse files Browse the repository at this point in the history
  • Loading branch information
grbIzl committed Sep 11, 2017
1 parent 44bd019 commit b316852
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 33 deletions.
10 changes: 5 additions & 5 deletions ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1658,25 +1658,25 @@ impl BlockChainClient for Client {
self.chain.read().logs(blocks, |entry| filter.matches(entry), filter.limit)
}

fn filter_traces(&self, filter: TraceFilter, after: Option<usize>, count: Option<usize>) -> Option<Vec<LocalizedTrace>> {
fn filter_traces(&self, filter: TraceFilter) -> Option<Vec<LocalizedTrace>> {
let start = self.block_number(filter.range.start);
let end = self.block_number(filter.range.end);

match (start, end) {
(Some(s), Some(e)) => {
let filter = trace::Filter {
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 traces = self.tracedb.read().filter(&filter);
let traces = self.tracedb.read().filter(&db_filter);
if traces.is_empty() {
return None;
}

let traces_iter = traces.into_iter().skip(after.unwrap_or(0));
Some(match count {
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(),
})
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/client/test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ impl BlockChainClient for TestBlockChainClient {
}
}

fn filter_traces(&self, _filter: TraceFilter, _after: Option<usize>, _count: Option<usize>) -> Option<Vec<LocalizedTrace>> {
fn filter_traces(&self, _filter: TraceFilter) -> Option<Vec<LocalizedTrace>> {
self.traces.read().clone()
}

Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/client/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ pub trait BlockChainClient : Sync + Send {
fn replay(&self, t: TransactionId, analytics: CallAnalytics) -> Result<Executed, CallError>;

/// Returns traces matching given filter.
fn filter_traces(&self, filter: TraceFilter, after: Option<usize>, count: Option<usize>) -> Option<Vec<LocalizedTrace>>;
fn filter_traces(&self, filter: TraceFilter) -> Option<Vec<LocalizedTrace>>;

/// Returns trace with given id.
fn trace(&self, trace: TraceId) -> Option<LocalizedTrace>;
Expand Down
4 changes: 4 additions & 0 deletions ethcore/types/src/trace_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ pub struct Filter {
pub from_address: Vec<Address>,
/// To address.
pub to_address: Vec<Address>,
/// Output offset
pub after: Option<usize>,
/// Output amount
pub count: Option<usize>,
}
4 changes: 2 additions & 2 deletions js/src/api/rpc/trace/trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ export default class Trace {
.then(outTraceReplay);
}

filter (filterObj, offset = null, count = null) {
filter (filterObj) {
return this._transport
.execute('trace_filter', inTraceFilter(filterObj), offset, count)
.execute('trace_filter', inTraceFilter(filterObj))
.then(outTraces);
}

Expand Down
26 changes: 13 additions & 13 deletions js/src/jsonrpc/interfaces/trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,26 +134,26 @@ then it should look something like:
type: Address,
desc: 'Sent to these addresses.',
optional: true
},
after: {
type: Quantity,
desc: 'The offset trace number',
optional: true
},
count: {
type: Quantity,
desc: 'Integer number of traces to display in a batch.',
optional: true
}
},
example: {
fromBlock: fromDecimal(3068100),
toBlock: fromDecimal(3068200),
toAddress: ['0x8bbB73BCB5d553B5A556358d27625323Fd781D37']
toAddress: ['0x8bbB73BCB5d553B5A556358d27625323Fd781D37'],
after: 1000,
count: 100
}
},
{
type: Quantity,
desc: 'The offset trace index',
optional: true,
example: 10
},
{
type: Quantity,
desc: 'Integer number of traces to display in a batch.',
example: 5,
optional: true
}
],
returns: {
type: Array,
Expand Down
4 changes: 1 addition & 3 deletions js/src/views/RpcCalls/data/rpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -1052,9 +1052,7 @@
"name": "trace_filter",
"desc": "Returns traces matching given filter",
"params": [
"`OBJECT` - The filter object",
"`INTEGER` - (optional) The offset number for trace output",
"`INTEGER` - (optional) Amount of traces to output"
"`OBJECT` - The filter object"
],
"returns": "`ARRAY` - Traces matching given filter",
"inputFormatters": [],
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/v1/impls/light/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct TracesClient;
impl Traces for TracesClient {
type Metadata = Metadata;

fn filter(&self, _filter: TraceFilter, _offset: Option<usize>, _count: Option<usize>) -> Result<Option<Vec<LocalizedTrace>>, Error> {
fn filter(&self, _filter: TraceFilter) -> Result<Option<Vec<LocalizedTrace>>, Error> {
Err(errors::light_unimplemented(None))
}

Expand Down
4 changes: 2 additions & 2 deletions rpc/src/v1/impls/traces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ impl<C, M> TracesClient<C, M> {
impl<C, M> Traces for TracesClient<C, M> where C: MiningBlockChainClient + 'static, M: MinerService + 'static {
type Metadata = Metadata;

fn filter(&self, filter: TraceFilter, offset: Option<usize>, count: Option<usize>) -> Result<Option<Vec<LocalizedTrace>>, Error> {
Ok(self.client.filter_traces(filter.into(), offset, count)
fn filter(&self, filter: TraceFilter) -> Result<Option<Vec<LocalizedTrace>>, Error> {
Ok(self.client.filter_traces(filter.into())
.map(|traces| traces.into_iter().map(LocalizedTrace::from).collect()))
}

Expand Down
4 changes: 2 additions & 2 deletions rpc/src/v1/tests/mocked/traces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn io() -> Tester {
fn rpc_trace_filter() {
let tester = io();

let request = r#"{"jsonrpc":"2.0","method":"trace_filter","params": [{}, null, null],"id":1}"#;
let request = r#"{"jsonrpc":"2.0","method":"trace_filter","params": [{}],"id":1}"#;
let response = r#"{"jsonrpc":"2.0","result":[{"action":{"callType":"call","from":"0x000000000000000000000000000000000000000f","gas":"0x100","input":"0x010203","to":"0x0000000000000000000000000000000000000010","value":"0x1"},"blockHash":"0x000000000000000000000000000000000000000000000000000000000000000a","blockNumber":10,"result":null,"subtraces":0,"traceAddress":[0],"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000005","transactionPosition":0,"type":"call"}],"id":1}"#;

assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
Expand All @@ -92,7 +92,7 @@ fn rpc_trace_filter_missing_trace() {
let tester = io();
*tester.client.traces.write() = None;

let request = r#"{"jsonrpc":"2.0","method":"trace_filter","params": [{}, null, null],"id":1}"#;
let request = r#"{"jsonrpc":"2.0","method":"trace_filter","params": [{}],"id":1}"#;
let response = r#"{"jsonrpc":"2.0","result":null,"id":1}"#;

assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/v1/traits/traces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ build_rpc_trait! {

/// Returns traces matching given filter.
#[rpc(name = "trace_filter")]
fn filter(&self, TraceFilter, Option<usize>, Option<usize>) -> Result<Option<Vec<LocalizedTrace>>, Error>;
fn filter(&self, TraceFilter) -> Result<Option<Vec<LocalizedTrace>>, Error>;

/// Returns transaction trace at given index.
#[rpc(name = "trace_get")]
Expand Down
16 changes: 14 additions & 2 deletions rpc/src/v1/types/trace_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ pub struct TraceFilter {
/// To address
#[serde(rename="toAddress")]
pub to_address: Option<Vec<H160>>,
/// Output offset
pub after: Option<usize>,
/// Output amount
pub count: Option<usize>,
}

impl Into<client::TraceFilter> for TraceFilter {
Expand All @@ -46,6 +50,8 @@ impl Into<client::TraceFilter> for TraceFilter {
range: start..end,
from_address: self.from_address.map_or_else(Vec::new, |x| x.into_iter().map(Into::into).collect()),
to_address: self.to_address.map_or_else(Vec::new, |x| x.into_iter().map(Into::into).collect()),
after: self.after,
count: self.count,
}
}
}
Expand All @@ -64,7 +70,9 @@ mod tests {
from_block: None,
to_block: None,
from_address: None,
to_address: None
to_address: None,
after: None,
count: None,
});
}

Expand All @@ -74,14 +82,18 @@ mod tests {
"fromBlock": "latest",
"toBlock": "latest",
"fromAddress": ["0x0000000000000000000000000000000000000003"],
"toAddress": ["0x0000000000000000000000000000000000000005"]
"toAddress": ["0x0000000000000000000000000000000000000005"],
"after": 50,
"count": 100
}"#;
let deserialized: TraceFilter = serde_json::from_str(s).unwrap();
assert_eq!(deserialized, TraceFilter {
from_block: Some(BlockNumber::Latest),
to_block: Some(BlockNumber::Latest),
from_address: Some(vec![Address::from(3).into()]),
to_address: Some(vec![Address::from(5).into()]),
after: 50.into(),
count: 100.into(),
});
}
}

0 comments on commit b316852

Please sign in to comment.