Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add trace depth #9

Open
wants to merge 1 commit into
base: attester-poc
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions py-sdk/src/forta_bot_sdk/traces/parse_debug_traces_and_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ def parse_debug_traces_and_logs(debug_trace: dict) -> Tuple[list[Trace], list[Lo
raw_logs: list[dict] = []

stack = deque()
stack.append(debug_trace)
stack.append((debug_trace, []))
while (len(stack) > 0):
trace = stack.pop()
trace, depth = stack.pop()
subtraces = trace.get("calls") or []
trace_dict = {
"trace_address": depth,
"action": {
"callType": trace.get("type").lower(),
"to": trace.get("to"),
Expand All @@ -45,8 +46,9 @@ def parse_debug_traces_and_logs(debug_trace: dict) -> Tuple[list[Trace], list[Lo
for log in trace.get("logs"):
raw_logs.append(log)
# add any sub-traces to the stack (reversed so that we pop the first subtrace first)
for subtrace in reversed(subtraces):
stack.append(subtrace)
for index, subtrace in reversed(list(enumerate(subtraces))):
child_depth = depth + [index]
stack.append((subtrace, child_depth))

if len(raw_logs) > 0:
# some chains (e.g. arbitrum) use different field name for log index
Expand Down