Skip to content

Commit

Permalink
Add mining income estimator
Browse files Browse the repository at this point in the history
  • Loading branch information
sonofmom committed Aug 7, 2021
1 parent 22e66de commit acb2856
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
37 changes: 36 additions & 1 deletion mytoncore.py
Original file line number Diff line number Diff line change
Expand Up @@ -2514,11 +2514,46 @@ def GetHashrate(self):
cpus = psutil.cpu_count()
numThreads = "-w{cpus}".format(cpus=cpus)
params = self.GetPowParams('kf-kkdY_B7p-77TLn2hUhM6QidWrrsl8FYWCIvBMpZKprBtN')
args = ["-vv", numThreads, "-t3", 'kf-kkdY_B7p-77TLn2hUhM6QidWrrsl8FYWCIvBMpZKprBtN', params["seed"], params["complexity"], params["iterations"], 'kf-kkdY_B7p-77TLn2hUhM6QidWrrsl8FYWCIvBMpZKprBtN', filePath]
args = ["-vv", numThreads, "-t10", 'kf-kkdY_B7p-77TLn2hUhM6QidWrrsl8FYWCIvBMpZKprBtN', params["seed"], params["complexity"], params["iterations"], 'kf-kkdY_B7p-77TLn2hUhM6QidWrrsl8FYWCIvBMpZKprBtN', filePath]
result = self.miner.Run(args)
return result
#end define

def EstimateMiningIncome(self):
local.AddLog("fetching 24h mining statistics", "debug")
try:
response = requests.get("https://ton.swisscops.com/statistics/statistics_1day.json")
except requests.exceptions.RequestException as e:
raise Exeption("error while fetching statistics: {}".format(e))

if response.ok:
statistics = response.json()

hashrate = re.match(r'.+speed: (.+) hps.+', self.GetHashrate(), re.MULTILINE | re.DOTALL)
if hashrate:
hashrate = round(float(hashrate[1]))

income = statistics["coins_per_hash"] * hashrate
earning = statistics["coins_per_hash"] * hashrate
if earning > 100:
chance = 100
else:
chance = round(earning)

result ="Mining income estimtations\n"
result+="-----------------------------------------------------------------\n"
result+="Total network 24h earnings:\t\t\t" + str(statistics["bleed_total"]) + " TON\n"
result+="Average network 24h hashrate:\t\t" + str(round(statistics["hashrate_average"])) + " HPS\n"
result+="Your machine hashrate:\t\t\t\t" + str(round(hashrate)) + " HPS\n"
result+="Est. 24h chance to mine a block:\t" + str(chance) + "%\n"
result+="Est. monthly income:\t\t\t\t" + str(round(earning,2) * 30) + " TON\n\n"
result+="Attention: Please note that above numbers are estimates!\n"
result+="Actual mining income depends on many factors such as \n"
result+="network hashrate increase, chosen giver as well as good portion of luck!"

return result
#end define

def Tlb2Json(self, text):
# Заменить скобки
start = 0
Expand Down
6 changes: 6 additions & 0 deletions mytonctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def Init(argv):
# console.AddItem("pt", PrintTest, "PrintTest")

console.AddItem("hr", GetHashrate, local.Translate("hr_cmd"))
console.AddItem("emi", EstimateMiningIncome, local.Translate("emi_cmd"))
console.AddItem("mon", EnableMining, local.Translate("mo_cmd"))
console.AddItem("moff", DisableMining, local.Translate("moff_cmd"))

Expand Down Expand Up @@ -879,6 +880,11 @@ def GetHashrate(args):
ColorPrint(result)
#end define

def EstimateMiningIncome(args):
ColorPrint("The data may be incorrect if mining is enabled during the test. Turn off mining before checking hashrate.")
ColorPrint(ton.EstimateMiningIncome())
#end define

def EnableMining(args):
powAddr = ton.GetSettings('powAddr')
minerAddr = ton.GetSettings('minerAddr')
Expand Down
4 changes: 4 additions & 0 deletions translate.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@
"en": "Get mining hashrate",
"ru": "Получить хешрейт сервера"
},
"emi_cmd": {
"en": "Estimate mining income",
"ru": "Оценить добычу от майнинга"
},
"mo_cmd": {
"en": "Enable mining",
"ru": "Включить майнинг"
Expand Down

0 comments on commit acb2856

Please sign in to comment.