-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdb.py
More file actions
130 lines (83 loc) · 3.23 KB
/
Copy pathdb.py
File metadata and controls
130 lines (83 loc) · 3.23 KB
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
import sqlite3
class Database:
def __init__(self):
self.db = sqlite3.connect('./server.db')
self.sql = self.db.cursor()
a = self.sql.execute(""" CREATE TABLE IF NOT EXISTS address (
address TEXT,
key TEXT,
id INT
)""")
b = self.sql.execute(""" CREATE TABLE IF NOT EXISTS trades (
contract TEXT,
amount TEXT,
method TEXT,
value TEXT,
id TEXT
)""")
b = self.sql.execute(""" CREATE TABLE IF NOT EXISTS past_trades (
contract TEXT,
id TEXT,
time TEXT,
amount TEXT,
status TEXT,
method TEXT
)""")
def store_address(self,address, key):
table = self.sql.execute("SELECT id FROM address WHERE id = 1")
if table.fetchone() is None:
q = "INSERT INTO address (address,key, id) VALUES (?,?,?);"
result = self.sql.execute(q,(address,key, 1))
self.db.commit()
else:
q = "UPDATE address SET address = ?, key = ? WHERE id = 1;"
result = self.sql.execute(q,(address,key))
self.db.commit()
if result :
return True
else:
return False
def get_address(self):
table = self.sql.execute("SELECT address FROM address WHERE id = 1")
temp = table.fetchone()
if temp is None:
return False
else:
return temp
def count_trades(self):
q = "SELECT COUNT(*) FROM trades;"
result = self.sql.execute(q)
result = result.fetchall()
return result
def store_trade(self,contract_addr,trade_amount,trade_method,trade_value,name):
q = "INSERT INTO trades (contract, amount, method, value, id) VALUES (?,?,?,?,?);"
result = self.sql.execute(q,(contract_addr,trade_amount, trade_method, trade_value,name))
self.db.commit()
return result
def get_user_data(self):
table = self.sql.execute("SELECT address, key FROM address WHERE id = 1")
temp = table.fetchone()
if temp is None:
return False
else:
return temp
def get_all_trades(self):
q = "SELECT * FROM trades"
result = self.sql.execute(q)
result = result.fetchall()
return result
def get_all_past_trades(self):
q = "SELECT * FROM past_trades"
result = self.sql.execute(q)
result = result.fetchall()
return result
def delete_trade(self,contract):
q = "DELETE FROM trades WHERE contract = ?;"
result = self.sql.execute(q,(contract,))
self.db.commit()
return True
def store_past_trades(self,contract_addr,id, time,trade_amount,tx_status,trade_method):
q = "INSERT INTO past_trades (contract,id,time, amount, status, method) VALUES (?,?,?,?,?,?);"
result = self.sql.execute(q,(contract_addr, id, time, trade_amount, tx_status, trade_method))
self.db.commit()
return result