forked from c00w/bitHopper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.py
69 lines (60 loc) · 2.8 KB
/
data.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
#!/usr/bin/python
#License#
#bitHopper by Colin Rice is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
#Based on a work at github.com.
import time
from twisted.internet.task import LoopingCall
class Data():
def __init__(self,bitHopper):
self.users = {}
self.bitHopper = bitHopper
self.pool = self.bitHopper.pool
self.db = self.bitHopper.db
self.speed = self.bitHopper.speed
self.difficulty = self.bitHopper.difficulty
self.db.update_user_shares_db()
shares = self.db.get_user_shares()
prune = LoopingCall(self.prune)
prune.start(10)
for user in shares:
self.users[user] = {'shares':shares[user],'rejects':0, 'last':0, 'shares_time': [], 'hash_rate': 0}
def prune(self):
for user in self.users:
for share_time in self.users[user]['shares_time']:
if time.time() - share_time > 60 * 5:
self.users[user]['shares_time'].remove(share_time)
self.users[user]['hash_rate'] = (len(self.users[user]['shares_time']) * 2**32) / (60 * 5 * 1000000)
def get_users(self):
users = {}
for item in self.users:
if self.users[item]['shares'] >0:
users[item] = self.users[item]
return users
def user_share_add(self,user,password,shares,server):
if user not in self.users:
self.users[user] = {'shares':0,'rejects':0, 'last':0, 'shares_time': [], 'hash_rate': 0}
self.users[user]['last'] = time.time()
self.users[user]['shares'] += shares
self.users[user]['shares_time'].append(time.time())
self.users[user]['hash_rate'] = (len(self.users[user]['shares_time']) * 2**32) / (60 * 5 * 1000000)
def reject_callback(self,server,data):
try:
if data != []:
self.db.update_rejects(server,1)
self.pool.get_servers()[server]['rejects'] += 1
#self.bitHopper.log_msg('[' + data[72:136] + '] => ' + self.bitHopper.pool.servers[server]['name'] + " REJECTED!")
except Exception, e:
self.bitHopper.log_dbg('reject_callback_error')
self.bitHopper.log_dbg(str(e))
return
def data_callback(self,server,data, user, password):
try:
if data != []:
self.speed.add_shares(1)
self.db.update_shares(server, 1, user, password)
self.pool.get_servers()[server]['user_shares'] +=1
self.pool.get_servers()[server]['expected_payout'] += 1.0/self.difficulty.get_difficulty() * 50.0
self.user_share_add(user, password, 1, server)
except Exception, e:
self.bitHopper.log_dbg('data_callback_error')
self.bitHopper.log_dbg(str(e))