-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdpos.py
98 lines (77 loc) · 2.74 KB
/
dpos.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
#!/usr/bin/python -Eu
# coding: utf-8
import web
import os
import sys
import json
import socket
import commands
import sqlite3
currentdir = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, currentdir + '/model')
from dpos_data import data_read, data_update
db_file = currentdir + '/dpos.db'
web_port = 36010
class index:
def GET(self):
res, msg = data_update(db_file, url='http://seed1.bumo.io:16002/')
#res, msg = data_update(db_file, url='http://127.0.0.1:36012/')
v_cands=data_read('validator_candidates', db_file)
k_cands=data_read('kol_candidates', db_file)
committee=data_read('committee', db_file)
votes=data_read('vote', db_file)
proposals=data_read('proposal', db_file)
v_rewards=data_read('validator_reward_distribution', db_file)
k_rewards=data_read('kol_reward_distribution', db_file)
cfg=data_read('configuration', db_file)
return render.index(v_cands=v_cands,
k_cands=k_cands,
committee=committee,
votes=votes,
proposals=proposals,
v_rewards=v_rewards,
k_rewards=k_rewards,
cfg=cfg)
class update:
def GET(self):
res, msg = data_update(db_file)
if not res:
return 'Failed to update dpos data to db, %s' % msg
else:
return msg
urls = (
'/', 'index',
'/update', 'update',
)
render = web.template.render(os.path.dirname(
__file__) + '/statics/', cache=False)
class WebSite(web.application):
def run(self, port=8075, *middleware):
func = self.wsgifunc(*middleware)
return web.httpserver.runsimple(func, ('0.0.0.0', port))
# Init app.
app = WebSite(urls, globals())
if __name__ == '__main__':
rcode, msg = commands.getstatusoutput("ifconfig|grep 'inet '")
ip = msg.split()[1].split('/')[0].strip()
print 'Please use the browser to open: \n\033[32m\033[4m' + 'http://' + ip + ':' + str(web_port) + '\033[0m'
# Perform the first fork.
try:
pid = os.fork()
if pid > 0:
sys.exit(0) # first parent out
except OSError as e:
sys.stderr.write("fork #1 failed: (%d) %s\n" % (e.errno, e.strerror))
sys.exit(1)
# Perform the second fork
try:
pid = os.fork()
if pid > 0:
sys.exit(0) # second parent out
except OSError as e:
sys.stderr.write("fork #2 failed: (%d) %s]n" % (e.errno, e.strerror))
sys.exit(1)
file = open(currentdir + '/dpos.log', 'w+')
os.dup2(file.fileno(), sys.stderr.fileno())
os.dup2(file.fileno(), sys.stdout.fileno())
app.run(web_port)