From b8b21092b90e0363638a64914a8edbec7247e2dc Mon Sep 17 00:00:00 2001 From: lza_menace Date: Mon, 10 May 2021 10:05:49 -0700 Subject: [PATCH] add hashrate checker --- tipbot/commands/__init__.py | 6 ++++++ tipbot/commands/mining.py | 43 +++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 tipbot/commands/mining.py diff --git a/tipbot/commands/__init__.py b/tipbot/commands/__init__.py index 4842fea..1f77527 100644 --- a/tipbot/commands/__init__.py +++ b/tipbot/commands/__init__.py @@ -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 ', + 'help': 'Determine how much WOW a miner with given hashrate will earn' } } diff --git a/tipbot/commands/mining.py b/tipbot/commands/mining.py new file mode 100644 index 0000000..3bc3326 --- /dev/null +++ b/tipbot/commands/mining.py @@ -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