Browse Source

call wallet.wait_until_synchronized before commands

283
ThomasV 10 years ago
parent
commit
079cb311ec
  1. 3
      electrum
  2. 2
      gui/android.py
  3. 2
      gui/gtk.py
  4. 2
      gui/qt/installwizard.py
  5. 9
      lib/wallet.py

3
electrum

@ -153,7 +153,7 @@ def init_cmdline(config):
wallet.start_threads(network) wallet.start_threads(network)
print_msg("Recovering wallet...") print_msg("Recovering wallet...")
wallet.synchronize() wallet.synchronize()
wallet.restore(lambda x: x) wallet.wait_until_synchronized()
msg = "Recovery successful" if wallet.is_found() else "Found no history for this wallet" msg = "Recovery successful" if wallet.is_found() else "Found no history for this wallet"
else: else:
msg = "This wallet was restored offline. It may contain more addresses than displayed." msg = "This wallet was restored offline. It may contain more addresses than displayed."
@ -247,6 +247,7 @@ def run_command(config, network, password):
# start threads # start threads
if wallet and network: if wallet and network:
wallet.start_threads(network) wallet.start_threads(network)
wallet.wait_until_synchronized()
# arguments passed to function # arguments passed to function
args = map(lambda x: config.get(x), cmd.params) args = map(lambda x: config.get(x), cmd.params)
# decode json arguments # decode json arguments

2
gui/android.py

@ -953,7 +953,7 @@ class ElectrumGui:
droid.dialogShow() droid.dialogShow()
wallet.start_threads(network) wallet.start_threads(network)
if action == 'restore': if action == 'restore':
wallet.restore(lambda x: None) wallet.wait_until_synchronized()
else: else:
wallet.synchronize() wallet.synchronize()
droid.dialogDismiss() droid.dialogDismiss()

2
gui/gtk.py

@ -1357,7 +1357,7 @@ class ElectrumGui():
dialog.show() dialog.show()
def recover_thread( wallet, dialog ): def recover_thread( wallet, dialog ):
wallet.restore(lambda x:x) wallet.wait_until_synchronized()
GObject.idle_add(dialog.destroy) GObject.idle_add(dialog.destroy)
thread.start_new_thread( recover_thread, ( wallet, dialog ) ) thread.start_new_thread( recover_thread, ( wallet, dialog ) )

2
gui/qt/installwizard.py

@ -549,7 +549,7 @@ class InstallWizard(QDialog):
wallet.start_threads(self.network) wallet.start_threads(self.network)
if action == 'restore': if action == 'restore':
self.waiting_dialog(lambda: wallet.restore(self.waiting_label.setText)) self.waiting_dialog(lambda: wallet.wait_until_synchronized(self.waiting_label.setText))
if self.network: if self.network:
msg = _("Recovery successful") if wallet.is_found() else _("No transactions found for this seed") msg = _("Recovery successful") if wallet.is_found() else _("No transactions found for this seed")
else: else:

9
lib/wallet.py

@ -314,11 +314,6 @@ class Abstract_Wallet(PrintError):
def is_up_to_date(self): def is_up_to_date(self):
with self.lock: return self.up_to_date with self.lock: return self.up_to_date
def update(self):
self.up_to_date = False
while not self.is_up_to_date():
time.sleep(0.1)
def is_imported(self, addr): def is_imported(self, addr):
account = self.accounts.get(IMPORTED_ACCOUNT) account = self.accounts.get(IMPORTED_ACCOUNT)
if account: if account:
@ -1135,11 +1130,12 @@ class Abstract_Wallet(PrintError):
self.verifier = None self.verifier = None
self.storage.put('stored_height', self.get_local_height(), True) self.storage.put('stored_height', self.get_local_height(), True)
def restore(self, callback): def wait_until_synchronized(self, callback=None):
from i18n import _ from i18n import _
def wait_for_wallet(): def wait_for_wallet():
self.set_up_to_date(False) self.set_up_to_date(False)
while not self.is_up_to_date(): while not self.is_up_to_date():
if callback:
msg = "%s\n%s %d"%( msg = "%s\n%s %d"%(
_("Please wait..."), _("Please wait..."),
_("Addresses generated:"), _("Addresses generated:"),
@ -1148,6 +1144,7 @@ class Abstract_Wallet(PrintError):
time.sleep(0.1) time.sleep(0.1)
def wait_for_network(): def wait_for_network():
while not self.network.is_connected(): while not self.network.is_connected():
if callback:
msg = "%s \n" % (_("Connecting...")) msg = "%s \n" % (_("Connecting..."))
apply(callback, (msg,)) apply(callback, (msg,))
time.sleep(0.1) time.sleep(0.1)

Loading…
Cancel
Save