From 86535cb3aa1ef0f41679e22cbb4ae7709b7dd7a0 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Mon, 10 May 2021 23:43:07 -0700 Subject: [PATCH] add lastblock cmd --- tipbot/commands/__init__.py | 7 ++++++- tipbot/commands/network.py | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/tipbot/commands/__init__.py b/tipbot/commands/__init__.py index d6d3056..dbe989f 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.network import mine, mempool, network, price +from tipbot.commands.network import mine, mempool, network, price, lastblock all_commands = { @@ -63,4 +63,9 @@ all_commands = { 'example': '/price', 'help': 'Show Wownero price and market data from CoinGecko' }, + 'lastblock': { + 'func': lastblock, + 'example': '/lastblock', + 'help': 'Show details about the last processed block on the network' + } } diff --git a/tipbot/commands/network.py b/tipbot/commands/network.py index e956c47..5850a44 100644 --- a/tipbot/commands/network.py +++ b/tipbot/commands/network.py @@ -1,5 +1,6 @@ import logging import requests +from time import time from tipbot.db import User from tipbot.helpers.decorators import wallet_rpc_required, log_event, check_debug from tipbot import wownero @@ -96,3 +97,19 @@ def price(update, context): update.message.reply_text(f'{tgt}-{bse} is {sats:.8f} {tgt} on {mname} with {volbtc:.2f} {tgt} volume. Currently market cap rank #{mcap}.') except: update.message.reply_text('Something borked -_-') + +@log_event +@check_debug +def lastblock(update, context): + try: + payload = {'jsonrpc':'2.0', 'id':'0', 'method':'get_last_block_header'} + headers = {'accept': 'application/json'} + r = requests.post(config.DAEMON_URI + '/json_rpc', json=payload, headers=headers, timeout=5) + r.raise_for_status() + j = r.json() + block = j['result']['block_header'] + update.message.reply_text('Last block found {0:.2f} minutes ago with height {1} included {2} transactions'.format(( + time() - float(block['timestamp']))/60, block['height'], block['num_txes'] + )) + except: + update.message.reply_text('Something borked -_-')