forked from bleach86/GhostVault_Utility
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.py
191 lines (146 loc) · 7.23 KB
/
database.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import sqlite3, json
class Database:
def __init__(self):
self.conn = sqlite3.connect("ghostzap.db")
self.cursor = self.conn.cursor()
self.cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
tables = self.cursor.fetchall()
self.tableList = []
for i in tables:
self.tableList.append(i[0])
if 'settings' not in self.tableList:
self.initSettings()
if 'jobs' not in self.tableList:
self.initJobs()
def initSettings(self):
with self.conn:
self.cursor.execute("""CREATE TABLE settings (
cliPath text,
extKey text,
stealthAddr text,
walletName
)""")
with self.conn:
self.cursor.execute(
"""INSERT INTO settings VALUES (:cliPath, :extKey, :stealthAddr, :walletName)""",
{'cliPath': '', 'extKey': None, 'walletName': None, 'stealthAddr': None})
def initJobs(self):
with self.conn:
self.cursor.execute("""CREATE TABLE jobs (
type integer,
maxZap real,
currentZapAmount real,
gvrMode integer,
lastZap integer,
nextZap integer,
isActive integer,
zapPub real,
zapAnon real,
txid text,
txidAnon text,
jobID text
)""")
def getCliPath(self):
self.cursor.execute("""SELECT * FROM settings""")
cliPath = self.cursor.fetchone()[0]
return cliPath
def setCliPath(self, path):
with self.conn:
self.cursor.execute("""UPDATE settings SET cliPath=:cliPath""", {"cliPath": path})
def getExtKey(self):
self.cursor.execute("""SELECT * FROM settings""")
extKey = self.cursor.fetchone()[1]
return extKey
def setExtKey(self, key):
with self.conn:
self.cursor.execute("""UPDATE settings SET extKey=:extKey""", {"extKey": key})
def getStealthAddr(self):
self.cursor.execute("""SELECT * FROM settings""")
stealthAddr = self.cursor.fetchone()[2]
return stealthAddr
def setStealthAddr(self, stealthAddr):
with self.conn:
self.cursor.execute("""UPDATE settings SET stealthAddr=:stealthAddr""", {"stealthAddr": stealthAddr})
def getWalletName(self):
self.cursor.execute("""SELECT * FROM settings""")
cliPath = self.cursor.fetchone()[3]
return cliPath
def setWalletName(self, name):
with self.conn:
self.cursor.execute("""UPDATE settings SET walletName=:walletName""", {"walletName": name})
def isJob(self, type):
self.cursor.execute("""SELECT * FROM jobs WHERE type=:type""", {'type': type})
existing = self.cursor.fetchall()
if len(existing) < 1:
return False
else:
return True
def newJob(self, type, maxZap, currentZapAmount, gvrMode, lastZap, nextZap, isActive, zapPub, zapAnon, jobID):
if not self.isJob(type):
with self.conn:
self.cursor.execute("""INSERT INTO jobs VALUES (:type, :maxZap, :currentZapAmount, :gvrMode, :lastZap, :nextZap, :isActive, :zapPub, :zapAnon, :txid, :txidAnon, :jobID)""",
{'type': type, 'maxZap': maxZap, 'currentZapAmount': currentZapAmount, 'gvrMode': gvrMode,
'lastZap': lastZap, 'nextZap': nextZap, 'isActive': isActive, 'zapPub': zapPub, 'zapAnon': zapAnon, 'txid': None, 'txidAnon': None, 'jobID': jobID})
def removeJob(self, type):
with self.conn:
self.cursor.execute(f"""DELETE from jobs WHERE type=:type""", {"type": type})
def getJobs(self):
self.cursor.execute("""SELECT * FROM jobs""")
existing = self.cursor.fetchall()
return existing
def getMaxZap(self, type):
self.cursor.execute("""SELECT * FROM jobs WHERE type=:type""", {'type': type})
maxZap = self.cursor.fetchone()[1]
return maxZap
def setMaxZap(self, type, maxZap):
with self.conn:
self.cursor.execute("""UPDATE jobs SET maxZap=:maxZap WHERE type=:type""", {"maxZap": maxZap, "type": type})
def getCurrentZapAmount(self, type):
self.cursor.execute("""SELECT * FROM jobs WHERE type=:type""", {'type': type})
currentZap = self.cursor.fetchone()[2]
return currentZap
def setCurrentZapAmount(self, type, currentZapAmount):
with self.conn:
self.cursor.execute("""UPDATE jobs SET currentZapAmount=:currentZapAmount WHERE type=:type""", {"currentZapAmount": currentZapAmount, "type": type})
def getGvrMode(self, type):
self.cursor.execute("""SELECT * FROM jobs WHERE type=:type""", {'type': type})
gvrMode = self.cursor.fetchone()[3]
return gvrMode
def setGvrMode(self, type, gvrMode):
with self.conn:
self.cursor.execute("""UPDATE jobs SET gvrMode=:gvrMode WHERE type=:type""", {"gvrMode": gvrMode, "type": type})
def getLastZap(self, type):
self.cursor.execute("""SELECT * FROM jobs WHERE type=:type""", {'type': type})
lastZap = self.cursor.fetchone()[4]
return lastZap
def setLastZap(self, type, lastZap):
with self.conn:
self.cursor.execute("""UPDATE jobs SET lastZap=:lastZap WHERE type=:type""", {"lastZap": lastZap, "type": type})
def getNextZap(self, type):
self.cursor.execute("""SELECT * FROM jobs WHERE type=:type""", {'type': type})
nextZap = self.cursor.fetchone()[5]
return nextZap
def setNextZap(self, type, nextZap):
with self.conn:
self.cursor.execute("""UPDATE jobs SET nextZap=:nextZap WHERE type=:type""", {"nextZap": nextZap, "type": type})
def getIsActive(self, type):
self.cursor.execute("""SELECT * FROM jobs WHERE type=:type""", {'type': type})
isActive = self.cursor.fetchone()[6]
return isActive
def setIsActive(self, type, isActive):
with self.conn:
self.cursor.execute("""UPDATE jobs SET isActive=:isActive WHERE type=:type""", {"isActive": isActive, "type": type})
def getTxid(self, type):
self.cursor.execute("""SELECT * FROM jobs WHERE type=:type""", {'type': type})
txid = self.cursor.fetchone()[9]
return txid
def setTxid(self, type, txid):
with self.conn:
self.cursor.execute("""UPDATE jobs SET txid=:txid WHERE type=:type""", {"txid": txid, "type": type})
def getTxidAnon(self, type):
self.cursor.execute("""SELECT * FROM jobs WHERE type=:type""", {'type': type})
txid = self.cursor.fetchone()[10]
return txid
def setTxidAnon(self, type, txid):
with self.conn:
self.cursor.execute("""UPDATE jobs SET txidAnon=:txidAnon WHERE type=:type""", {"txidAnon": txid, "type": type})