-
Notifications
You must be signed in to change notification settings - Fork 0
/
x3.py
212 lines (178 loc) · 8.34 KB
/
x3.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
210
211
212
# -*- coding: utf-8 -*-
import sys
import time
import json
import requests
#Import Blinka
import digitalio
import board
# Import Python Imaging Library
from PIL import Image, ImageDraw, ImageFont
import adafruit_rgb_display.st7789 as st7789
def get_ethermine_values(wallet):
api_url = "https://api.ethermine.org/miner/{}/dashboard".format(wallet)
r = requests.get(api_url)
data = json.loads(r.text)
ret_value = {}
ret_value["unpaid"] = data["data"]["currentStatistics"]["unpaid"]/1000000000000000000
ret_value["workers"] = data["data"]["currentStatistics"]["activeWorkers"]
ret_value["reported_hashrate"] = data["data"]["currentStatistics"]["reportedHashrate"]/1000000
ret_value["actual_hashrate"] = data["data"]["currentStatistics"]["currentHashrate"]/1000000
ret_value["invalid_shares"] = data["data"]["currentStatistics"]["invalidShares"]
ret_value["stale_shares"] = data["data"]["currentStatistics"]["staleShares"]
return ret_value
def get_flexpool_values(wallet):
base_api_url = "https://flexpool.io/api/v1/miner/" + '0x' + wallet
ret_value = {}
# Get unpaid
r = requests.get(base_api_url+"/balance")
data = json.loads(r.text)
ret_value["unpaid"] = data["result"]/1000000000000000000
# Get unpaid
r = requests.get(base_api_url+"/workerCount")
data = json.loads(r.text)
ret_value["workers"] = data["result"]["online"]
# Get other stats
r = requests.get(base_api_url+"/stats")
data = json.loads(r.text)
ret_value["reported_hashrate"] = data["result"]["current"]["reported_hashrate"]/1000000
ret_value["actual_hashrate"] = data["result"]["current"]["effective_hashrate"]/1000000
ret_value["invalid_shares"] = data["result"]["daily"]["invalid_shares"]
ret_value["stale_shares"] = data["result"]["daily"]["stale_shares"]
return ret_value
def get_hiveon_values(wallet):
base_api_url = "https://hiveon.net/api/v1/stats/"
ret_value = {}
wallet = wallet.lower()
# Get unpaid
r = requests.get(base_api_url+"miner/"+wallet+"/ETH/billing-acc")
data = json.loads(r.text)
ret_value["unpaid"] = data["totalUnpaid"]
# Get workers
r = requests.get(base_api_url+"workers-count?minerAddress="+wallet+"&coin=ETH&window=10m&limit=1")
data = json.loads(r.text)
ret_value["workers"] = int(data["items"][0]["count"])
# Get hashrate stats
r = requests.get(base_api_url+"hashrates?minerAddress="+wallet+"&coin=ETH&limit=1")
data = json.loads(r.text)
ret_value["reported_hashrate"] = int(data["items"][0]["reportedHashrate"])/1000000
ret_value["actual_hashrate"] = int(data["items"][0]["hashrate"])/1000000
# Get shares stats
r = requests.get(base_api_url+"shares?minerAddress="+wallet+"&coin=ETH&window=10m&limit=144")
data = json.loads(r.text)
invalid_shares, stale_shares = 0, 0
for item in data["items"]:
stale_shares += int(item["staleCount"]) if "staleCount" in item else 0
invalid_shares += int(item["invalidCount"]) if "invalidCount" in item else 0
ret_value["invalid_shares"] = invalid_shares
ret_value["stale_shares"] = stale_shares
return ret_value
if len(sys.argv) != 3 or (sys.argv[1] != "ethermine" and sys.argv[1] != "flexpool" and sys.argv[1] != "hiveon"):
print("Usage: sudo python3 miner.py ethermine|flexpool|hiveon wallet")
exit
pool = sys.argv[1]
wallet = sys.argv[2]
if wallet.startswith("0x"):
wallet = wallet[2:]
value_api_url = "https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd"
# Configuration for CS and DC pins (these are FeatherWing defaults on M0/M4):
cs_pin = digitalio.DigitalInOut(board.CE0)
dc_pin = digitalio.DigitalInOut(board.D25)
reset_pin = None
# Config for display baudrate (default max is 24mhz):
BAUDRATE = 24000000
# Setup SPI bus using hardware SPI:
spi = board.SPI()
# Create the ST7789 display:
disp = st7789.ST7789(spi, cs=cs_pin, dc=dc_pin, rst=reset_pin, baudrate=BAUDRATE,
width=90, height=90, x_offset=50, y_offset=60, setRotation=1)
# Create blank image for drawing.
# Make sure to create image with mode 'RGB' for full color.
height = disp.width # we swap height/width to rotate it to landscape!
width = disp.height
image = Image.new('RGB', (width, height))
rotation = 90
setRotation = 2
# Get drawing object to draw on image.
draw = ImageDraw.Draw(image)
# Draw a black filled box to clear the image.
draw.rectangle((0, 0, width, height), outline=0, fill=(0, 0, 0))
disp.image(image)
# Draw some shapes.
# First define some constants to allow easy resizing of shapes.
padding = -2
top = padding
bottom = height-padding
# Move left to right keeping track of the current x position for drawing shapes.
x = 0
# Alternatively load a TTF font. Make sure the .ttf font file is in the
# same directory as the python script!
# Some other nice fonts to try: http://www.dafont.com/bitmap.php
font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 24)
big_font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 48)
small_font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 18)
font_height = font.getsize("a")[1]
big_font_height = big_font.getsize("a")[1]
red = "#FF0000"
green = "#00FF00"
blue = "#0000FF"
yellow = "#FFFF00"
# Turn on the backlight
backlight = digitalio.DigitalInOut(board.D22)
backlight.switch_to_output()
backlight.value = True
# Add buttons as inputs
buttonA = digitalio.DigitalInOut(board.D23)
buttonA.switch_to_input()
duration = 300
counter = duration
state = 0
while True:
# Draw a black filled box to clear the image.
draw.rectangle((0, 0, width, height), outline=0, fill=0)
if counter == duration:
try:
miner_data = get_ethermine_values(wallet) if pool == "ethermine" else get_flexpool_values(wallet) if pool == "flexpool" else get_hiveon_values(wallet)
r = requests.get(value_api_url)
data = json.loads(r.text)
eth_value = data["ethereum"]["usd"]
except:
y = top
draw.text((x,y),"ERROR LOADING DATA", font=font, fill=red)
print("error")
time.sleep(60)
continue
y = top
if not buttonA.value:
state = 1 if state == 0 else 0
if state == 0:
draw.text((x,y),"{:.5f}".format(miner_data["unpaid"]),font=big_font, fill=green if miner_data["workers"] >= 2 and miner_data["invalid_shares"] < 3 else red)
y += big_font_height
draw.text((x,y),"${:.2f}".format(miner_data["unpaid"]*eth_value), font=big_font, fill=green)
y += big_font_height
draw.text((x,y),"${:.2f}".format(eth_value), font=big_font, fill=green)
draw.text((width-40,0), str(counter), font=small_font, fill=yellow)
else:
draw.text((x,y),"Unpaid: ", font=font, fill=blue)
draw.text((x+font.getsize("Unpaid: ")[0],y), "{:.5f}".format(miner_data["unpaid"]), font=font, fill=green)
y += font_height
draw.text((x,y),"Value: ", font=font, fill=blue)
draw.text((x+font.getsize("Value: ")[0],y+5), "${:.2f} ${:.2f}".format(eth_value*miner_data["unpaid"], eth_value), font=small_font, fill=green)
y += font_height
draw.text((x,y),"Workers: Mh/s (R/A):", font=font, fill=blue)
y += font_height
draw.text((x,y), "{}: {:.1f} / ".format(miner_data["workers"], miner_data["reported_hashrate"]), font=font, fill=green)
draw.text((x+font.getsize("{} - {:.1f} / ".format(miner_data["workers"], miner_data["reported_hashrate"]))[0],y), "{:.1f}".format(miner_data["actual_hashrate"]), font=font, fill=green if miner_data["actual_hashrate"] >= miner_data["reported_hashrate"] else yellow)
y += font_height
draw.text((x,y),"Stale / Invalid: ", font=font, fill=blue)
draw.text((x+font.getsize("Stale / Invalid: ")[0],y), str(miner_data["stale_shares"]), font=font, fill=green)
draw.text((x+font.getsize("Stale / Invalid: {}".format(miner_data["stale_shares"]))[0],y), " / ", font=font, fill=blue)
draw.text((x+font.getsize("Stale / Invalid: {} / ".format(miner_data["stale_shares"]))[0],y),str(miner_data["invalid_shares"]), font=font, fill=green if miner_data["invalid_shares"] == 0 else red)
y += font_height
draw.text((x,y), str(counter), font=small_font, fill=yellow)
# Display image.
disp.image(image, rotation)
counter -= 1
if counter == 0:
counter = duration
time.sleep(15)