Skip to content

Commit

Permalink
fix: fix gas profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Feb 17, 2023
1 parent e172e95 commit d102be9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
14 changes: 12 additions & 2 deletions ethtx/models/w3_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,18 @@ def to_object(self) -> Call:
call_type = self.type.lower()
call_data = self.input
return_value = self.output
gas_used = int(self.gasUsed, 16) if self.gasUsed else None
call_gas = int(self.gas, 16) if self.gas else None
gas_used = None
call_gas = None
if self.gasUsed :
if self.gasUsed.startswith("0x"):
gas_used = int(self.gasUsed, 16)
else:
gas_used = self.gasUsed
if self.gas:
if self.gas.startswith("0x"):
call_gas = int(self.gas, 16)
else:
call_gas = self.gas
status = self.error is None
error = self.error
pc = self.pc
Expand Down
11 changes: 10 additions & 1 deletion ethtx/providers/trace_convertor.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,22 @@ def decode(self, tracedata, w3transaction):

self.handleContractChange(item)
self.addFromTotal()
gasUsed = 0
if len(structLogs) > 0:
gasUsed = structLogs[0]["gas"] - (structLogs[len(structLogs)-1]["gas"] - structLogs[len(structLogs)-1]["gasCost"])
self.gas_refund = w3transaction.gas - tracedata["gas"] - (structLogs[len(structLogs)-1]["gas"] - structLogs[len(structLogs)-1]["gasCost"])

else:
self.gas_refund = tracedata["gas"] - tracedata["gas"]


result = {
"type": "CALL",
"from": w3transaction.from_address,
"to": w3transaction.to,
"value": w3transaction.value,
"gas": tracedata["gas"],
"gasUsed": w3transaction.gas ,
"gasUsed": gasUsed,
"input": w3transaction.input,
"output": tracedata["returnValue"],
"time": "",
Expand Down Expand Up @@ -284,4 +292,5 @@ def decode(self, tracedata, w3transaction):
if "jumps" in self.callstack[0]:
result["jumps"] = self.callstack[0]["jumps"]
self.delempty(result)
print("resultdata:%s"%(result["gasUsed"]))
return result

0 comments on commit d102be9

Please sign in to comment.