fix(rpc-trace): add after and count to trace_filter (#9662)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
EdwardJES
2024-07-22 17:53:41 +10:00
committed by GitHub
parent 875b3f0c59
commit cfa3681b27

View File

@@ -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
@@ -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)
}