forked from LBRYCommunity/lbry-sdk
Merge pull request #568 from lbryio/get_unused_address
get_unused_address / get_new_address
This commit is contained in:
commit
23f1cf9c82
4 changed files with 55 additions and 11 deletions
|
@ -9,12 +9,12 @@ at anytime.
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
### Added
|
### Added
|
||||||
*
|
* Create wallet_unused_address API command
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
*
|
* wallet_new_address API command always returns new address
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
|
||||||
|
|
|
@ -293,10 +293,10 @@ Returns:
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
## file_seed
|
## file_set_status
|
||||||
|
|
||||||
```text
|
```text
|
||||||
Start or stop seeding a file
|
Start or stop downloading a file
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
'status': (str) "start" or "stop"
|
'status': (str) "start" or "stop"
|
||||||
|
@ -636,3 +636,15 @@ Returns:
|
||||||
Could contain more than one public key if multisig.
|
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
|
||||||
|
```
|
||||||
|
|
||||||
|
|
|
@ -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