diff --git a/CHANGELOG.md b/CHANGELOG.md index 77b93e713..5fca2eb1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lbrynet/core/Wallet.py b/lbrynet/core/Wallet.py index eda716816..2a3808900 100644 --- a/lbrynet/core/Wallet.py +++ b/lbrynet/core/Wallet.py @@ -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 diff --git a/lbrynet/lbrynet_daemon/Daemon.py b/lbrynet/lbrynet_daemon/Daemon.py index e3c7a2f74..6e8553a83 100644 --- a/lbrynet/lbrynet_daemon/Daemon.py +++ b/lbrynet/lbrynet_daemon/Daemon.py @@ -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): """