Skip to content

Commit 64f4031

Browse files
authored
Merge pull request #8 from unparalleled-js/feat/jules/fixes-from-alchemy
fix: better handling of None gas and parity reverts
2 parents eeb3515 + 9c16880 commit 64f4031

File tree

6 files changed

+340
-25
lines changed

6 files changed

+340
-25
lines changed

evm_trace/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import math
2-
from typing import Any, Dict, Iterable, Iterator, List, Optional, Type
2+
from typing import Any, Dict, Iterator, List, Optional, Type
33

44
from eth_utils import to_int
55
from hexbytes import HexBytes
@@ -50,7 +50,7 @@ class CallTreeNode(BaseModel):
5050
display_cls: Type[DisplayableCallTreeNode] = DisplayableCallTreeNode
5151

5252
@property
53-
def display_nodes(self) -> Iterable[DisplayableCallTreeNode]:
53+
def display_nodes(self) -> Iterator[DisplayableCallTreeNode]:
5454
return self.display_cls.make_tree(self)
5555

5656
@validator("address", "calldata", "returndata", pre=True)

evm_trace/display.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import TYPE_CHECKING, Iterable, Optional
1+
from typing import TYPE_CHECKING, Iterator, Optional
22

33
from eth_utils import to_checksum_address
44

@@ -38,20 +38,28 @@ def title(self) -> str:
3838
address = address_hex_str
3939

4040
cost = self.call.gas_cost
41-
42-
call_path = str(address)
41+
call_path = str(address) if address else ""
4342
if self.call.calldata:
44-
call_path = f"{call_path}.<{self.call.calldata[:4].hex()}>"
43+
call_path = f"{call_path}." if call_path else ""
44+
call_path = f"{call_path}<{self.call.calldata[:4].hex()}>"
45+
46+
call_path = (
47+
f"[reverted] {call_path}" if self.call.failed and self.parent is None else call_path
48+
)
49+
call_path = call_path.strip()
50+
node_title = f"{call_type}: {call_path}" if call_path else call_type
51+
if cost is not None:
52+
node_title = f"{node_title} [{cost} gas]"
4553

46-
return f"{call_type}: {call_path} [{cost} gas]"
54+
return node_title
4755

4856
@classmethod
4957
def make_tree(
5058
cls,
5159
root: "CallTreeNode",
5260
parent: Optional["DisplayableCallTreeNode"] = None,
5361
is_last: bool = False,
54-
) -> Iterable["DisplayableCallTreeNode"]:
62+
) -> Iterator["DisplayableCallTreeNode"]:
5563
displayable_root = cls(root, parent=parent, is_last=is_last)
5664
yield displayable_root
5765

evm_trace/parity.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List, Optional, Type, Union
1+
from typing import Any, Dict, List, Optional, Type, Union
22

33
from pydantic import BaseModel, Field, validator
44

@@ -96,6 +96,7 @@ def get_calltree_from_parity_trace(
9696
traces: ParityTraceList,
9797
root: Optional[ParityTrace] = None,
9898
display_cls: Type[DisplayableCallTreeNode] = DisplayableCallTreeNode,
99+
**root_kwargs,
99100
) -> CallTreeNode:
100101
"""
101102
Create a :class:`~evm_trace.base.CallTreeNode` from output models using the Parity approach
@@ -108,17 +109,19 @@ def get_calltree_from_parity_trace(
108109
the first item by default.
109110
display_cls (Type[DisplayableCallTreeNode]]: A custom class to use for representing
110111
the call tree. Defaults to :class:`~evm_trace.display.DisplayableCallTreeNode`.
112+
**root_kwargs: Additional kwargs to append to the root node. Useful for adding gas for
113+
reverted calls.
111114
112115
Returns:
113116
:class:`~evm_trace.base.CallTreeNode`
114117
"""
115-
if root is None:
116-
root = traces[0]
117-
118-
node_kwargs = dict(
118+
root = root or traces[0]
119+
failed = root.error is not None
120+
node_kwargs: Dict[Any, Any] = dict(
119121
call_type=root.call_type,
120-
error=root.error is not None,
122+
failed=failed,
121123
display_cls=display_cls,
124+
**root_kwargs,
122125
)
123126

124127
if root.call_type == CallType.CREATE:
Lines changed: 285 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,285 @@
1+
[
2+
{
3+
"action": {
4+
"from": "0x7768fbc67afecf2b4caee9d1841ad14637d13652",
5+
"callType": "call",
6+
"gas": "0x3c8c1",
7+
"input": "0x5ae401dc0000000000000000000000000000000000000000000000000000000062a8f38e00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000e4472b43f300000000000000000000000000000000000000000000000007b3c18f3a57800000000000000000000000000000000000000000000000000009288316522878cc00000000000000000000000000000000000000000000000000000000000000800000000000000000000000007768fbc67afecf2b4caee9d1841ad14637d136520000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000005be7632014b307bd29304bbceab6478a89fa738400000000000000000000000000000000000000000000000000000000",
8+
"to": "0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45",
9+
"value": "0x7b3c18f3a578000"
10+
},
11+
"blockHash": "0x5126b891b46a265d31df884f4cffadbdfed6e34d8be4d93694d200ccc48e72d6",
12+
"blockNumber": 14963663,
13+
"error": "Reverted",
14+
"result": null,
15+
"subtraces": 1,
16+
"traceAddress": [],
17+
"transactionHash": "0x15cddbe410208d3c819a6f2ee50b8cc9c4b0f3362ca2f99fe1bf5c0ab955b1f7",
18+
"transactionPosition": 248,
19+
"type": "call"
20+
},
21+
{
22+
"action": {
23+
"from": "0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45",
24+
"callType": "delegatecall",
25+
"gas": "0x3b497",
26+
"input": "0x472b43f300000000000000000000000000000000000000000000000007b3c18f3a57800000000000000000000000000000000000000000000000000009288316522878cc00000000000000000000000000000000000000000000000000000000000000800000000000000000000000007768fbc67afecf2b4caee9d1841ad14637d136520000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000005be7632014b307bd29304bbceab6478a89fa7384",
27+
"to": "0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45",
28+
"value": "0x7b3c18f3a578000"
29+
},
30+
"blockHash": "0x5126b891b46a265d31df884f4cffadbdfed6e34d8be4d93694d200ccc48e72d6",
31+
"blockNumber": 14963663,
32+
"error": "Reverted",
33+
"result": null,
34+
"subtraces": 7,
35+
"traceAddress": [
36+
0
37+
],
38+
"transactionHash": "0x15cddbe410208d3c819a6f2ee50b8cc9c4b0f3362ca2f99fe1bf5c0ab955b1f7",
39+
"transactionPosition": 248,
40+
"type": "call"
41+
},
42+
{
43+
"action": {
44+
"from": "0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45",
45+
"callType": "call",
46+
"gas": "0x379a1",
47+
"input": "0xd0e30db0",
48+
"to": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
49+
"value": "0x7b3c18f3a578000"
50+
},
51+
"blockHash": "0x5126b891b46a265d31df884f4cffadbdfed6e34d8be4d93694d200ccc48e72d6",
52+
"blockNumber": 14963663,
53+
"result": {
54+
"gasUsed": "0x5da6",
55+
"output": "0x"
56+
},
57+
"subtraces": 0,
58+
"traceAddress": [
59+
0,
60+
0
61+
],
62+
"transactionHash": "0x15cddbe410208d3c819a6f2ee50b8cc9c4b0f3362ca2f99fe1bf5c0ab955b1f7",
63+
"transactionPosition": 248,
64+
"type": "call"
65+
},
66+
{
67+
"action": {
68+
"from": "0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45",
69+
"callType": "call",
70+
"gas": "0x31bc9",
71+
"input": "0xa9059cbb0000000000000000000000002c6b0aa42d4fcb880f5ffffbd0e39e4b48548c1e00000000000000000000000000000000000000000000000007b3c18f3a578000",
72+
"to": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
73+
"value": "0x0"
74+
},
75+
"blockHash": "0x5126b891b46a265d31df884f4cffadbdfed6e34d8be4d93694d200ccc48e72d6",
76+
"blockNumber": 14963663,
77+
"result": {
78+
"gasUsed": "0x1f7e",
79+
"output": "0x0000000000000000000000000000000000000000000000000000000000000001"
80+
},
81+
"subtraces": 0,
82+
"traceAddress": [
83+
0,
84+
1
85+
],
86+
"transactionHash": "0x15cddbe410208d3c819a6f2ee50b8cc9c4b0f3362ca2f99fe1bf5c0ab955b1f7",
87+
"transactionPosition": 248,
88+
"type": "call"
89+
},
90+
{
91+
"action": {
92+
"from": "0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45",
93+
"callType": "staticcall",
94+
"gas": "0x2f059",
95+
"input": "0x70a082310000000000000000000000007768fbc67afecf2b4caee9d1841ad14637d13652",
96+
"to": "0x5be7632014b307bd29304bbceab6478a89fa7384",
97+
"value": "0x0"
98+
},
99+
"blockHash": "0x5126b891b46a265d31df884f4cffadbdfed6e34d8be4d93694d200ccc48e72d6",
100+
"blockNumber": 14963663,
101+
"result": {
102+
"gasUsed": "0x1a14",
103+
"output": "0x0000000000000000000000000000000000000000000000000000000000000000"
104+
},
105+
"subtraces": 0,
106+
"traceAddress": [
107+
0,
108+
2
109+
],
110+
"transactionHash": "0x15cddbe410208d3c819a6f2ee50b8cc9c4b0f3362ca2f99fe1bf5c0ab955b1f7",
111+
"transactionPosition": 248,
112+
"type": "call"
113+
},
114+
{
115+
"action": {
116+
"from": "0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45",
117+
"callType": "staticcall",
118+
"gas": "0x2c6b3",
119+
"input": "0x0902f1ac",
120+
"to": "0x2c6b0aa42d4fcb880f5ffffbd0e39e4b48548c1e",
121+
"value": "0x0"
122+
},
123+
"blockHash": "0x5126b891b46a265d31df884f4cffadbdfed6e34d8be4d93694d200ccc48e72d6",
124+
"blockNumber": 14963663,
125+
"result": {
126+
"gasUsed": "0x9c8",
127+
"output": "0x000000000000000000000000000000000000000000000000caa825830eefc756000000000000000000000000000000000000000000000000b73b0cd356c097060000000000000000000000000000000000000000000000000000000062a8ef1e"
128+
},
129+
"subtraces": 0,
130+
"traceAddress": [
131+
0,
132+
3
133+
],
134+
"transactionHash": "0x15cddbe410208d3c819a6f2ee50b8cc9c4b0f3362ca2f99fe1bf5c0ab955b1f7",
135+
"transactionPosition": 248,
136+
"type": "call"
137+
},
138+
{
139+
"action": {
140+
"from": "0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45",
141+
"callType": "staticcall",
142+
"gas": "0x2b9bd",
143+
"input": "0x70a082310000000000000000000000002c6b0aa42d4fcb880f5ffffbd0e39e4b48548c1e",
144+
"to": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
145+
"value": "0x0"
146+
},
147+
"blockHash": "0x5126b891b46a265d31df884f4cffadbdfed6e34d8be4d93694d200ccc48e72d6",
148+
"blockNumber": 14963663,
149+
"result": {
150+
"gasUsed": "0x216",
151+
"output": "0x000000000000000000000000000000000000000000000000beeece6291181706"
152+
},
153+
"subtraces": 0,
154+
"traceAddress": [
155+
0,
156+
4
157+
],
158+
"transactionHash": "0x15cddbe410208d3c819a6f2ee50b8cc9c4b0f3362ca2f99fe1bf5c0ab955b1f7",
159+
"transactionPosition": 248,
160+
"type": "call"
161+
},
162+
{
163+
"action": {
164+
"from": "0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45",
165+
"callType": "call",
166+
"gas": "0x2b124",
167+
"input": "0x022c0d9f0000000000000000000000000000000000000000000000000826cda4f5acb78e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000007768fbc67afecf2b4caee9d1841ad14637d1365200000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000",
168+
"to": "0x2c6b0aa42d4fcb880f5ffffbd0e39e4b48548c1e",
169+
"value": "0x0"
170+
},
171+
"blockHash": "0x5126b891b46a265d31df884f4cffadbdfed6e34d8be4d93694d200ccc48e72d6",
172+
"blockNumber": 14963663,
173+
"result": {
174+
"gasUsed": "0x1d480",
175+
"output": "0x"
176+
},
177+
"subtraces": 3,
178+
"traceAddress": [
179+
0,
180+
5
181+
],
182+
"transactionHash": "0x15cddbe410208d3c819a6f2ee50b8cc9c4b0f3362ca2f99fe1bf5c0ab955b1f7",
183+
"transactionPosition": 248,
184+
"type": "call"
185+
},
186+
{
187+
"action": {
188+
"from": "0x2c6b0aa42d4fcb880f5ffffbd0e39e4b48548c1e",
189+
"callType": "call",
190+
"gas": "0x27c8f",
191+
"input": "0xa9059cbb0000000000000000000000007768fbc67afecf2b4caee9d1841ad14637d136520000000000000000000000000000000000000000000000000826cda4f5acb78e",
192+
"to": "0x5be7632014b307bd29304bbceab6478a89fa7384",
193+
"value": "0x0"
194+
},
195+
"blockHash": "0x5126b891b46a265d31df884f4cffadbdfed6e34d8be4d93694d200ccc48e72d6",
196+
"blockNumber": 14963663,
197+
"result": {
198+
"gasUsed": "0x1764b",
199+
"output": "0x0000000000000000000000000000000000000000000000000000000000000001"
200+
},
201+
"subtraces": 0,
202+
"traceAddress": [
203+
0,
204+
5,
205+
0
206+
],
207+
"transactionHash": "0x15cddbe410208d3c819a6f2ee50b8cc9c4b0f3362ca2f99fe1bf5c0ab955b1f7",
208+
"transactionPosition": 248,
209+
"type": "call"
210+
},
211+
{
212+
"action": {
213+
"from": "0x2c6b0aa42d4fcb880f5ffffbd0e39e4b48548c1e",
214+
"callType": "staticcall",
215+
"gas": "0x109b0",
216+
"input": "0x70a082310000000000000000000000002c6b0aa42d4fcb880f5ffffbd0e39e4b48548c1e",
217+
"to": "0x5be7632014b307bd29304bbceab6478a89fa7384",
218+
"value": "0x0"
219+
},
220+
"blockHash": "0x5126b891b46a265d31df884f4cffadbdfed6e34d8be4d93694d200ccc48e72d6",
221+
"blockNumber": 14963663,
222+
"result": {
223+
"gasUsed": "0xa74",
224+
"output": "0x000000000000000000000000000000000000000000000000c28157de19430fc8"
225+
},
226+
"subtraces": 0,
227+
"traceAddress": [
228+
0,
229+
5,
230+
1
231+
],
232+
"transactionHash": "0x15cddbe410208d3c819a6f2ee50b8cc9c4b0f3362ca2f99fe1bf5c0ab955b1f7",
233+
"transactionPosition": 248,
234+
"type": "call"
235+
},
236+
{
237+
"action": {
238+
"from": "0x2c6b0aa42d4fcb880f5ffffbd0e39e4b48548c1e",
239+
"callType": "staticcall",
240+
"gas": "0xfdd0",
241+
"input": "0x70a082310000000000000000000000002c6b0aa42d4fcb880f5ffffbd0e39e4b48548c1e",
242+
"to": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
243+
"value": "0x0"
244+
},
245+
"blockHash": "0x5126b891b46a265d31df884f4cffadbdfed6e34d8be4d93694d200ccc48e72d6",
246+
"blockNumber": 14963663,
247+
"result": {
248+
"gasUsed": "0x216",
249+
"output": "0x000000000000000000000000000000000000000000000000beeece6291181706"
250+
},
251+
"subtraces": 0,
252+
"traceAddress": [
253+
0,
254+
5,
255+
2
256+
],
257+
"transactionHash": "0x15cddbe410208d3c819a6f2ee50b8cc9c4b0f3362ca2f99fe1bf5c0ab955b1f7",
258+
"transactionPosition": 248,
259+
"type": "call"
260+
},
261+
{
262+
"action": {
263+
"from": "0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45",
264+
"callType": "staticcall",
265+
"gas": "0xe144",
266+
"input": "0x70a082310000000000000000000000007768fbc67afecf2b4caee9d1841ad14637d13652",
267+
"to": "0x5be7632014b307bd29304bbceab6478a89fa7384",
268+
"value": "0x0"
269+
},
270+
"blockHash": "0x5126b891b46a265d31df884f4cffadbdfed6e34d8be4d93694d200ccc48e72d6",
271+
"blockNumber": 14963663,
272+
"result": {
273+
"gasUsed": "0xa74",
274+
"output": "0x0000000000000000000000000000000000000000000000000794ba2117ad6d45"
275+
},
276+
"subtraces": 0,
277+
"traceAddress": [
278+
0,
279+
6
280+
],
281+
"transactionHash": "0x15cddbe410208d3c819a6f2ee50b8cc9c4b0f3362ca2f99fe1bf5c0ab955b1f7",
282+
"transactionPosition": 248,
283+
"type": "call"
284+
}
285+
]

0 commit comments

Comments
 (0)