-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContractStripper.py
99 lines (91 loc) · 3.53 KB
/
ContractStripper.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from tkinter import filedialog
import pickle #remove this line when implementing
StripThis=pickle.load(open("c:\\Users\\david\\Downloads\\pickle.pkl",'rb')) #set StripThis as your contract string
ContractLanguage='.sol' #I guess pass the language through here? Takes input ".vy", ".rs", or ".sol"
def StripSolContract(StripThis):
file=StripThis
LineList=[]
for line in file.splitlines():
TestLine=line.replace(" ","")
if '//' in line:
AppendThis=line.split('//',1)[0]
MaybeAppendThis=AppendThis.replace(" ","")
if MaybeAppendThis != "":
LineList.append(AppendThis)
pass
elif TestLine is not "":
AppendThis=line
LineList.append(AppendThis)
return LineList
def StripVyContract(StripThis):
file=StripThis
LineList=[]
SkipThisLine=False
for line in file.splitlines():
if SkipThisLine is False:
if '#' in line:
if line == "#":
continue
AppendThis=line.split('#')[0]
MaybeAppendThis=AppendThis.replace(" ","")
if len(MaybeAppendThis)<=1:
continue
elif MaybeAppendThis.split()[0]=="#":
continue
elif MaybeAppendThis is not "":
LineList.append(AppendThis)
continue
elif "'''" in line:
LeftLine=line.split("'''",1)[0]
MaybeLeftLine=LeftLine.replace(" ","")
SkipThisLine=True
if MaybeLeftLine!="" and MaybeLeftLine != "'''":
LineList.append(LeftLine)
continue
elif '"""' in line:
LeftLine=line.split('"""',1)[0]
MaybeLeftLine=LeftLine.replace(" ","")
SkipThisLine=True
if MaybeLeftLine!="" and MaybeLeftLine != '"""' and LeftLine !="":
LineList.append(LeftLine)
continue
else:
if line.replace(' ','') is not "":
AppendThis=line
LineList.append(AppendThis)
continue
elif SkipThisLine is True:
if "'''" in line:
SkipThisLine=False
if line == "'''":
continue
SplittedLine=line.split("'''")
RightLine=SplittedLine[len(SplittedLine)-1]
if RightLine != "'''" and RightLine != "":
LineList.append(RightLine)
continue
elif '"""' in line:
SkipThisLine=False
if line == '"""':
continue
SplittedLine=line.split('"""')
RightLine=SplittedLine[len(SplittedLine)-1]
if RightLine != '"""' and RightLine != "":
LineList.append(RightLine)
continue
return LineList
def WriteContract(LineList):
StrippedContract=""
for x in LineList:
if StrippedContract == "":
StrippedContract=x
continue
else:
StrippedContract=StrippedContract+"\n"+x
continue
print(StrippedContract)
return StrippedContract
if ('.sol' or '.rs') == ContractLanguage:
WriteContract(StripSolContract(StripMeDaddy))
elif '.vy' == ContractLanguage:
WriteContract(StripVyContract(StripMeDaddy))