-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebsite.py
More file actions
71 lines (62 loc) · 3.01 KB
/
website.py
File metadata and controls
71 lines (62 loc) · 3.01 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
import os
import peewee
import tornado.template as template
import tornado.web as web
import tornado.websocket as websock
def local_path(dir):
return os.path.join(os.path.dirname(__file__), dir)
class MainHandler(web.RequestHandler):
def initialize(self, ref_object):
self.rise = ref_object
def get(self):
from pydeepool import Delegate, Voter
loader = template.Loader(local_path('html'))
context = {}
context['delegate'] = self.rise.delegates.get_by_public_key(self.rise.config['key'])['delegate']
context['share'] = self.rise.config['votershare']
context['supporters'] = Voter.select().count()
delegate = Delegate.get(id=1)
context['blockpayout'] = self.rise.config['blockpayout']
context['avevote'] = delegate.current_average / context['supporters']
self.write(loader.load('index.html').generate(**context))
class AcntHandler(web.RequestHandler):
def initialize(self, ref_object):
self.rise = ref_object
def get(self, addr=None):
acnt = self.rise.accounts.get_account(addr)
delegate = self.rise.accounts.get_delegates(addr)
if acnt['success'] == False:
self.write('Account not found.')
return
if delegate['success'] == False or len(delegate['delegates']) <= 0:
self.write('You aren\'t voting for anyone.')
return
if delegate['delegates'][0]['publicKey'] != self.rise.config['key']:
self.write('You aren\'t voting for this delegate.')
return
db = peewee.SqliteDatabase('voters.db')
from pydeepool import Voter, Contrib, Delegate
from decimal import Decimal
context = {}
context['acnt'] = acnt['account']
context['delegate'] = delegate['delegates'][0]
context['stats'] = Delegate.get(id=1)
context['voter'] = Voter.get(address=addr)
context['share'] = self.rise.config['votershare']/100
context['voterperc'] = int(context['voter'].current_ave)/context['stats'].current_average
weight = context['voter'].current_ave / context['stats'].current_average
deliver = Decimal(context['stats'].current_forge * context['share'])
stats = context['stats']
#get latest reward
reward = self.rise.blocks.get_blocks(limit=1)['blocks'][0]['reward']
forged_blocks = (stats.current_forge / reward)
forged_perday = (self.rise.config['blockpayout'] / 101)
context['payout'] = deliver * weight
context['estpay'] = (Decimal(context['payout']) / Decimal(forged_blocks/forged_perday))
loader = template.Loader(local_path('html'))
self.write(loader.load('account.html').generate(**context))
def webapp(rise):
return web.Application([
(r"/", MainHandler, dict(ref_object=rise)),
(r"/addr/(\d+R)/", AcntHandler, dict(ref_object=rise)),
], static_path=local_path('assets'))