Merge pull request #358 from lbryio/fix_wallet_init_3
Fix wallet initialization
This commit is contained in:
commit
552ed77882
1 changed files with 22 additions and 23 deletions
|
@ -771,7 +771,6 @@ class LBRYumWallet(Wallet):
|
|||
self._config = config
|
||||
self.network = None
|
||||
self.wallet = None
|
||||
self.cmd_runner = None
|
||||
self.first_run = False
|
||||
self.printed_retrieving_headers = False
|
||||
self._start_check = None
|
||||
|
@ -809,10 +808,11 @@ class LBRYumWallet(Wallet):
|
|||
|
||||
self._start_check = task.LoopingCall(check_started)
|
||||
|
||||
d.addCallback(lambda _: self._load_wallet())
|
||||
d.addCallback(self._save_wallet)
|
||||
d.addCallback(lambda _: self._start_check.start(.1))
|
||||
d.addCallback(lambda _: network_start_d)
|
||||
d.addCallback(lambda _: self._load_wallet())
|
||||
d.addCallback(lambda _: self._get_cmd_runner())
|
||||
d.addCallback(lambda _: self._load_blockchain())
|
||||
return d
|
||||
|
||||
def _stop(self):
|
||||
|
@ -843,8 +843,6 @@ class LBRYumWallet(Wallet):
|
|||
return d
|
||||
|
||||
def _load_wallet(self):
|
||||
|
||||
def get_wallet():
|
||||
path = self.config.get_wallet_path()
|
||||
storage = lbryum.wallet.WalletStorage(path)
|
||||
wallet = lbryum.wallet.Wallet(storage)
|
||||
|
@ -858,6 +856,7 @@ class LBRYumWallet(Wallet):
|
|||
self.wallet = wallet
|
||||
return defer.succeed(True)
|
||||
|
||||
def _load_blockchain(self):
|
||||
blockchain_caught_d = defer.Deferred()
|
||||
|
||||
def check_caught_up():
|
||||
|
@ -900,30 +899,30 @@ class LBRYumWallet(Wallet):
|
|||
return defer.fail(err)
|
||||
|
||||
self._catch_up_check = task.LoopingCall(check_caught_up)
|
||||
d = get_wallet()
|
||||
d.addCallback(self._save_wallet)
|
||||
d.addCallback(lambda _: self.wallet.start_threads(self.network))
|
||||
d = defer.succeed(self.wallet.start_threads(self.network))
|
||||
d.addCallback(lambda _: self._catch_up_check.start(.1))
|
||||
d.addErrback(log_error)
|
||||
d.addCallback(lambda _: blockchain_caught_d)
|
||||
return d
|
||||
|
||||
def _get_cmd_runner(self):
|
||||
self.cmd_runner = Commands(self.config, self.wallet, self.network)
|
||||
return Commands(self.config, self.wallet, self.network)
|
||||
|
||||
# run commands as a defer.succeed,
|
||||
# lbryum commands should be run this way , unless if the command
|
||||
# only makes a lbrum server query, use _run_cmd_as_defer_to_thread()
|
||||
def _run_cmd_as_defer_succeed(self, command_name, *args):
|
||||
cmd_runner = self._get_cmd_runner()
|
||||
cmd = known_commands[command_name]
|
||||
func = getattr(self.cmd_runner, cmd.name)
|
||||
func = getattr(cmd_runner, cmd.name)
|
||||
return defer.succeed(func(*args))
|
||||
|
||||
# run commands as a deferToThread, lbryum commands that only make
|
||||
# queries to lbryum server should be run this way
|
||||
def _run_cmd_as_defer_to_thread(self, command_name, *args):
|
||||
cmd_runner = self._get_cmd_runner()
|
||||
cmd = known_commands[command_name]
|
||||
func = getattr(self.cmd_runner, cmd.name)
|
||||
func = getattr(cmd_runner, cmd.name)
|
||||
return threads.deferToThread(func, *args)
|
||||
|
||||
def get_balance(self):
|
||||
|
|
Loading…
Reference in a new issue