From b0fd6e57df1288a37815e905d2fe669affb89958 Mon Sep 17 00:00:00 2001 From: Kay Kurokawa Date: Mon, 27 Mar 2017 12:41:53 -0400 Subject: [PATCH 1/3] create and properly distinguish get_unused_address and get_new_address --- lbrynet/core/Wallet.py | 23 ++++++++++++++++------- lbrynet/lbrynet_daemon/Daemon.py | 23 +++++++++++++++++++++++ 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/lbrynet/core/Wallet.py b/lbrynet/core/Wallet.py index f6bc28711..86834a9d7 100644 --- a/lbrynet/core/Wallet.py +++ b/lbrynet/core/Wallet.py @@ -418,12 +418,12 @@ class Wallet(object): def update_peer_address(self, peer, address): self.peer_addresses[peer] = address - def get_new_address_for_peer(self, peer): + def get_unused_address_for_peer(self, peer): def set_address_for_peer(address): self.current_address_given_to_peer[peer] = address return address - d = self.get_new_address() + d = self.get_unused_address() d.addCallback(set_address_for_peer) return d @@ -974,13 +974,22 @@ class LBRYumWallet(Wallet): lambda result: Decimal(result['confirmed']) + Decimal(result.get('unconfirmed', 0.0))) return d + # Always create and return a brand new address + @defer.inlineCallbacks def get_new_address(self): + addr = self.wallet.create_new_address(account=None) + yield self._save_wallet() + defer.returnValue(addr) + + # Return an address with no balance in it, if + # there is none, create a brand new address + @defer.inlineCallbacks + def get_unused_address(self): addr = self.wallet.get_unused_address(account=None) if addr is None: addr = self.wallet.create_new_address() - d = defer.succeed(addr) - d.addCallback(self._save_wallet) - return d + yield self._save_wallet() + defer.returnValue(addr) def get_block(self, blockhash): return self._run_cmd_as_defer_to_thread('getblock', blockhash) @@ -1113,7 +1122,7 @@ class LBRYumWallet(Wallet): def list_addresses(self): return self._run_cmd_as_defer_succeed('listaddresses') - def _save_wallet(self, val): + def _save_wallet(self, val=None): self.wallet.storage.write() return defer.succeed(val) @@ -1198,7 +1207,7 @@ class LBRYcrdAddressQueryHandler(object): return fields if self.query_identifiers[0] in queries: - d = self.wallet.get_new_address_for_peer(self.peer) + d = self.wallet.get_unused_address_for_peer(self.peer) d.addCallback(create_response) return d if self.address is None: diff --git a/lbrynet/lbrynet_daemon/Daemon.py b/lbrynet/lbrynet_daemon/Daemon.py index 3fa1739ac..db5b866ea 100644 --- a/lbrynet/lbrynet_daemon/Daemon.py +++ b/lbrynet/lbrynet_daemon/Daemon.py @@ -1985,6 +1985,29 @@ class Daemon(AuthJSONRPCServer): d.addCallback(lambda address: self._render_response(address)) return d + + @AuthJSONRPCServer.auth_required + def jsonrpc_wallet_unused_address(self): + """ + Return an address containing no balance, will create + a new address if there is none. + + Args: + None + Returns: + (str) Unused wallet address in base58 + """ + + def _disp(address): + log.info("Got unused wallet address: " + address) + return defer.succeed(address) + + d = self.session.wallet.get_unused_address() + d.addCallback(_disp) + d.addCallback(lambda address: self._render_response(address)) + return d + + @AuthJSONRPCServer.auth_required def jsonrpc_send_amount_to_address(self, amount, address): """ From b15fba9c348744d1bc07f926d16c62462fb89c8c Mon Sep 17 00:00:00 2001 From: Kay Kurokawa Date: Mon, 27 Mar 2017 12:45:16 -0400 Subject: [PATCH 2/3] add changelog --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d5408dce..3005663f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,12 +9,12 @@ at anytime. ## [Unreleased] ### Added - * + * Create wallet_unused_address API command * * ### Changed - * + * wallet_new_address API command always returns new address * * From 26f40b62f918e23e5bf34f409ed10ea0dca5a5a8 Mon Sep 17 00:00:00 2001 From: Kay Kurokawa Date: Mon, 27 Mar 2017 12:51:19 -0400 Subject: [PATCH 3/3] run gen_api_docs.py script --- docs/index.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/index.md b/docs/index.md index aecdd6c86..e4dd46502 100644 --- a/docs/index.md +++ b/docs/index.md @@ -293,10 +293,10 @@ Returns: ] ``` -## file_seed +## file_set_status ```text -Start or stop seeding a file +Start or stop downloading a file Args: 'status': (str) "start" or "stop" @@ -636,3 +636,15 @@ Returns: Could contain more than one public key if multisig. ``` +## wallet_unused_address + +```text +Return an address containing no balance, will create +a new address if there is none. + +Args: + None +Returns: + (str) Unused wallet address in base58 +``` +