-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor decode traces * Refactor get second level calls * Add support of debug_traceTransaction method * Upd tests and readme
- Loading branch information
1 parent
b06a408
commit 7121c4c
Showing
12 changed files
with
217 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import type { TraceLogTree, TraceLog, CallType } from '../schema/trace.js' | ||
|
||
export function nodeToTraceLog(node: TraceLogTree, path: number[]): TraceLog | undefined { | ||
let traceLog: TraceLog | undefined | ||
|
||
const traceLogBase = { | ||
subtraces: node.calls?.length ?? 0, | ||
traceAddress: path, | ||
result: { | ||
output: node.output, | ||
gasUsed: node.gasUsed, | ||
}, | ||
} | ||
|
||
switch (node.type) { | ||
case 'CALL': | ||
case 'DELEGATECALL': | ||
case 'CALLCODE': | ||
case 'STATICCALL': | ||
traceLog = { | ||
...traceLogBase, | ||
type: 'call', | ||
action: { | ||
callType: node.type.toLowerCase() as CallType, | ||
from: node.from, | ||
to: node.to, | ||
gas: node.gas, | ||
input: node.input, | ||
value: node.value ?? BigInt('0x0'), | ||
}, | ||
} | ||
break | ||
case 'CREATE': | ||
traceLog = { | ||
...traceLogBase, | ||
type: 'create', | ||
action: { | ||
from: node.from, | ||
gas: node.gas, | ||
value: node.value ?? BigInt('0x0'), | ||
}, | ||
} | ||
break | ||
case 'SELFDESTRUCT': | ||
traceLog = { | ||
...traceLogBase, | ||
type: 'suicide', | ||
action: { | ||
refundAddress: node.to, | ||
address: node.from, | ||
balance: node.value ?? BigInt('0x0'), | ||
}, | ||
} | ||
break | ||
default: | ||
traceLog = undefined | ||
} | ||
|
||
return traceLog | ||
} | ||
|
||
function visit(node: TraceLogTree, path: number[]) { | ||
const children = node.calls | ||
const transformedNode = nodeToTraceLog(node, path) | ||
let result: TraceLog[] = [] | ||
|
||
if (children) { | ||
for (let i = 0; i < children?.length; i++) { | ||
const transformedChildNode = visit(children[i], [...path, i]) | ||
|
||
if (transformedChildNode) { | ||
result = result.concat(transformedChildNode) | ||
} | ||
} | ||
} | ||
|
||
if (transformedNode) { | ||
return result.concat(transformedNode) | ||
} else { | ||
return result | ||
} | ||
} | ||
|
||
export function transformTraceTree(trace: TraceLogTree) { | ||
return visit(trace, []) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.