forked from c00w/bitHopper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpool_class.py
More file actions
138 lines (122 loc) · 5.31 KB
/
pool_class.py
File metadata and controls
138 lines (122 loc) · 5.31 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
131
132
133
134
135
136
137
138
#!/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
class Pool():
def __init__(self, name, attribute_dict, bitHopper):
self.bitHopper = bitHopper
self.dict = {'index_name':name}
self._parse(attribute_dict)
def _parse(self, attribute_dict):
self['shares'] = int(self.bitHopper.difficulty.get_difficulty())
self['ghash'] = -1
self['duration'] = -2
self['duration_temporal'] = 0
self['isDurationEstimated'] = False
self['last_pulled'] = time.time()
self['lag'] = False
self['api_lag'] = False
refresh_limit = self.bitHopper.config.getint('main', 'pool_refreshlimit')
self['refresh_time'] = int(attribute_dict.get('refresh_time', refresh_limit))
self['refresh_limit'] = int(attribute_dict.get('refresh_limit', refresh_limit))
self['rejects'] = self.bitHopper.db.get_rejects(self['index_name'])
self['user_shares'] = self.bitHopper.db.get_shares(self['index_name'])
self['payout'] = self.bitHopper.db.get_payout(self['index_name'])
self['expected_payout'] = self.bitHopper.db.get_expected_payout(self['index_name'])
self['api_address'] = attribute_dict.get('api_address', self['index_name'])
self['role'] = attribute_dict.get('role', 'disable')
if self['role'] in ['mine_slush']:
self['role'] = 'mine_c'
self['c'] = 300
self['lp_address'] = attribute_dict.get('lp_address', None)
self['err_api_count'] = 0
self['pool_index'] = self['index_name']
self['default_role'] = self['role']
if self['default_role'] in ['info','disable']:
self['default_role'] = 'mine'
#Coin Handling
if 'coin' not in attribute_dict:
if self['role'] in ['mine', 'info', 'backup', 'backup_latehop', 'mine_charity', 'mine_c']:
coin_type = 'btc'
elif self['role'] in ['mine_nmc']:
coin_type = 'nmc'
elif self['role'] in ['mine_ixc']:
coin_type = 'ixc'
elif self['role'] in ['mine_i0c']:
coin_type = 'i0c'
elif self['role'] in ['mine_scc']:
coin_type = 'scc'
else:
coin_type = 'btc'
self['coin'] = coin_type
else:
self['coin'] = attribute_dict['coin']
#Everything not explicitly handled should be set
for attr in attribute_dict:
if attr not in self.dict:
self.dict[attr] = attribute_dict[attr]
def __lt__(self, other):
if self['role'] in ['backup', 'backup_latehop']:
rr_self = float(self['rejects']/(self['user_shares']+1))
rr_self += self.get('penalty', 0.0)
rr_other = float(other['rejects']/(other['user_shares']+1))
rr_other += other.get('penalty', 0.0)
return rr_self <= rr_other
elif other.role in ['disable']:
return True
elif self['role'] in ['disable']:
return False
else:
return self['shares'] < other.shares
def btc_shares(self,):
difficulty = self.bitHopper.difficulty.get_difficulty()
nmc_difficulty = self.bitHopper.difficulty.get_nmc_difficulty()
ixc_difficulty = self.bitHopper.difficulty.get_ixc_difficulty()
i0c_difficulty = self.bitHopper.difficulty.get_i0c_difficulty()
scc_difficulty = self.bitHopper.difficulty.get_scc_difficulty()
if self['coin'] in ['btc']:
shares = self['shares']
elif self['coin'] in ['nmc']:
shares = self['shares']*difficulty / nmc_difficulty
elif self['coin'] in ['ixc']:
shares = self['shares']*difficulty / ixc_difficulty
elif self['coin'] in ['i0c']:
shares = self['shares']*difficulty / i0c_difficulty
elif self['coin'] in ['scc']:
shares = self['shares']*difficulty / scc_difficulty
else:
shares = difficulty
if self['role'] == 'mine_c':
#Checks if shares are to high and if so sends it through the roof
#So we don't mine it.
c = int(self['c'])
hashrate = float(self['ghash'])
hopoff = difficulty * (0.435 - 503131/(1173666 + c*hashrate))
if shares > hopoff:
shares = 2*difficulty
if self['role'] in ['mine_force', 'mine_lp_force']:
shares = 0
# apply penalty
shares = shares * float(self.get('penalty', 1))
return shares, self
def is_valid(self):
if self['lag']:
return False
if self['role'] not in ['backup', 'backup_latehop'] and self['api_lag']:
return False
if self.bitHopper.exchange.profitability.get(self['coin'],0) < 1.0:
return False
return True
def __getitem__(self, key):
return self.dict[key]
def get(self, key, default=None):
if default != None:
return self.dict.get(key, default)
else:
return self.dict.get(key)
def __setitem__(self, key, value):
self.dict[key] = value
def __contains__(self, item):
return item in self.dict