Path: blob/master/Unofficial miners/Multithreaded_PC_Miner.py
920 views
#!/usr/bin/env python31# ---------- Duino-Coin Multithreaded PC Miner (v1.7) ----------- #2# https://github.com/revoxhere/duino-coin3# Distributed under MIT license4# © Duino-Coin Community 20205# --------------------------------------------------------------- #67refresh_time = 3.5 # refresh time in seconds for the output (recommended: 3.5)8autorestart_time = 360 # autorestart time in seconds. 0 = disabled910discord_key = "" # coming soon1112# --------------------------------------------------------------- #1314import hashlib15import multiprocessing16import os17import random18import socket19import statistics20import sys21import threading22import time23import urllib.request2425if sys.platform == "win32":26try:27from colorama import Back, Fore, Style, init28init()29except:30print("You don't have colorama installed. Try to install it now?")31choice = input("(y/n): ")32if choice == "y":33os.system("pip install colorama")34os._exit(1)35else:36os._exit(1)37colorama_choice = True38else:39colorama_choice = False4041class bcolors:42blue = '\033[36m'43yellow = '\033[93m'44endc = '\033[0m'45back_cyan = '\033[46m'46red = '\033[31m'47back_yellow = '\033[43m'48black = '\033[30m'49back_red = '\033[41m'5051last_hash_count = 052khash_count = 053hash_count = 054hash_mean = []5556def hashrateCalculator():57global last_hash_count, hash_count, khash_count, hash_mean5859last_hash_count = hash_count60khash_count = last_hash_count / 100061if khash_count == 0:62khash_count = random.uniform(0, 1)6364hash_mean.append(khash_count)65khash_count = statistics.mean(hash_mean)66khash_count = round(khash_count, 2)6768hash_count = 06970threading.Timer(1.0, hashrateCalculator).start()717273def start_thread(arr, i, username, accepted_shares, bad_shares, thread_number):74global hash_count, khash_count75soc = socket.socket()7677serverip = "https://raw.githubusercontent.com/revoxhere/duino-coin/gh-pages/serverip.txt"78with urllib.request.urlopen(serverip) as content:79content = content.read().decode().splitlines()80pool_address = content[0]81pool_port = content[1]8283soc.connect((str(pool_address), int(pool_port)))84soc.recv(3).decode()8586hashrateCalculator()87while True:88try:89soc.send(bytes("JOB,"+str(username), encoding="utf8"))90job = soc.recv(1024).decode()91job = job.split(",")92try:93difficulty = job[2]94except:95for p in multiprocessing.active_children():96p.terminate()97time.sleep(1)98sys.argv.append(str(thread_number))99os.execl(sys.executable, sys.executable, *sys.argv)100101for result in range(100 * int(difficulty) + 1):102hash_count = hash_count + 1103ducos1 = hashlib.sha1(str(job[0] + str(result)).encode("utf-8")).hexdigest()104if job[1] == ducos1:105soc.send(bytes(str(result) + "," + str(last_hash_count) + ",Multithreaded Miner v1.7", encoding="utf8"))106feedback = soc.recv(1024).decode()107arr[i] = khash_count108if feedback == "GOOD" or feedback == "BLOCK":109accepted_shares[i] += 1110break111elif feedback == "BAD":112bad_shares[i] += 1113break114elif feedback == "INVU":115print("Entered username is incorrect!")116except (KeyboardInterrupt, SystemExit):117print("Thread #{}: exiting...".format(i))118os._exit(0)119120121def autorestarter():122time.sleep(autorestart_time)123124for p in multiprocessing.active_children():125p.terminate()126time.sleep(1)127sys.argv.append(str(thread_number))128os.execl(sys.executable, sys.executable, *sys.argv)129130131def getBalance():132global pool_address, pool_port133soc = socket.socket()134soc.connect((str(pool_address), int(pool_port)))135soc.recv(3).decode()136137soc.send(bytes("LOGI," + username + "," + password, encoding="utf8"))138response = soc.recv(2).decode()139if response != "OK":140print("Error logging in - check account credentials!")141soc.close()142os._exit(1)143144soc.send(bytes("BALA", encoding="utf8"))145balance = soc.recv(1024).decode()146soc.close()147148return float(balance)149150151def calculateProfit(start_bal):152global curr_bal, profit_array153154prev_bal = curr_bal155156curr_bal = getBalance()157session = curr_bal - start_bal158minute = curr_bal - prev_bal159hourly = minute * 60160161profit_array = [session, minute, hourly]162threading.Timer(60, calculateProfit, [start_bal]).start()163164165def showOutput():166clear()167168if colorama_choice:169print(Back.CYAN + Fore.YELLOW + "Duino-Coin Multithreaded PC Miner" + Style.RESET_ALL + "\n")170else:171print(bcolors.back_cyan + bcolors.yellow + "Duino-Coin Multithreaded PC Miner" + bcolors.endc + "\n")172173174if colorama_choice:175print(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")176else:177print(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")178179d = {}180for thread in range(thread_number):181d[f"#{thread + 1}"] = [f"{hashrate_array[thread]} kH/s", accepted_shares[thread], bad_shares[thread]]182183if colorama_choice:184print(Fore.YELLOW + Back.CYAN + "{:<9} {:<13} {:<10} {:<10}".format('Thread','Hashrate','Accepted','Rejected') + Style.RESET_ALL)185else:186print(bcolors.yellow + bcolors.back_cyan + "{:<9} {:<13} {:<10} {:<10}".format('Thread','Hashrate','Accepted','Rejected') + bcolors.endc)187for k, v in d.items():188hashrate, good, bad = v189if colorama_choice:190print(Fore.CYAN + "{:<9} {:<13} {:<10} {:<10}".format(k, hashrate, good, bad) + Style.RESET_ALL)191else:192print(bcolors.blue + "{:<9} {:<13} {:<10} {:<10}".format(k, hashrate, good, bad) + bcolors.endc)193194if colorama_choice:195print(Back.RED + "{:<9} {:<13} {:<10} {:<10}".format("TOTAL", totalHashrate(sum(hashrate_array)), sum(accepted_shares), sum(bad_shares)) + Style.RESET_ALL)196else:197print(bcolors.back_red + "{:<9} {:<13} {:<10} {:<10}".format("TOTAL", totalHashrate(sum(hashrate_array)), sum(accepted_shares), sum(bad_shares)) + bcolors.endc)198199threading.Timer(float(refresh_time), showOutput).start()200201202def clear():203os.system('cls' if os.name=='nt' else 'clear')204205206def totalHashrate(khash):207if khash / 1000 >= 1:208return str(round(khash / 1000, 2)) + " MH/s"209else:210return str(round(khash, 2)) + " kH/s"211212213if __name__ == '__main__':214global thread_number, curr_bal215216if os.name == 'nt':217os.system("title " + "Duino-Coin multithreaded miner")218else:219print('\33]0;' + "Duino-Coin multithreaded miner"+'\a', end='')220clear()221222if colorama_choice:223print(Fore.RED + "The profit is refreshed every 60 seconds" + Style.RESET_ALL)224else:225print(bcolors.red + "The profit is refreshed every 60 seconds" + bcolors.endc)226227if (autorestart_time) > 0:228threading.Thread(target=autorestarter).start()229230with urllib.request.urlopen("https://raw.githubusercontent.com/revoxhere/duino-coin/gh-pages/serverip.txt") as content:231content = content.read().decode().splitlines() # doing this here because can't access pool_address and pool_port in the threads232pool_address = content[0]233pool_port = content[1]234235arguments = len(sys.argv)236if arguments <= 3:237if colorama_choice:238print(Fore.RED + "Provide username, password and thread count!" + Style.RESET_ALL)239print(Fore.YELLOW + "Example: python3 Multithreaded_PC_Miner.py username password 4" + Style.RESET_ALL)240print(Fore.RED + "Exiting in 15s." + Style.RESET_ALL)241else:242print(bcolors.red + "Provide username, password and thread count!" + bcolors.endc)243print(bcolors.yellow + "Example: python3 Multithreaded_PC_Miner.py username password 4" + bcolors.endc)244print(bcolors.red + "Exiting in 15s." + bcolors.endc)245time.sleep(15)246os._exit(0)247248username = str(sys.argv[1])249password = str(sys.argv[2])250thread_number = int(sys.argv[3])251if thread_number > 8:252print("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")253print(f"Miner for user {username} started with {thread_number} threads")254255hashrate_array = multiprocessing.Array("d", thread_number)256accepted_shares = multiprocessing.Array("i", thread_number)257bad_shares = multiprocessing.Array("i", thread_number)258259start_balance = getBalance()260curr_bal = start_balance261calculateProfit(start_balance)262showOutput()263264for i in range(thread_number):265p = multiprocessing.Process(target=start_thread, args=(hashrate_array, i, username, accepted_shares, bad_shares, thread_number))266p.start()267time.sleep(0.5)268time.sleep(1)269270271272