create and properly distinguish get_unused_address and get_new_address
This commit is contained in:
parent
b04455f9c7
commit
b0fd6e57df
2 changed files with 39 additions and 7 deletions
|
@ -418,12 +418,12 @@ class Wallet(object):
|
||||||
def update_peer_address(self, peer, address):
|
def update_peer_address(self, peer, address):
|
||||||
self.peer_addresses[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):
|
def set_address_for_peer(address):
|
||||||
self.current_address_given_to_peer[peer] = address
|
self.current_address_given_to_peer[peer] = address
|
||||||
return address
|
return address
|
||||||
|
|
||||||
d = self.get_new_address()
|
d = self.get_unused_address()
|
||||||
d.addCallback(set_address_for_peer)
|
d.addCallback(set_address_for_peer)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
@ -974,13 +974,22 @@ class LBRYumWallet(Wallet):
|
||||||
lambda result: Decimal(result['confirmed']) + Decimal(result.get('unconfirmed', 0.0)))
|
lambda result: Decimal(result['confirmed']) + Decimal(result.get('unconfirmed', 0.0)))
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
# Always create and return a brand new address
|
||||||
|
@defer.inlineCallbacks
|
||||||
def get_new_address(self):
|
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)
|
addr = self.wallet.get_unused_address(account=None)
|
||||||
if addr is None:
|
if addr is None:
|
||||||
addr = self.wallet.create_new_address()
|
addr = self.wallet.create_new_address()
|
||||||
d = defer.succeed(addr)
|
yield self._save_wallet()
|
||||||
d.addCallback(self._save_wallet)
|
defer.returnValue(addr)
|
||||||
return d
|
|
||||||
|
|
||||||
def get_block(self, blockhash):
|
def get_block(self, blockhash):
|
||||||
return self._run_cmd_as_defer_to_thread('getblock', blockhash)
|
return self._run_cmd_as_defer_to_thread('getblock', blockhash)
|
||||||
|
@ -1113,7 +1122,7 @@ class LBRYumWallet(Wallet):
|
||||||
def list_addresses(self):
|
def list_addresses(self):
|
||||||
return self._run_cmd_as_defer_succeed('listaddresses')
|
return self._run_cmd_as_defer_succeed('listaddresses')
|
||||||
|
|
||||||
def _save_wallet(self, val):
|
def _save_wallet(self, val=None):
|
||||||
self.wallet.storage.write()
|
self.wallet.storage.write()
|
||||||
return defer.succeed(val)
|
return defer.succeed(val)
|
||||||
|
|
||||||
|
@ -1198,7 +1207,7 @@ class LBRYcrdAddressQueryHandler(object):
|
||||||
return fields
|
return fields
|
||||||
|
|
||||||
if self.query_identifiers[0] in queries:
|
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)
|
d.addCallback(create_response)
|
||||||
return d
|
return d
|
||||||
if self.address is None:
|
if self.address is None:
|
||||||
|
|
|
@ -1985,6 +1985,29 @@ class Daemon(AuthJSONRPCServer):
|
||||||
d.addCallback(lambda address: self._render_response(address))
|
d.addCallback(lambda address: self._render_response(address))
|
||||||
return d
|
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
|
@AuthJSONRPCServer.auth_required
|
||||||
def jsonrpc_send_amount_to_address(self, amount, address):
|
def jsonrpc_send_amount_to_address(self, amount, address):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue