You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.7 KiB
Python
72 lines
2.7 KiB
Python
4 years ago
|
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
|
||
|
|
||
|
|
||
|
@log_event
|
||
|
@check_debug
|
||
|
def mine(update, context):
|
||
|
# 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
|
||
4 years ago
|
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(
|
||
4 years ago
|
hr/1e3, diff, ttb/(60*60*24), (lbr/1e11)/(ttb/(60*60*24))
|
||
|
))
|
||
|
except:
|
||
|
update.message.reply_text('Something b0rked -_-')
|
||
|
return False
|
||
4 years ago
|
|
||
|
@log_event
|
||
|
@check_debug
|
||
|
def mempool(update, context):
|
||
|
try:
|
||
|
payload = {'jsonrpc':'2.0', 'id':'0', 'method':'get_info'}
|
||
|
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()
|
||
|
txs = j['result']['tx_pool_size']
|
||
|
update.message.reply_text('The current number of transactions in mempool is: {0}'.format(txs))
|
||
|
except:
|
||
|
update.message.reply_text('Something borked -_-')
|
||
4 years ago
|
|
||
|
@log_event
|
||
|
@check_debug
|
||
|
def network(update, context):
|
||
|
try:
|
||
|
payload = {'jsonrpc':'2.0', 'id':'0', 'method':'get_info'}
|
||
|
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()
|
||
|
height = j['result']['height']
|
||
|
diff = j['result']['difficulty']
|
||
|
hashrate = float(diff)/120
|
||
|
update.message.reply_text('The current block height is {0:,}. Difficulty is {1:,}. Hashrate is {2:.2f} Mh/s.'.format(
|
||
|
height, diff, hashrate/1e6
|
||
|
))
|
||
|
except:
|
||
|
update.message.reply_text('Something borked -_-')
|