From b1472ba1a7aea0817dd445d9906046cad2f12b63 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Tue, 5 Nov 2013 18:55:53 +0100 Subject: [PATCH] fix regression: offline mode --- electrum | 36 +++++++++++++++++++++++------------- gui/qt/installwizard.py | 14 ++++++++------ gui/qt/lite_window.py | 11 +++++++---- gui/qt/main_window.py | 28 ++++++++++++++++++---------- lib/wallet.py | 35 +++++++++++++++++++++++------------ 5 files changed, 79 insertions(+), 45 deletions(-) diff --git a/electrum b/electrum index b7fd394e1..e06b2b6c7 100755 --- a/electrum +++ b/electrum @@ -153,13 +153,18 @@ if __name__ == '__main__': #sys.exit("Error: Unknown GUI: " + gui_name ) # network interface - network = Network(config) - network.start() + if not options.offline: + network = Network(config) + network.start() + else: + network = None gui = gui.ElectrumGui(config, network) gui.main(url) - network.stop() + if network: + network.stop() + # we use daemon threads, their termination is enforced. # this sleep command gives them time to terminate cleanly. time.sleep(0.1) @@ -215,17 +220,22 @@ if __name__ == '__main__': wallet.init_seed( str(seed) ) wallet.save_seed() - network = Network(config) - network.start() - wallet.start_threads(network) - - print_msg("Recovering wallet...") - wallet.restore(lambda x: x) - - if wallet.is_found(): - print_msg("Recovery successful") + if not options.offline: + network = Network(config) + network.start() + wallet.start_threads(network) + + print_msg("Recovering wallet...") + wallet.restore(lambda x: x) + + if wallet.is_found(): + print_msg("Recovery successful") + else: + print_msg("Warning: Found no history for this wallet") else: - print_msg("Warning: Found no history for this wallet") + wallet.create_accounts() + wallet.synchronize() + print_msg("Warning: This wallet was restored offline. It may contain more addresses than displayed.") else: wallet.init_seed(None) diff --git a/gui/qt/installwizard.py b/gui/qt/installwizard.py index 884186cb9..57698f7d8 100644 --- a/gui/qt/installwizard.py +++ b/gui/qt/installwizard.py @@ -304,7 +304,8 @@ class InstallWizard(QDialog): else: raise #if not self.config.get('server'): - self.network_dialog() + if self.network: + self.network_dialog() # start wallet threads wallet.start_threads(self.network) @@ -313,12 +314,13 @@ class InstallWizard(QDialog): self.waiting_dialog(lambda: wallet.restore(self.waiting_label.setText)) - if wallet.is_found(): - QMessageBox.information(None, _('Information'), _("Recovery successful"), _('OK')) + if self.network: + if wallet.is_found(): + QMessageBox.information(None, _('Information'), _("Recovery successful"), _('OK')) + else: + QMessageBox.information(None, _('Information'), _("No transactions found for this seed"), _('OK')) else: - QMessageBox.information(None, _('Information'), _("No transactions found for this seed"), _('OK')) - - wallet.fill_addressbook() + QMessageBox.information(None, _('Information'), _("This wallet was restored offline. It may contain more addresses than displayed."), _('OK')) self.password_dialog(wallet) diff --git a/gui/qt/lite_window.py b/gui/qt/lite_window.py index 1a422b1e2..3f2437084 100644 --- a/gui/qt/lite_window.py +++ b/gui/qt/lite_window.py @@ -821,9 +821,10 @@ class MiniDriver(QObject): self.network = main_window.network self.window = mini_window - self.network.register_callback('updated',self.update_callback) - self.network.register_callback('connected', self.update_callback) - self.network.register_callback('disconnected', self.update_callback) + if self.network: + self.network.register_callback('updated',self.update_callback) + self.network.register_callback('connected', self.update_callback) + self.network.register_callback('disconnected', self.update_callback) self.state = None @@ -838,7 +839,9 @@ class MiniDriver(QObject): self.emit(SIGNAL("updatesignal()")) def update(self): - if not self.network.interface: + if not self.network: + self.initializing() + elif not self.network.interface: self.initializing() elif not self.network.interface.is_connected: self.connecting() diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py index f1b465a73..ff8711dd7 100644 --- a/gui/qt/main_window.py +++ b/gui/qt/main_window.py @@ -187,13 +187,15 @@ class ElectrumWindow(QMainWindow): self.history_list.setFocus(True) # network callbacks - self.network.register_callback('updated', lambda: self.need_update.set()) - self.network.register_callback('banner', lambda: self.emit(QtCore.SIGNAL('banner_signal'))) - self.network.register_callback('disconnected', lambda: self.emit(QtCore.SIGNAL('update_status'))) - self.network.register_callback('disconnecting', lambda: self.emit(QtCore.SIGNAL('update_status'))) - self.network.register_callback('new_transaction', lambda: self.emit(QtCore.SIGNAL('transaction_signal'))) - # set initial message - self.console.showMessage(self.network.banner) + if self.network: + self.network.register_callback('updated', lambda: self.need_update.set()) + self.network.register_callback('banner', lambda: self.emit(QtCore.SIGNAL('banner_signal'))) + self.network.register_callback('disconnected', lambda: self.emit(QtCore.SIGNAL('update_status'))) + self.network.register_callback('disconnecting', lambda: self.emit(QtCore.SIGNAL('update_status'))) + self.network.register_callback('new_transaction', lambda: self.emit(QtCore.SIGNAL('transaction_signal'))) + + # set initial message + self.console.showMessage(self.network.banner) self.wallet = None self.init_lite() @@ -457,7 +459,7 @@ class ElectrumWindow(QMainWindow): def notify_transactions(self): - if not self.network.is_connected(): + if not self.network or not self.network.is_connected(): return print_error("Notifying GUI") @@ -532,7 +534,11 @@ class ElectrumWindow(QMainWindow): def update_status(self): - if self.network.is_connected(): + if self.network is None: + text = _("Offline") + icon = QIcon(":icons/status_disconnected.png") + + elif self.network.is_connected(): if not self.wallet.up_to_date: text = _("Synchronizing...") icon = QIcon(":icons/status_waiting.png") @@ -562,7 +568,7 @@ class ElectrumWindow(QMainWindow): def update_wallet(self): self.update_status() - if self.wallet.up_to_date or not self.network.is_connected(): + if self.wallet.up_to_date or not self.network or not self.network.is_connected(): self.update_history_tab() self.update_receive_tab() self.update_contacts_tab() @@ -2073,6 +2079,8 @@ class ElectrumWindow(QMainWindow): def run_network_dialog(self): + if not self.network: + return NetworkDialog(self.wallet.network, self.config, self).do_exec() def closeEvent(self, event): diff --git a/lib/wallet.py b/lib/wallet.py index afaa55f37..731a8980a 100644 --- a/lib/wallet.py +++ b/lib/wallet.py @@ -1560,16 +1560,20 @@ class Wallet: def start_threads(self, network): from verifier import TxVerifier self.network = network - self.verifier = TxVerifier(self.network, self.storage) - self.verifier.start() - self.set_verifier(self.verifier) - self.synchronizer = WalletSynchronizer(self, network) - self.synchronizer.start() + if self.network: + self.verifier = TxVerifier(self.network, self.storage) + self.verifier.start() + self.set_verifier(self.verifier) + self.synchronizer = WalletSynchronizer(self, network) + self.synchronizer.start() + else: + self.verifier = None + self.synchronizer =None def stop_threads(self): - self.verifier.stop() - self.synchronizer.stop() - + if self.network: + self.verifier.stop() + self.synchronizer.stop() def restore(self, callback): @@ -1580,7 +1584,8 @@ class Wallet: msg = "%s\n%s %d\n%s %.1f"%( _("Please wait..."), _("Addresses generated:"), - len(self.addresses(True)),_("Kilobytes received:"), + len(self.addresses(True)), + _("Kilobytes received:"), self.network.interface.bytes_received/1024.) apply(callback, (msg,)) @@ -1593,11 +1598,17 @@ class Wallet: time.sleep(0.1) # wait until we are connected, because the user might have selected another server - wait_for_network() - + if self.network: + wait_for_network() self.create_accounts() - wait_for_wallet() + + if self.network: + wait_for_wallet() + else: + self.synchronize() + + self.fill_addressbook()