add hashrate checker

This commit is contained in:
lza_menace 2021-05-10 10:05:49 -07:00
parent a78ebeaa2b
commit b8b21092b9
2 changed files with 49 additions and 0 deletions

View File

@ -5,6 +5,7 @@ from tipbot.commands.tip import tip
from tipbot.commands.withdraw import withdraw
from tipbot.commands.balance import balance
from tipbot.commands.deposit import deposit
from tipbot.commands.mining import mine
all_commands = {
@ -41,5 +42,10 @@ all_commands = {
'debug': {
'func': debug,
'admin': True
},
'mine': {
'func': mine,
'example': '/mine <hashes_per_second>',
'help': 'Determine how much WOW a miner with given hashrate will earn'
}
}

43
tipbot/commands/mining.py Normal file
View File

@ -0,0 +1,43 @@
import logging
import requests
from tipbot.db import User
from tipbot.helpers.decorators import wallet_rpc_required, log_event, check_debug
from tipbot import wownero
from tipbot import config
@wallet_rpc_required
@log_event
@check_debug
def mine(update, context):
# First delete message to remove clutter
update.message.delete()
# Check that enough arguments were provided
if len(context.args) < 1:
update.message.reply_text('Not enough arguments passed. Include hash rate per second to estimate.')
return False
# Check that hash rate arg is an actual number
try:
hr = float(context.args[0])
except:
update.message.reply_text('Invalid hashrate provided')
return False
# Run the numbers, tell the user
try:
payload = {'jsonrpc':'2.0', 'id':'0', 'method':'getlastblockheader'}
headers = {'Content-Type':'application/json'}
r = requests.post(config.DAEMON_URI + '/json_rpc', json=payload, headers=headers, timeout=5)
r.raise_for_status()
j = r.json()
diff = float(j['result']['block_header']['difficulty'])
lbr = float(j['result']['block_header']['reward'])
ttb = diff / hr
update.message.reply_text('The estimated time to find a block with {0:.2f} kh/s at diff {1:.2e} is {2:.2f} days. On average you will earn {3:.2f} WOW per day'.format(
hr/1e3, diff, ttb/(60*60*24), (lbr/1e11)/(ttb/(60*60*24))
))
except:
update.message.reply_text('Something b0rked -_-')
return False