From e22d43bb03e666565cb2f81886ee6b7b584a0fb9 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Mon, 18 Dec 2017 13:17:54 -0500 Subject: [PATCH] fix wallet_unlock --- lbrynet/core/Wallet.py | 36 +++++++++++++++++------------------- lbrynet/daemon/Daemon.py | 19 +++++-------------- 2 files changed, 22 insertions(+), 33 deletions(-) diff --git a/lbrynet/core/Wallet.py b/lbrynet/core/Wallet.py index 19f605c29..e7a875a45 100644 --- a/lbrynet/core/Wallet.py +++ b/lbrynet/core/Wallet.py @@ -1180,7 +1180,6 @@ class LBRYumWallet(Wallet): self.network = None self.wallet = None self._cmd_runner = None - self.wallet_pw_d = None self.wallet_unlocked_d = defer.Deferred() self.is_first_run = False self.printed_retrieving_headers = False @@ -1204,6 +1203,9 @@ class LBRYumWallet(Wallet): def _start(self): network_start_d = defer.Deferred() + # fired when the wallet actually unlocks (wallet_unlocked_d can be called multiple times) + wallet_unlock_success = defer.Deferred() + def setup_network(): self.network = Network(self.config) log.info("Loading the wallet") @@ -1226,29 +1228,25 @@ class LBRYumWallet(Wallet): if self._cmd_runner and self._cmd_runner.locked: try: self._cmd_runner.unlock_wallet(password) + wallet_unlock_success.callback(True) + log.info("Unlocked the wallet!") except InvalidPassword: - log.warning("Incorrect password") - check_locked() - raise InvalidPassword - if self._cmd_runner and self._cmd_runner.locked: - raise Exception("Failed to unlock wallet") - elif not self._cmd_runner: - raise Exception("Command runner hasn't been initialized yet") - self.wallet_unlocked_d.callback(True) - log.info("Unlocked the wallet!") + log.warning("Incorrect password, try again") + self.wallet_unlocked_d = defer.Deferred() + self.wallet_unlocked_d.addCallback(unlock) + return defer.succeed(False) + return defer.succeed(True) def check_locked(): - if self._cmd_runner and self._cmd_runner.locked: - log.info("Waiting for wallet password") - d = defer.Deferred() - d.addCallback(unlock) - self.wallet_pw_d = d - return self.wallet_unlocked_d - elif not self._cmd_runner: - raise Exception("Command runner hasn't been initialized yet") if not self.wallet.use_encryption: log.info("Wallet is not encrypted") - self.wallet_unlocked_d.callback(True) + wallet_unlock_success.callback(True) + elif not self._cmd_runner: + raise Exception("Command runner hasn't been initialized yet") + elif self._cmd_runner.locked: + log.info("Waiting for wallet password") + self.wallet_unlocked_d.addCallback(unlock) + return wallet_unlock_success self._start_check = task.LoopingCall(check_started) diff --git a/lbrynet/daemon/Daemon.py b/lbrynet/daemon/Daemon.py index b657276ef..eafa5b5c9 100644 --- a/lbrynet/daemon/Daemon.py +++ b/lbrynet/daemon/Daemon.py @@ -21,8 +21,6 @@ from lbryschema.error import URIParseError, DecodeError from lbryschema.validator import validate_claim_id from lbryschema.address import decode_address -from lbryum.errors import InvalidPassword - # TODO: importing this when internet is disabled raises a socket.gaierror from lbrynet.core.system_info import get_lbrynet_version from lbrynet import conf, analytics @@ -1259,19 +1257,12 @@ class Daemon(AuthJSONRPCServer): """ cmd_runner = self.session.wallet.get_cmd_runner() - if cmd_runner is not None and cmd_runner.locked: - result = True - elif self.session.wallet.wallet_pw_d is not None: - d = self.session.wallet.wallet_pw_d - if not d.called: - d.addCallback(lambda _: not self.session.wallet._cmd_runner.locked) - self.session.wallet.wallet_pw_d.callback(password) - try: - result = yield d - except InvalidPassword: - result = False + if cmd_runner.locked: + d = self.session.wallet.wallet_unlocked_d + d.callback(password) + result = yield d else: - result = self.session.wallet._cmd_runner.locked + result = True response = yield self._render_response(result) defer.returnValue(response)