-
Notifications
You must be signed in to change notification settings - Fork 1
/
optiexplorer.py
215 lines (171 loc) · 6.25 KB
/
optiexplorer.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# optiexplorer.py v 0.32 to be used with Python3.5 or better
# Copyright Hclivess, Maccaspacca, vv181 2017
# Copyright Maccaspacca 2018
# for license see LICENSE file
# ..
from tornado.wsgi import WSGIContainer
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
import sqlite3, time, essentials
from flask import Flask, render_template
app = Flask(__name__)
key, public_key_readable, private_key_readable, _, _, public_key_hashed, address = essentials.keys_load ("privkey.der", "pubkey.der")
# load config
try:
lines = [line.rstrip('\n') for line in open('pool.txt')]
for line in lines:
try:
if "m_timeout=" in line:
m_timeout = int(line.split('=')[1])
except Exception as e:
m_timeout = 5
except Exception as e:
m_timeout = 5
# load config
#@app.route('/static/<filename>')
# def server_static(filename):
# return static_file(filename, root='static/')
@app.route('/')
# def hello():
def main():
conn = sqlite3.connect('static/ledger.db')
conn.text_factory = str
c = conn.cursor()
shares = sqlite3.connect('shares.db')
shares.text_factory = str
s = shares.cursor()
oldies = sqlite3.connect('archive.db')
oldies.text_factory = str
o = oldies.cursor()
addresses = []
for row in s.execute("SELECT * FROM shares"):
shares_address = row[0]
shares_value = row[1]
shares_timestamp = row[2]
if shares_address not in addresses:
addresses.append(shares_address)
total_hash = 0
worker_count = 0
output_shares = []
output_timestamps = []
data_addres = []
data_shares = []
data_mrate = []
data_mname = []
data_wcount = []
for x in addresses:
s.execute(
"SELECT sum(shares) FROM shares WHERE address = ? AND paid != 1", (x,))
shares_sum = s.fetchone()[0]
if shares_sum == None:
shares_sum = 0
continue
output_shares.append(shares_sum)
s.execute(
"SELECT timestamp FROM shares WHERE address = ? ORDER BY timestamp ASC LIMIT 1", (x,))
shares_timestamp = s.fetchone()[0]
output_timestamps.append(float(shares_timestamp))
s.execute(
"SELECT * FROM shares WHERE address = ? ORDER BY timestamp DESC LIMIT 1", (x,))
shares_last = s.fetchone()
#mrate = shares_last[4]
mname = shares_last[7] # last worker
s.execute("SELECT DISTINCT name FROM shares WHERE address = ?", (x,))
shares_names = s.fetchall()
nrate = []
ncount = []
for n in shares_names:
s.execute(
"SELECT * FROM shares WHERE address = ? AND name = ? ORDER BY timestamp DESC LIMIT 1", (x, n[0]))
names_last = s.fetchone()
t1 = time.time()
t2 = float(names_last[2])
t3 = (t1 - t2) / 60
if t3 < m_timeout:
nrate.append(int(names_last[4]))
ncount.append(int(names_last[6]))
else:
nrate.append(0)
ncount.append(0)
mrate = sum(nrate) # hashrate of address
wcount = sum(ncount) # worker count
total_hash = total_hash + mrate
worker_count = worker_count + wcount
if t3 < 30:
data_addres.append(x)
data_shares.append(shares_sum)
data_mrate.append(str(mrate))
data_mname.append(mname)
data_wcount.append(str(wcount))
try:
shares_total = sum(output_shares)
except:
shares_total = 0
try:
block_threshold = min(output_timestamps)
except:
block_threshold = time.time()
reward_list = []
data_block = []
data_reward = []
data_tShares = []
data_rewardps = []
data_tReward = []
data_tHash = []
data_twcount = []
for row in c.execute("SELECT * FROM transactions WHERE address = ? AND CAST(timestamp AS INTEGER) >= ? AND reward != 0", (address,) + (block_threshold,)):
data_block.append(row[0])
data_reward.append(row[9])
reward_list.append(float(row[9]))
if data_block == [] and data_reward == []:
data_block.append(0)
data_reward.append(0)
reward_total = sum(reward_list)
try:
reward_per_share = reward_total / shares_total
except:
reward_per_share = 0
data_tShares.append(shares_total)
data_rewardps.append(reward_per_share)
data_tReward.append(reward_total)
data_tHash.append(format('%.2f' % (total_hash / 1000)))
data_twcount.append(worker_count)
# payout view
data_pendingaddress = []
data_pendingreward = []
if reward_total > 0:
for x, y in zip(addresses, output_shares):
try:
claim = y * reward_per_share
except:
claim = 0
data_pendingaddress.append(x)
data_pendingreward.append(format('%.8f' % (claim)))
data_paddress = []
data_bismuthreward = []
data_blockheight = []
data_ptime = []
for row in c.execute("SELECT * FROM transactions WHERE address = ? and openfield = ? ORDER BY timestamp DESC LIMIT 80", (address,) + ("pool",)):
data_paddress.append(row[3])
data_bismuthreward.append(row[4])
data_blockheight.append(row[0])
data_ptime.append(format(time.strftime(
"%Y/%m/%d,%H:%M:%S", time.gmtime(float(row[1])))))
conn.close()
shares.close()
oldies.close()
return render_template("index.html",
recentminers=zip(
data_addres, data_shares, data_mrate, data_mname, data_wcount),
bpstats=zip(data_block, data_reward, data_tShares,
data_rewardps, data_tReward, data_tHash, data_twcount),
payouts=zip(data_addres, data_bismuthreward,
data_blockheight, data_ptime),
payoutsfees=zip(data_pendingaddress,
data_pendingreward)
)
if __name__ == "__main__":
#app.run(host='0.0.0.0', port=9080, debug=True)
http_server = HTTPServer(WSGIContainer(app))
http_server.listen(9080)
IOLoop.instance().start()