Merge pull request #149 from lbryio/address-is-mine

Add address_is_mine() API method
This commit is contained in:
Jack Robison 2016-09-06 13:09:08 -04:00 committed by GitHub
commit 54229282a4
2 changed files with 38 additions and 0 deletions

View file

@ -498,6 +498,10 @@ class LBRYWallet(object):
d = self._get_history()
return d
def address_is_mine(self, address):
d = self._address_is_mine(address)
return d
def get_tx_json(self, txid):
def _decode(raw_tx):
tx = Transaction(raw_tx).deserialize()
@ -723,6 +727,9 @@ class LBRYWallet(object):
def _get_history(self):
return defer.fail(NotImplementedError())
def _address_is_mine(self, address):
return defer.fail(NotImplementedError())
def _start(self):
pass
@ -861,6 +868,9 @@ class LBRYcrdWallet(LBRYWallet):
def _get_history(self):
return threads.deferToThread(self._list_transactions_rpc)
def _address_is_mine(self, address):
return threads.deferToThread(self._get_address_is_mine_rpc, address)
def _get_rpc_conn(self):
return AuthServiceProxy(self.rpc_conn_string)
@ -1050,6 +1060,11 @@ class LBRYcrdWallet(LBRYWallet):
rpc_conn = self._get_rpc_conn()
return rpc_conn.listtransactions()
@_catch_connection_error
def _get_address_is_mine_rpc(self, address):
rpc_conn = self._get_rpc_conn()
return address in rpc_conn.getaddressesbyaccount("")
@_catch_connection_error
def _stop_rpc(self):
# check if our lbrycrdd is actually running, or if we connected to one that was already
@ -1344,6 +1359,11 @@ class LBRYumWallet(LBRYWallet):
func = getattr(self.cmd_runner, cmd.name)
return threads.deferToThread(func)
def _address_is_mine(self, address):
cmd = known_commands['ismine']
func = getattr(self.cmd_runner, cmd.name)
return threads.deferToThread(func, address)
def get_pub_keys(self, wallet):
cmd = known_commands['getpubkeys']
func = getattr(self.cmd_runner, cmd.name)

View file

@ -2131,6 +2131,24 @@ class LBRYDaemon(jsonrpc.JSONRPC):
d.addCallback(lambda r: self._render_response(r, OK_CODE))
return d
def jsonrpc_address_is_mine(self, p):
"""
Checks if an address is associated with the current wallet.
Args:
address: string
Returns:
is_mine: bool
"""
address = p['address']
d = self.session.wallet.address_is_mine(address)
d.addCallback(lambda is_mine: self._render_response(is_mine, OK_CODE))
return d
def jsonrpc_get_public_key_from_wallet(self, p):
"""
Get public key from wallet address