forked from emg110/demo-local-state-expansion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dryrun.py
76 lines (61 loc) · 2.32 KB
/
dryrun.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from typing import List
class DryrunStackValue:
def __init__(self, v):
self.type = v["type"]
self.bytes = v["bytes"]
self.int = v["uint"]
def __str__(self):
if self.type == 1:
return self.bytes
return self.int
class DryrunTraceLine:
def __init__(self, tl):
self.line = tl["line"]
self.pc = tl["pc"]
self.stack = [DryrunStackValue(sv) for sv in tl["stack"]]
def trace_line(self):
return (self.line, [sv.__str__() for sv in self.stack])
class DryrunTrace:
def __init__(self, trace):
self.trace = [DryrunTraceLine(line) for line in trace]
def get_trace(self) -> List[str]:
return [line.trace_line() for line in self.trace]
class DryrunTransactionResult:
def __init__(self, dr):
if "disassembly" in dr:
self.disassembly = dr["disassembly"]
if "app-call-messages" in dr:
self.app_call_messages = dr["app-call-messages"]
if "app-call-trace" in dr:
self.app_call_trace = DryrunTrace(dr["app-call-trace"])
if "local-deltas" in dr:
self.local_deltas = dr["local-deltas"]
if "global-deltas" in dr:
self.global_deltas = dr["global-deltas"]
if "cost" in dr:
self.app_call_cost = dr["cost"]
if "logic-sig-messages" in dr:
self.logic_sig_messages = dr["logic-sig-messages"]
if "logic-sig-trace" in dr:
self.logic_sig_trace = DryrunTrace(dr["logic-sig-trace"])
def app_trace(self):
lines = []
for line in self.app_call_trace.get_trace():
src_line = self.disassembly[line[0] - 1]
lines.append(
"{}{}\t{}".format(src_line, " " * (16 - len(src_line)), line[1])
)
return "\n".join(lines)
def lsig_trace(self):
lines = []
for line in self.logic_sig_trace.get_trace():
src_line = self.disassembly[line[0] - 1]
lines.append(
"{}{}\t{}".format(src_line, " " * (16 - len(src_line)), line[1])
)
return "\n".join(lines)
class DryrunResponse:
def __init__(self, drrjson):
self.error = drrjson["error"]
self.protocol = drrjson["protocol-version"]
self.txns = [DryrunTransactionResult(txn) for txn in drrjson["txns"]]