From 900eeb177a5cfc96fc5e1405eb9b2e576c3e246c Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Fri, 2 Sep 2016 01:27:30 -0400 Subject: [PATCH] Add address_is_mine() API method --- lbrynet/core/LBRYWallet.py | 20 ++++++++++++++++++++ lbrynet/lbrynet_daemon/LBRYDaemon.py | 18 ++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/lbrynet/core/LBRYWallet.py b/lbrynet/core/LBRYWallet.py index 864048d44..3bcac43f6 100644 --- a/lbrynet/core/LBRYWallet.py +++ b/lbrynet/core/LBRYWallet.py @@ -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) diff --git a/lbrynet/lbrynet_daemon/LBRYDaemon.py b/lbrynet/lbrynet_daemon/LBRYDaemon.py index 48c20ac7b..9d2acd65a 100644 --- a/lbrynet/lbrynet_daemon/LBRYDaemon.py +++ b/lbrynet/lbrynet_daemon/LBRYDaemon.py @@ -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