-
Notifications
You must be signed in to change notification settings - Fork 4
/
miningpoolhub.py
executable file
·209 lines (162 loc) · 5.41 KB
/
miningpoolhub.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
import json
import logging
import signal
import socket
import sys
import urllib2
import httplib
import datetime
from log import Log
import os
import re
import pickle
from singleton import Singleton
from config import Config
import calibration
import yaml
import pools
import time
class Miningpoolhub:
__metaclass__ = Singleton
supported_miners = ['ewbf', 'ccminer', 'ccminer2', 'xmrig_nvidia', 'ethminer']
algos = {
"cryptonight": {
"endpoint": "europe.cryptonight-hub.miningpoolhub.com",
"port": 12024,
"wtm": [213, 101]
},
"equihash": {
"endpoint": "europe.equihash-hub.miningpoolhub.com",
"port": 12023,
"wtm": [167, 185, 166, 214]
},
"daggerhashimoto": {
"endpoint": "europe.ethash-hub.miningpoolhub.com",
"port": 12020,
"wtm": [151, 162, 154, 178]
},
"lyra2rev2": {
"endpoint": "hub.miningpoolhub.com",
"port": 12018,
"wtm": [148, 5]
},
"neoscrypt": {
"endpoint": "hub.miningpoolhub.com",
"port": 12012,
"wtm": [8]
},
"keccak": {
"endpoint": "hub.miningpoolhub.com",
"port": 12003,
"wtm": [73]
},
"skein": {
"endpoint": "hub.miningpoolhub.com",
"port": 12016,
"wtm": [114,67]
},
"groestl": {
"endpoint": "hub.miningpoolhub.com",
"port": 12004,
"wtm": [48]
}
}
algo_map = {
"ethash": "daggerhashimoto",
"Lyra2RE2": "lyra2rev2"
}
def __init__(self):
self.data_path = os.getenv("HOME") + "/.minotaur"
if not os.path.exists(self.data_path):
os.mkdir(self.data_path, 0755)
if Config().get('pools.miningpoolhub.enable_excavator'):
self.supported_miners.append('excavator')
self.paying_file = self.data_path + "/miningpoolhub.yml"
self.paying = {}
if os.path.exists(self.paying_file):
self.last_refresh = os.stat(self.paying_file).st_mtime
self.paying = yaml.load(open(self.paying_file).read())
else:
self.paying = {}
self.last_refresh = None
def shortened(self, region):
return 'mph'
def refresh_data(self, save=True):
if self.last_refresh != None and (time.time() - self.last_refresh) < 300:
return True
try:
opener = urllib2.build_opener()
opener.addheaders = [('User-Agent', 'Mozilla/5.0')]
paying = {}
for algo in self.algos.keys():
for wtm in self.algos[algo]['wtm']:
response = opener.open("http://whattomine.com/coins/%d.json" % (wtm))
network = json.loads(response.read())
base_block_time = float(1) / float(network['nethash'])
daily = (float(86400) / float(network['block_time']) * base_block_time * float(network['block_reward']))
rate = daily * float(network['exchange_rate']) * 1000
if Config().get('pools.miningpoolhub.pool_fee'):
rate -= (rate / 100) * Config().get('pools.miningpoolhub.pool_fee')
if not algo in paying.keys() or rate > paying[algo]:
paying[algo] = rate
self.paying = paying
self.save_paying_data()
self.last_refresh = time.time()
return True
except urllib2.HTTPError, e:
return False
except urllib2.URLError, e:
return False
except httplib.HTTPException, e:
return False
except Exception:
return False
def save_paying_data(self):
with open(self.paying_file + ".new", "w") as f:
f.write(yaml.dump(self.paying))
os.rename(self.paying_file + ".new", self.paying_file)
def mbtc_per_day(self, benchmarks, paying=False):
if paying == 'cached':
paying = yaml.load(open(self.paying_file).read())
if not paying:
paying = self.paying
payrates = {
None: {}
}
for algo in paying.keys():
if algo in benchmarks.keys():
payrates[None][algo] = paying[algo] * benchmarks[algo]
return payrates
def get_best_miner_and_algorithm(self, device):
hashrates = calibration.Calibration().get_hashrates(device)
if hashrates == None:
return [None, None, None, None]
best_hashrates = calibration.Calibration().get_best_algorithm_benchmarks(hashrates)
payrates = self.mbtc_per_day(best_hashrates)
payrates[None] = pools.Pools().deduct_power_from_payrates(device, payrates[None])
best_rate = 0
best_algo = None
best_miner = None
for algo in payrates[None]:
if payrates[None][algo] > best_rate:
best_rate = payrates[None][algo]
best_algo = algo
best_miner = device.get_best_miner_for_algorithm(best_algo, self.supported_miners)
if best_miner == None:
best_rate = 0
best_algo = None
best_region = None
if payrates[None] == {}:
device.log('warning', 'no miningpoolhub payrate information - defaulting to %s' % (Config().get('pools.miningpoolhub.default_algorithm')))
best_algo = Config().get('pools.miningpoolhub.default_algorithm')
best_region = Config().get('pools.miningpoolhub.primary_region')
return [best_miner, best_algo, None, best_rate]
def get_payrate(self, device, hashrates, miner_name, algo, region):
benchmarks = {
algo: hashrates[miner_name][algo]['hashrate']
}
payrates = self.mbtc_per_day(benchmarks)
payrates[None] = pools.Pools().deduct_power_from_payrates(device, payrates[None])
return payrates[None][algo]
def get_endpoints(self, algo, region):
return ["%s:%d" % (self.algos[algo]['endpoint'], self.algos[algo]['port'])]