add 'height' parameter to get_block

This commit is contained in:
Jack 2016-09-09 00:48:54 -04:00
parent 54229282a4
commit 0f0afadc94
2 changed files with 22 additions and 2 deletions

View file

@ -494,6 +494,10 @@ class LBRYWallet(object):
d.addCallback(self._get_decoded_tx) d.addCallback(self._get_decoded_tx)
return d return d
def get_block_info(self, height):
d = self._get_blockhash(height)
return d
def get_history(self): def get_history(self):
d = self._get_history() d = self._get_history()
return d return d
@ -862,6 +866,9 @@ class LBRYcrdWallet(LBRYWallet):
def get_claims_from_tx(self, txid): def get_claims_from_tx(self, txid):
return threads.deferToThread(self._get_claims_from_tx_rpc, txid) return threads.deferToThread(self._get_claims_from_tx_rpc, txid)
def _get_blockhash(self, blockhash):
return threads.deferToThread(self._get_blockhash_rpc, blockhash)
def _get_value_for_name(self, name): def _get_value_for_name(self, name):
return threads.deferToThread(self._get_value_for_name_rpc, name) return threads.deferToThread(self._get_value_for_name_rpc, name)
@ -994,6 +1001,11 @@ class LBRYcrdWallet(LBRYWallet):
rpc_conn = self._get_rpc_conn() rpc_conn = self._get_rpc_conn()
return rpc_conn.getblock(blockhash) return rpc_conn.getblock(blockhash)
@_catch_connection_error
def _get_blockhash_rpc(self, height):
rpc_conn = self._get_rpc_conn()
return rpc_conn.getblockhash(height)
@_catch_connection_error @_catch_connection_error
def _get_claims_from_tx_rpc(self, txid): def _get_claims_from_tx_rpc(self, txid):
rpc_conn = self._get_rpc_conn() rpc_conn = self._get_rpc_conn()
@ -1247,6 +1259,11 @@ class LBRYumWallet(LBRYWallet):
d.addCallback(lambda header: self.network.blockchain.hash_header(header)) d.addCallback(lambda header: self.network.blockchain.hash_header(header))
return d return d
def _get_blockhash(self, height):
d = threads.deferToThread(self.network.blockchain.read_header, height)
d.addCallback(lambda header: self.network.blockchain.hash_header(header))
return d
def get_name_claims(self): def get_name_claims(self):
cmd = known_commands['getnameclaims'] cmd = known_commands['getnameclaims']
func = getattr(self.cmd_runner, cmd.name) func = getattr(self.cmd_runner, cmd.name)

View file

@ -2255,10 +2255,13 @@ class LBRYDaemon(jsonrpc.JSONRPC):
if 'blockhash' in p.keys(): if 'blockhash' in p.keys():
blockhash = p['blockhash'] blockhash = p['blockhash']
d = self.session.wallet.get_block(blockhash)
elif 'height' in p.keys():
height = p['height']
d = self.session.wallet.get_block_info(height)
d.addCallback(lambda blockhash: self.session.wallet.get_block(blockhash))
else: else:
return server.failure return server.failure
d = self.session.wallet.get_block(blockhash)
d.addCallback(lambda r: self._render_response(r, OK_CODE)) d.addCallback(lambda r: self._render_response(r, OK_CODE))
return d return d