diff --git a/monero/backends/jsonrpc.py b/monero/backends/jsonrpc.py index 5b13428..ac026da 100644 --- a/monero/backends/jsonrpc.py +++ b/monero/backends/jsonrpc.py @@ -60,6 +60,15 @@ class JSONRPCDaemon(object): confirmations=0)) return txs + def headers(self, start_height, end_height=None): + end_height = end_height or start_height + res = self.raw_jsonrpc_request('get_block_headers_range', { + 'start_height': start_height, + 'end_height': end_height}) + if res['status'] == 'OK': + return res['headers'] + raise Exception() + def raw_request(self, path, data): hdr = {'Content-Type': 'application/json'} _log.debug(u"Request: {path}\nData: {data}".format( @@ -76,7 +85,6 @@ class JSONRPCDaemon(object): _log.debug(u"Result:\n{result}".format(result=_ppresult)) return result - def raw_jsonrpc_request(self, method, params=None): hdr = {'Content-Type': 'application/json'} data = {'jsonrpc': '2.0', 'id': 0, 'method': method, 'params': params or {}} diff --git a/monero/daemon.py b/monero/daemon.py index 0cb2486..52ede66 100644 --- a/monero/daemon.py +++ b/monero/daemon.py @@ -41,3 +41,13 @@ class Daemon(object): :rtype: list of :class:`Transaction ` """ return self._backend.mempool() + + + def headers(self, start_height, end_height=None): + """ + Returns block headers for given height range. + If no :param end_height: is given, it's assumed to be equal to :param start_height: + + :rtype: list of dict + """ + return self._backend.headers(start_height, end_height) diff --git a/utils/daemonping.py b/utils/daemoninfo.py similarity index 71% rename from utils/daemonping.py rename to utils/daemoninfo.py index 1540e2c..8c12321 100755 --- a/utils/daemonping.py +++ b/utils/daemoninfo.py @@ -31,8 +31,15 @@ def get_daemon(): d = get_daemon() info = d.info() -print("Net: {net:>18s}\n" +print("Net: {net:>15s}net\n" "Height: {height:10d}\n" - "Difficulty: {difficulty:10d}".format( - net='test' if info['testnet'] else 'live', + "Difficulty: {difficulty:10d}\n" + "Alt blocks: {alt_blocks_count:10d}\n".format( + net='test' if info['testnet'] \ + else 'stage' if info['stagenet'] \ + else 'main' if info['mainnet'] else 'unknown', **info)) +for hdr in reversed(d.headers(info['height']-7, info['height']-1)): + print("{height:10d} {hash} {block_size_kb:6.2f} kB {num_txes:3d} txn(s) " + "v{major_version:d}".format( + block_size_kb=hdr['block_size']/1024.0, **hdr))