Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
revoxhere
GitHub Repository: revoxhere/duino-coin
Path: blob/master/Unofficial miners/Multithreaded_PC_Miner.py
920 views
1
#!/usr/bin/env python3
2
# ---------- Duino-Coin Multithreaded PC Miner (v1.7) ----------- #
3
# https://github.com/revoxhere/duino-coin
4
# Distributed under MIT license
5
# © Duino-Coin Community 2020
6
# --------------------------------------------------------------- #
7
8
refresh_time = 3.5 # refresh time in seconds for the output (recommended: 3.5)
9
autorestart_time = 360 # autorestart time in seconds. 0 = disabled
10
11
discord_key = "" # coming soon
12
13
# --------------------------------------------------------------- #
14
15
import hashlib
16
import multiprocessing
17
import os
18
import random
19
import socket
20
import statistics
21
import sys
22
import threading
23
import time
24
import urllib.request
25
26
if sys.platform == "win32":
27
try:
28
from colorama import Back, Fore, Style, init
29
init()
30
except:
31
print("You don't have colorama installed. Try to install it now?")
32
choice = input("(y/n): ")
33
if choice == "y":
34
os.system("pip install colorama")
35
os._exit(1)
36
else:
37
os._exit(1)
38
colorama_choice = True
39
else:
40
colorama_choice = False
41
42
class bcolors:
43
blue = '\033[36m'
44
yellow = '\033[93m'
45
endc = '\033[0m'
46
back_cyan = '\033[46m'
47
red = '\033[31m'
48
back_yellow = '\033[43m'
49
black = '\033[30m'
50
back_red = '\033[41m'
51
52
last_hash_count = 0
53
khash_count = 0
54
hash_count = 0
55
hash_mean = []
56
57
def hashrateCalculator():
58
global last_hash_count, hash_count, khash_count, hash_mean
59
60
last_hash_count = hash_count
61
khash_count = last_hash_count / 1000
62
if khash_count == 0:
63
khash_count = random.uniform(0, 1)
64
65
hash_mean.append(khash_count)
66
khash_count = statistics.mean(hash_mean)
67
khash_count = round(khash_count, 2)
68
69
hash_count = 0
70
71
threading.Timer(1.0, hashrateCalculator).start()
72
73
74
def start_thread(arr, i, username, accepted_shares, bad_shares, thread_number):
75
global hash_count, khash_count
76
soc = socket.socket()
77
78
serverip = "https://raw.githubusercontent.com/revoxhere/duino-coin/gh-pages/serverip.txt"
79
with urllib.request.urlopen(serverip) as content:
80
content = content.read().decode().splitlines()
81
pool_address = content[0]
82
pool_port = content[1]
83
84
soc.connect((str(pool_address), int(pool_port)))
85
soc.recv(3).decode()
86
87
hashrateCalculator()
88
while True:
89
try:
90
soc.send(bytes("JOB,"+str(username), encoding="utf8"))
91
job = soc.recv(1024).decode()
92
job = job.split(",")
93
try:
94
difficulty = job[2]
95
except:
96
for p in multiprocessing.active_children():
97
p.terminate()
98
time.sleep(1)
99
sys.argv.append(str(thread_number))
100
os.execl(sys.executable, sys.executable, *sys.argv)
101
102
for result in range(100 * int(difficulty) + 1):
103
hash_count = hash_count + 1
104
ducos1 = hashlib.sha1(str(job[0] + str(result)).encode("utf-8")).hexdigest()
105
if job[1] == ducos1:
106
soc.send(bytes(str(result) + "," + str(last_hash_count) + ",Multithreaded Miner v1.7", encoding="utf8"))
107
feedback = soc.recv(1024).decode()
108
arr[i] = khash_count
109
if feedback == "GOOD" or feedback == "BLOCK":
110
accepted_shares[i] += 1
111
break
112
elif feedback == "BAD":
113
bad_shares[i] += 1
114
break
115
elif feedback == "INVU":
116
print("Entered username is incorrect!")
117
except (KeyboardInterrupt, SystemExit):
118
print("Thread #{}: exiting...".format(i))
119
os._exit(0)
120
121
122
def autorestarter():
123
time.sleep(autorestart_time)
124
125
for p in multiprocessing.active_children():
126
p.terminate()
127
time.sleep(1)
128
sys.argv.append(str(thread_number))
129
os.execl(sys.executable, sys.executable, *sys.argv)
130
131
132
def getBalance():
133
global pool_address, pool_port
134
soc = socket.socket()
135
soc.connect((str(pool_address), int(pool_port)))
136
soc.recv(3).decode()
137
138
soc.send(bytes("LOGI," + username + "," + password, encoding="utf8"))
139
response = soc.recv(2).decode()
140
if response != "OK":
141
print("Error logging in - check account credentials!")
142
soc.close()
143
os._exit(1)
144
145
soc.send(bytes("BALA", encoding="utf8"))
146
balance = soc.recv(1024).decode()
147
soc.close()
148
149
return float(balance)
150
151
152
def calculateProfit(start_bal):
153
global curr_bal, profit_array
154
155
prev_bal = curr_bal
156
157
curr_bal = getBalance()
158
session = curr_bal - start_bal
159
minute = curr_bal - prev_bal
160
hourly = minute * 60
161
162
profit_array = [session, minute, hourly]
163
threading.Timer(60, calculateProfit, [start_bal]).start()
164
165
166
def showOutput():
167
clear()
168
169
if colorama_choice:
170
print(Back.CYAN + Fore.YELLOW + "Duino-Coin Multithreaded PC Miner" + Style.RESET_ALL + "\n")
171
else:
172
print(bcolors.back_cyan + bcolors.yellow + "Duino-Coin Multithreaded PC Miner" + bcolors.endc + "\n")
173
174
175
if colorama_choice:
176
print(Back.YELLOW + Fore.BLACK + "Profit: " + str(profit_array[1]) + "/min " + str(profit_array[2]) + "/h" + "\nTotal session: " + str(profit_array[0]) + Style.RESET_ALL + "\n")
177
else:
178
print(bcolors.back_yellow + bcolors.black + "Profit: " + str(profit_array[1]) + "/min " + str(profit_array[2]) + "/h" + "\nTotal session: " + str(profit_array[0]) + bcolors.endc + "\n")
179
180
d = {}
181
for thread in range(thread_number):
182
d[f"#{thread + 1}"] = [f"{hashrate_array[thread]} kH/s", accepted_shares[thread], bad_shares[thread]]
183
184
if colorama_choice:
185
print(Fore.YELLOW + Back.CYAN + "{:<9} {:<13} {:<10} {:<10}".format('Thread','Hashrate','Accepted','Rejected') + Style.RESET_ALL)
186
else:
187
print(bcolors.yellow + bcolors.back_cyan + "{:<9} {:<13} {:<10} {:<10}".format('Thread','Hashrate','Accepted','Rejected') + bcolors.endc)
188
for k, v in d.items():
189
hashrate, good, bad = v
190
if colorama_choice:
191
print(Fore.CYAN + "{:<9} {:<13} {:<10} {:<10}".format(k, hashrate, good, bad) + Style.RESET_ALL)
192
else:
193
print(bcolors.blue + "{:<9} {:<13} {:<10} {:<10}".format(k, hashrate, good, bad) + bcolors.endc)
194
195
if colorama_choice:
196
print(Back.RED + "{:<9} {:<13} {:<10} {:<10}".format("TOTAL", totalHashrate(sum(hashrate_array)), sum(accepted_shares), sum(bad_shares)) + Style.RESET_ALL)
197
else:
198
print(bcolors.back_red + "{:<9} {:<13} {:<10} {:<10}".format("TOTAL", totalHashrate(sum(hashrate_array)), sum(accepted_shares), sum(bad_shares)) + bcolors.endc)
199
200
threading.Timer(float(refresh_time), showOutput).start()
201
202
203
def clear():
204
os.system('cls' if os.name=='nt' else 'clear')
205
206
207
def totalHashrate(khash):
208
if khash / 1000 >= 1:
209
return str(round(khash / 1000, 2)) + " MH/s"
210
else:
211
return str(round(khash, 2)) + " kH/s"
212
213
214
if __name__ == '__main__':
215
global thread_number, curr_bal
216
217
if os.name == 'nt':
218
os.system("title " + "Duino-Coin multithreaded miner")
219
else:
220
print('\33]0;' + "Duino-Coin multithreaded miner"+'\a', end='')
221
clear()
222
223
if colorama_choice:
224
print(Fore.RED + "The profit is refreshed every 60 seconds" + Style.RESET_ALL)
225
else:
226
print(bcolors.red + "The profit is refreshed every 60 seconds" + bcolors.endc)
227
228
if (autorestart_time) > 0:
229
threading.Thread(target=autorestarter).start()
230
231
with urllib.request.urlopen("https://raw.githubusercontent.com/revoxhere/duino-coin/gh-pages/serverip.txt") as content:
232
content = content.read().decode().splitlines() # doing this here because can't access pool_address and pool_port in the threads
233
pool_address = content[0]
234
pool_port = content[1]
235
236
arguments = len(sys.argv)
237
if arguments <= 3:
238
if colorama_choice:
239
print(Fore.RED + "Provide username, password and thread count!" + Style.RESET_ALL)
240
print(Fore.YELLOW + "Example: python3 Multithreaded_PC_Miner.py username password 4" + Style.RESET_ALL)
241
print(Fore.RED + "Exiting in 15s." + Style.RESET_ALL)
242
else:
243
print(bcolors.red + "Provide username, password and thread count!" + bcolors.endc)
244
print(bcolors.yellow + "Example: python3 Multithreaded_PC_Miner.py username password 4" + bcolors.endc)
245
print(bcolors.red + "Exiting in 15s." + bcolors.endc)
246
time.sleep(15)
247
os._exit(0)
248
249
username = str(sys.argv[1])
250
password = str(sys.argv[2])
251
thread_number = int(sys.argv[3])
252
if thread_number > 8:
253
print("Notice: you're launching a miner with 8+ threads, values this high may not add anything to your efficiency but are spamming our small server.\nIf you don't want to contribute in making server go offline then please set this number a bit lower.\nThanks in advance")
254
print(f"Miner for user {username} started with {thread_number} threads")
255
256
hashrate_array = multiprocessing.Array("d", thread_number)
257
accepted_shares = multiprocessing.Array("i", thread_number)
258
bad_shares = multiprocessing.Array("i", thread_number)
259
260
start_balance = getBalance()
261
curr_bal = start_balance
262
calculateProfit(start_balance)
263
showOutput()
264
265
for i in range(thread_number):
266
p = multiprocessing.Process(target=start_thread, args=(hashrate_array, i, username, accepted_shares, bad_shares, thread_number))
267
p.start()
268
time.sleep(0.5)
269
time.sleep(1)
270
271
272