Browse Source

fix regression: offline mode

283
ThomasV 11 years ago
parent
commit
b1472ba1a7
  1. 10
      electrum
  2. 6
      gui/qt/installwizard.py
  3. 5
      gui/qt/lite_window.py
  4. 14
      gui/qt/main_window.py
  5. 17
      lib/wallet.py

10
electrum

@ -153,13 +153,18 @@ if __name__ == '__main__':
#sys.exit("Error: Unknown GUI: " + gui_name ) #sys.exit("Error: Unknown GUI: " + gui_name )
# network interface # network interface
if not options.offline:
network = Network(config) network = Network(config)
network.start() network.start()
else:
network = None
gui = gui.ElectrumGui(config, network) gui = gui.ElectrumGui(config, network)
gui.main(url) gui.main(url)
if network:
network.stop() network.stop()
# we use daemon threads, their termination is enforced. # we use daemon threads, their termination is enforced.
# this sleep command gives them time to terminate cleanly. # this sleep command gives them time to terminate cleanly.
time.sleep(0.1) time.sleep(0.1)
@ -215,6 +220,7 @@ if __name__ == '__main__':
wallet.init_seed( str(seed) ) wallet.init_seed( str(seed) )
wallet.save_seed() wallet.save_seed()
if not options.offline:
network = Network(config) network = Network(config)
network.start() network.start()
wallet.start_threads(network) wallet.start_threads(network)
@ -226,6 +232,10 @@ if __name__ == '__main__':
print_msg("Recovery successful") print_msg("Recovery successful")
else: else:
print_msg("Warning: Found no history for this wallet") print_msg("Warning: Found no history for this wallet")
else:
wallet.create_accounts()
wallet.synchronize()
print_msg("Warning: This wallet was restored offline. It may contain more addresses than displayed.")
else: else:
wallet.init_seed(None) wallet.init_seed(None)

6
gui/qt/installwizard.py

@ -304,6 +304,7 @@ class InstallWizard(QDialog):
else: raise else: raise
#if not self.config.get('server'): #if not self.config.get('server'):
if self.network:
self.network_dialog() self.network_dialog()
# start wallet threads # start wallet threads
@ -313,12 +314,13 @@ class InstallWizard(QDialog):
self.waiting_dialog(lambda: wallet.restore(self.waiting_label.setText)) self.waiting_dialog(lambda: wallet.restore(self.waiting_label.setText))
if self.network:
if wallet.is_found(): if wallet.is_found():
QMessageBox.information(None, _('Information'), _("Recovery successful"), _('OK')) QMessageBox.information(None, _('Information'), _("Recovery successful"), _('OK'))
else: else:
QMessageBox.information(None, _('Information'), _("No transactions found for this seed"), _('OK')) QMessageBox.information(None, _('Information'), _("No transactions found for this seed"), _('OK'))
else:
wallet.fill_addressbook() QMessageBox.information(None, _('Information'), _("This wallet was restored offline. It may contain more addresses than displayed."), _('OK'))
self.password_dialog(wallet) self.password_dialog(wallet)

5
gui/qt/lite_window.py

@ -821,6 +821,7 @@ class MiniDriver(QObject):
self.network = main_window.network self.network = main_window.network
self.window = mini_window self.window = mini_window
if self.network:
self.network.register_callback('updated',self.update_callback) self.network.register_callback('updated',self.update_callback)
self.network.register_callback('connected', self.update_callback) self.network.register_callback('connected', self.update_callback)
self.network.register_callback('disconnected', self.update_callback) self.network.register_callback('disconnected', self.update_callback)
@ -838,7 +839,9 @@ class MiniDriver(QObject):
self.emit(SIGNAL("updatesignal()")) self.emit(SIGNAL("updatesignal()"))
def update(self): def update(self):
if not self.network.interface: if not self.network:
self.initializing()
elif not self.network.interface:
self.initializing() self.initializing()
elif not self.network.interface.is_connected: elif not self.network.interface.is_connected:
self.connecting() self.connecting()

14
gui/qt/main_window.py

@ -187,11 +187,13 @@ class ElectrumWindow(QMainWindow):
self.history_list.setFocus(True) self.history_list.setFocus(True)
# network callbacks # network callbacks
if self.network:
self.network.register_callback('updated', lambda: self.need_update.set()) 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('banner', lambda: self.emit(QtCore.SIGNAL('banner_signal')))
self.network.register_callback('disconnected', lambda: self.emit(QtCore.SIGNAL('update_status'))) 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('disconnecting', lambda: self.emit(QtCore.SIGNAL('update_status')))
self.network.register_callback('new_transaction', lambda: self.emit(QtCore.SIGNAL('transaction_signal'))) self.network.register_callback('new_transaction', lambda: self.emit(QtCore.SIGNAL('transaction_signal')))
# set initial message # set initial message
self.console.showMessage(self.network.banner) self.console.showMessage(self.network.banner)
@ -457,7 +459,7 @@ class ElectrumWindow(QMainWindow):
def notify_transactions(self): def notify_transactions(self):
if not self.network.is_connected(): if not self.network or not self.network.is_connected():
return return
print_error("Notifying GUI") print_error("Notifying GUI")
@ -532,7 +534,11 @@ class ElectrumWindow(QMainWindow):
def update_status(self): 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: if not self.wallet.up_to_date:
text = _("Synchronizing...") text = _("Synchronizing...")
icon = QIcon(":icons/status_waiting.png") icon = QIcon(":icons/status_waiting.png")
@ -562,7 +568,7 @@ class ElectrumWindow(QMainWindow):
def update_wallet(self): def update_wallet(self):
self.update_status() 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_history_tab()
self.update_receive_tab() self.update_receive_tab()
self.update_contacts_tab() self.update_contacts_tab()
@ -2073,6 +2079,8 @@ class ElectrumWindow(QMainWindow):
def run_network_dialog(self): def run_network_dialog(self):
if not self.network:
return
NetworkDialog(self.wallet.network, self.config, self).do_exec() NetworkDialog(self.wallet.network, self.config, self).do_exec()
def closeEvent(self, event): def closeEvent(self, event):

17
lib/wallet.py

@ -1560,18 +1560,22 @@ class Wallet:
def start_threads(self, network): def start_threads(self, network):
from verifier import TxVerifier from verifier import TxVerifier
self.network = network self.network = network
if self.network:
self.verifier = TxVerifier(self.network, self.storage) self.verifier = TxVerifier(self.network, self.storage)
self.verifier.start() self.verifier.start()
self.set_verifier(self.verifier) self.set_verifier(self.verifier)
self.synchronizer = WalletSynchronizer(self, network) self.synchronizer = WalletSynchronizer(self, network)
self.synchronizer.start() self.synchronizer.start()
else:
self.verifier = None
self.synchronizer =None
def stop_threads(self): def stop_threads(self):
if self.network:
self.verifier.stop() self.verifier.stop()
self.synchronizer.stop() self.synchronizer.stop()
def restore(self, callback): def restore(self, callback):
from i18n import _ from i18n import _
def wait_for_wallet(): def wait_for_wallet():
@ -1580,7 +1584,8 @@ class Wallet:
msg = "%s\n%s %d\n%s %.1f"%( msg = "%s\n%s %d\n%s %.1f"%(
_("Please wait..."), _("Please wait..."),
_("Addresses generated:"), _("Addresses generated:"),
len(self.addresses(True)),_("Kilobytes received:"), len(self.addresses(True)),
_("Kilobytes received:"),
self.network.interface.bytes_received/1024.) self.network.interface.bytes_received/1024.)
apply(callback, (msg,)) apply(callback, (msg,))
@ -1593,11 +1598,17 @@ class Wallet:
time.sleep(0.1) time.sleep(0.1)
# wait until we are connected, because the user might have selected another server # wait until we are connected, because the user might have selected another server
if self.network:
wait_for_network() wait_for_network()
self.create_accounts() self.create_accounts()
if self.network:
wait_for_wallet() wait_for_wallet()
else:
self.synchronize()
self.fill_addressbook()

Loading…
Cancel
Save