add lastblock cmd

master
lza_menace 3 years ago
parent 0db75f3e7e
commit 86535cb3aa

@ -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.network import mine, mempool, network, price from tipbot.commands.network import mine, mempool, network, price, lastblock
all_commands = { all_commands = {
@ -63,4 +63,9 @@ all_commands = {
'example': '/price', 'example': '/price',
'help': 'Show Wownero price and market data from CoinGecko' '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'
}
} }

@ -1,5 +1,6 @@
import logging import logging
import requests import requests
from time import time
from tipbot.db import User from tipbot.db import User
from tipbot.helpers.decorators import wallet_rpc_required, log_event, check_debug from tipbot.helpers.decorators import wallet_rpc_required, log_event, check_debug
from tipbot import wownero 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}.') update.message.reply_text(f'{tgt}-{bse} is {sats:.8f} {tgt} on {mname} with {volbtc:.2f} {tgt} volume. Currently market cap rank #{mcap}.')
except: except:
update.message.reply_text('Something borked -_-') 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 -_-')