Skip to content

Commit

Permalink
fix(rpc-trace): add after and count to trace_filter (paradigmxyz#9662)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Seitz <[email protected]>
  • Loading branch information
tsnewnami and mattsse authored Jul 22, 2024
1 parent 875b3f0 commit cfa3681
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion crates/rpc/rpc/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ where
filter: TraceFilter,
) -> EthResult<Vec<LocalizedTransactionTrace>> {
let matcher = filter.matcher();
let TraceFilter { from_block, to_block, .. } = filter;
let TraceFilter { from_block, to_block, after, count, .. } = filter;
let start = from_block.unwrap_or(0);
let end = if let Some(to_block) = to_block {
to_block
Expand Down Expand Up @@ -341,6 +341,20 @@ where
}
}

// apply after and count to traces if specified, this allows for a pagination style.
// only consider traces after
if let Some(after) = after.map(|a| a as usize).filter(|a| *a < all_traces.len()) {
all_traces = all_traces.split_off(after);
}

// at most, return count of traces
if let Some(count) = count {
let count = count as usize;
if count < all_traces.len() {
all_traces.truncate(count);
}
};

Ok(all_traces)
}

Expand Down

0 comments on commit cfa3681

Please sign in to comment.