add mempool command

This commit is contained in:
lza_menace 2021-05-10 14:37:41 -07:00
parent 2d0dfc31fe
commit a4febff15d
2 changed files with 21 additions and 3 deletions

View file

@ -5,7 +5,7 @@ from tipbot.commands.tip import tip
from tipbot.commands.withdraw import withdraw from tipbot.commands.withdraw import withdraw
from tipbot.commands.balance import balance from tipbot.commands.balance import balance
from tipbot.commands.deposit import deposit from tipbot.commands.deposit import deposit
from tipbot.commands.mining import mine from tipbot.commands.mining import mine, mempool
all_commands = { all_commands = {
@ -47,5 +47,10 @@ all_commands = {
'func': mine, 'func': mine,
'example': '/mine <hashes_per_second>', 'example': '/mine <hashes_per_second>',
'help': 'Determine how much WOW a miner with given hashrate will earn' 'help': 'Determine how much WOW a miner with given hashrate will earn'
},
'mempool': {
'func': mempool,
'example': '/mempool',
'help': 'Determine how many transactions currently sit in the mempool'
} }
} }

View file

@ -6,7 +6,6 @@ from tipbot import wownero
from tipbot import config from tipbot import config
@wallet_rpc_required
@log_event @log_event
@check_debug @check_debug
def mine(update, context): def mine(update, context):
@ -32,9 +31,23 @@ def mine(update, context):
diff = float(j['result']['block_header']['difficulty']) diff = float(j['result']['block_header']['difficulty'])
lbr = float(j['result']['block_header']['reward']) lbr = float(j['result']['block_header']['reward'])
ttb = diff / hr 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( 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)) hr/1e3, diff, ttb/(60*60*24), (lbr/1e11)/(ttb/(60*60*24))
)) ))
except: except:
update.message.reply_text('Something b0rked -_-') update.message.reply_text('Something b0rked -_-')
return False return False
@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 -_-')