Merge pull request #619 from wallermadev/master

Adding functionality to check the balance of a given wallet.
This commit is contained in:
Jack Robison 2017-04-23 20:27:36 -04:00 committed by GitHub
commit dc7193bb8f
3 changed files with 31 additions and 10 deletions

View file

@ -10,18 +10,16 @@ at anytime.
## [Unreleased]
### Added
* Add `lbryschema_version` to response from `version`
*
*
* Added call to `get_address_balance` when `address` conditional returns true
* Added `address` conditional to `jsonrpc_wallet_balance`
* Added `get_address_balance` method to the `Wallet` class
### Changed
*
*
*
* Added optional `address` and `include_unconfirmed` params to `jsonrpc_wallet_balance` method
### Fixed
* fix stream_cost_estimate throwing exception on non decodeable claims
*
*
## [0.10.0rc2] - 2017-04-17
### Changed

View file

@ -797,6 +797,9 @@ class Wallet(object):
def get_new_address(self):
return defer.fail(NotImplementedError())
def get_address_balance(self, address):
return defer.fail(NotImplementedError())
def get_block(self, blockhash):
return defer.fail(NotImplementedError())
@ -1024,6 +1027,16 @@ class LBRYumWallet(Wallet):
yield self._save_wallet()
defer.returnValue(addr)
# Get the balance of a given address.
def get_address_balance(self, address, include_balance=False):
c, u, x = self.wallet.get_addr_balance(address)
if include_balance is False:
return Decimal(float(c) / COIN)
else:
return Decimal((float(c) + float(u) + float(x)) / COIN)
# Return an address with no balance in it, if
# there is none, create a brand new address
@defer.inlineCallbacks

View file

@ -1311,20 +1311,30 @@ class Daemon(AuthJSONRPCServer):
if 'DEPRECATED' not in getattr(self, "jsonrpc_" + command).__doc__]
))
def jsonrpc_get_balance(self):
def jsonrpc_get_balance(self, address=None, include_unconfirmed=False):
"""
DEPRECATED. Use `wallet_balance` instead.
"""
return self.jsonrpc_wallet_balance()
return self.jsonrpc_wallet_balance(address, include_unconfirmed)
def jsonrpc_wallet_balance(self):
def jsonrpc_wallet_balance(self, address=None, include_unconfirmed=False):
"""
Return the balance of the wallet
Args:
'address' (optional): If address is provided only that balance will be given
'include_unconfirmed' (optional): If set unconfirmed balance will be included in
the only takes effect when address is also provided.
Returns:
(float) amount of lbry credits in wallet
"""
return self._render_response(float(self.session.wallet.get_balance()))
if address is None:
return self._render_response(float(self.session.wallet.get_balance()))
else:
return self._render_response(float(
self.session.wallet.get_address_balance(address, include_unconfirmed)))
def jsonrpc_stop(self):
"""