From c38b463bf6a4411e4dbe22168e053045490bc53d Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Sun, 26 Aug 2018 00:44:23 -0400 Subject: [PATCH] added default_wallet and default_account properties to daemon --- lbrynet/daemon/Daemon.py | 48 +++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/lbrynet/daemon/Daemon.py b/lbrynet/daemon/Daemon.py index e076d98e6..b5eb6cf82 100644 --- a/lbrynet/daemon/Daemon.py +++ b/lbrynet/daemon/Daemon.py @@ -238,14 +238,14 @@ class Daemon(AuthJSONRPCServer): self.streams = {} @property - def wallet(self): + def default_wallet(self): try: return self.wallet_manager.default_wallet except AttributeError: return None @property - def account(self): + def default_account(self): try: return self.wallet_manager.default_account except AttributeError: @@ -1110,8 +1110,8 @@ class Daemon(AuthJSONRPCServer): """ broadcast = not no_broadcast return self.jsonrpc_account_fund( - self.wallet_manager.default_account.name, - self.wallet_manager.default_account.name, + self.default_account.name, + self.default_account.name, amount=amount, outputs=num_addresses, broadcast=broadcast @@ -1179,7 +1179,7 @@ class Daemon(AuthJSONRPCServer): """ if address is not None: raise NotImplementedError("Limiting by address needs to be re-implemented in new wallet.") - dewies = yield self.wallet_manager.default_account.get_balance( + dewies = yield self.default_account.get_balance( 0 if include_unconfirmed else 6 ) defer.returnValue(round(dewies / COIN, 3)) @@ -1210,7 +1210,7 @@ class Daemon(AuthJSONRPCServer): self.error_if_account_exists(account_name) account = LBCAccount.from_dict( self.wallet_manager.get_or_create_ledger('lbc_mainnet'), - self.wallet_manager, { + self.default_wallet, { 'name': account_name, 'seed': seed, 'private_key': private_key, @@ -1220,12 +1220,12 @@ class Daemon(AuthJSONRPCServer): } } ) - self.wallet_manager.save() + self.default_wallet.save() result = account.to_dict() result['status'] = 'added' result.pop('certificates', None) - result['is_default'] = self.wallet_manager.accounts[0] == account + result['is_default'] = self.default_wallet.accounts[0] == account return result @requires("wallet") @@ -1248,16 +1248,16 @@ class Daemon(AuthJSONRPCServer): self.error_if_account_exists(account_name) account = LBCAccount.generate( self.wallet_manager.get_or_create_ledger('lbc_mainnet'), - self.wallet_manager, account_name, { + self.default_wallet, account_name, { 'name': SingleKey.name if single_key else HierarchicalDeterministic.name } ) - self.wallet_manager.save() + self.default_wallet.save() result = account.to_dict() result['status'] = 'created' result.pop('certificates', None) - result['is_default'] = self.wallet_manager.accounts[0] == account + result['is_default'] = self.default_wallet.accounts[0] == account return result @requires("wallet") @@ -1275,10 +1275,9 @@ class Daemon(AuthJSONRPCServer): (map) removed account details """ - wallet = self.wallet_manager.default_wallet account = self.get_account_or_error('account_name', account_name) - wallet.accounts.remove(account) - wallet.save() + self.default_wallet.accounts.remove(account) + self.default_wallet.save() result = account.to_dict() result['status'] = 'removed' result.pop('certificates', None) @@ -1326,16 +1325,16 @@ class Daemon(AuthJSONRPCServer): change_made = True if default: - self.wallet_manager.accounts.remove(account) - self.wallet_manager.accounts.insert(0, account) + self.default_wallet.accounts.remove(account) + self.default_wallet.accounts.insert(0, account) change_made = True if change_made: - self.wallet_manager.save() + self.default_wallet.save() result = account.to_dict() result.pop('certificates', None) - result['is_default'] = self.wallet_manager.accounts[0] == account + result['is_default'] = self.default_wallet.accounts[0] == account return result @requires(WALLET_COMPONENT) @@ -2031,7 +2030,7 @@ class Daemon(AuthJSONRPCServer): if amount <= 0: raise Exception("Invalid amount") tx = yield self.wallet_manager.claim_new_channel(channel_name, amount) - self.wallet_manager.save() + self.default_wallet.save() self.analytics_manager.send_new_channel() nout = 0 txo = tx.outputs[nout] @@ -2203,7 +2202,7 @@ class Daemon(AuthJSONRPCServer): # raises an error if the address is invalid decode_address(address) - available = yield self.wallet_manager.default_account.get_balance() + available = yield self.default_account.get_balance() if bid >= available: # TODO: add check for existing claim balance #balance = yield self.wallet.get_max_usable_balance_for_claim(name) @@ -2255,7 +2254,7 @@ class Daemon(AuthJSONRPCServer): log.warning("Stripping empty fee from published metadata") del metadata['fee'] elif 'address' not in metadata['fee']: - address = yield self.wallet_manager.default_account.receiving.get_or_create_usable_address() + address = yield self.default_account.receiving.get_or_create_usable_address() metadata['fee']['address'] = address if 'fee' in metadata and 'version' not in metadata['fee']: metadata['fee']['version'] = '_0_0_1' @@ -2309,7 +2308,7 @@ class Daemon(AuthJSONRPCServer): certificate = None if channel_name: - certificates = yield self.wallet_manager.get_certificates(channel_name) + certificates = yield self.default_wallet.get_certificates(channel_name) for cert in certificates: if cert.claim_id == channel_id: certificate = cert @@ -3280,9 +3279,8 @@ class Daemon(AuthJSONRPCServer): response['head_blob_availability'].get('is_available') defer.returnValue(response) - def get_account_or_error(self, argument: str, account_name: str, lbc_only=True): - for account in self.wallet_manager.default_wallet.accounts: + for account in self.default_wallet.accounts: if account.name == account_name: if lbc_only and not isinstance(account, LBCAccount): raise ValueError( @@ -3294,7 +3292,7 @@ class Daemon(AuthJSONRPCServer): raise ValueError("Couldn't find an account named: '{}'.".format(account_name)) def error_if_account_exists(self, account_name: str): - for account in self.wallet_manager.default_wallet.accounts: + for account in self.default_wallet.accounts: if account.name == account_name: raise ValueError("Account with name '{}' already exists.".format(account_name))