From a4febff15dcfa8103f958849797e2d523ccd1a42 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Mon, 10 May 2021 14:37:41 -0700 Subject: [PATCH] add mempool command --- tipbot/commands/__init__.py | 7 ++++++- tipbot/commands/mining.py | 17 +++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/tipbot/commands/__init__.py b/tipbot/commands/__init__.py index 1f77527..22dfab7 100644 --- a/tipbot/commands/__init__.py +++ b/tipbot/commands/__init__.py @@ -5,7 +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 +from tipbot.commands.mining import mine, mempool all_commands = { @@ -47,5 +47,10 @@ all_commands = { 'func': mine, 'example': '/mine ', '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' } } diff --git a/tipbot/commands/mining.py b/tipbot/commands/mining.py index b8d5d83..2cab51e 100644 --- a/tipbot/commands/mining.py +++ b/tipbot/commands/mining.py @@ -6,7 +6,6 @@ from tipbot import wownero from tipbot import config -@wallet_rpc_required @log_event @check_debug def mine(update, context): @@ -32,9 +31,23 @@ def mine(update, context): 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( + 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 + +@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 -_-')