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