From 246711b1f6965a53665cdd4401b53f490df95341 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Mon, 10 May 2021 20:36:07 -0700 Subject: [PATCH] add network bit, rename file --- tipbot/commands/__init__.py | 9 +++++++-- tipbot/commands/{mining.py => network.py} | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) rename tipbot/commands/{mining.py => network.py} (74%) diff --git a/tipbot/commands/__init__.py b/tipbot/commands/__init__.py index 22dfab7..8a930e7 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, mempool +from tipbot.commands.network import mine, mempool, network all_commands = { @@ -52,5 +52,10 @@ all_commands = { 'func': mempool, 'example': '/mempool', 'help': 'Determine how many transactions currently sit in the mempool' - } + }, + 'network': { + 'func': network, + 'example': '/network', + 'help': 'Show details about the Wownero network' + }, } diff --git a/tipbot/commands/mining.py b/tipbot/commands/network.py similarity index 74% rename from tipbot/commands/mining.py rename to tipbot/commands/network.py index 2cab51e..19ee605 100644 --- a/tipbot/commands/mining.py +++ b/tipbot/commands/network.py @@ -51,3 +51,21 @@ def mempool(update, context): update.message.reply_text('The current number of transactions in mempool is: {0}'.format(txs)) except: update.message.reply_text('Something borked -_-') + +@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 -_-')