Add method for retrieving block headers from daemon

This commit is contained in:
Michał Sałaban 2019-10-16 13:36:50 +02:00
parent eb88f7cd6f
commit fb13992c77
3 changed files with 29 additions and 4 deletions

View file

@ -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 {}}

View file

@ -41,3 +41,13 @@ class Daemon(object):
:rtype: list of :class:`Transaction <monero.transaction.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)