diff --git a/evm_trace/display.py b/evm_trace/display.py index a6e8ad9..8fcb9e3 100644 --- a/evm_trace/display.py +++ b/evm_trace/display.py @@ -119,15 +119,18 @@ def make_tree( # Events have no children. return - # Treat events as leaf calls. - for event in root.events: - yield cls(event, parent=displayable_root, is_last=True) - - count = 1 - for child_node in root.calls: - is_last = count == len(root.calls) + # Handle events, which won't have any sub-calls or anything. + total_events = len(root.events) + for index, event in enumerate(root.events, start=1): + is_last = index == total_events + yield cls(event, parent=displayable_root, is_last=is_last) + + # Handle calls (and calls of calls). + total_calls = len(root.calls) + for index, child_node in enumerate(root.calls, start=1): + is_last = index == total_calls + # NOTE: `.make_tree()` will handle calls of calls (recursion). yield from cls.make_tree(child_node, parent=displayable_root, is_last=is_last) - count += 1 def __str__(self) -> str: """