electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 94888739d346f970b735daa69f4bb0cec2f73a3b
parent 37747d74695daf000ffb0db9626191193a6b0555
Author: SomberNight <somber.night@protonmail.com>
Date:   Thu,  9 Jan 2020 18:21:48 +0100

try to fix "--offline" mode

Diffstat:
Melectrum/gui/qt/__init__.py | 4++--
Melectrum/gui/qt/channels_list.py | 5++++-
Melectrum/gui/qt/lightning_dialog.py | 1+
Melectrum/gui/qt/main_window.py | 13++++++++-----
Melectrum/gui/qt/watchtower_dialog.py | 1+
Melectrum/lnworker.py | 5+++++
Melectrum/wallet.py | 2+-
7 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/electrum/gui/qt/__init__.py b/electrum/gui/qt/__init__.py @@ -157,9 +157,9 @@ class ElectrumGui(Logger): m.clear() network = self.daemon.network m.addAction(_("Network"), self.show_network_dialog) - if network.lngossip: + if network and network.lngossip: m.addAction(_("Lightning Network"), self.show_lightning_dialog) - if network.local_watchtower: + if network and network.local_watchtower: m.addAction(_("Local Watchtower"), self.show_watchtower_dialog) for window in self.windows: name = window.wallet.basename() diff --git a/electrum/gui/qt/channels_list.py b/electrum/gui/qt/channels_list.py @@ -127,9 +127,12 @@ class ChannelsList(MyTreeView): def do_update_rows(self, wallet): if wallet != self.parent.wallet: return + lnworker = self.parent.wallet.lnworker + if not lnworker: + return self.model().clear() self.update_headers(self.headers) - for chan in self.parent.wallet.lnworker.channels.values(): + for chan in lnworker.channels.values(): items = [QtGui.QStandardItem(x) for x in self.format_fields(chan)] self.set_editability(items) items[self.Columns.NODE_ID].setData(chan.channel_id, ROLE_CHANNEL_ID) diff --git a/electrum/gui/qt/lightning_dialog.py b/electrum/gui/qt/lightning_dialog.py @@ -42,6 +42,7 @@ class LightningDialog(QDialog): self.gui_object = gui_object self.config = gui_object.config self.network = gui_object.daemon.network + assert self.network self.setWindowTitle(_('Lightning Network')) self.setMinimumSize(600, 20) vbox = QVBoxLayout(self) diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py @@ -435,7 +435,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): def load_wallet(self, wallet): wallet.thread = TaskThread(self, self.on_error) self.update_recently_visited(wallet.storage.path) - if wallet.lnworker: + if wallet.lnworker and wallet.network: wallet.network.trigger_callback('channels_updated', wallet) self.need_update.set() # Once GUI has been initialized check if we want to announce something since the callback has been called before the GUI was initialized @@ -642,7 +642,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): tools_menu.addAction(_("Electrum preferences") if sys.platform == 'darwin' else _("Preferences"), self.settings_dialog) if self.network: tools_menu.addAction(_("&Network"), self.gui_object.show_network_dialog) - if self.wallet.has_lightning(): + if self.wallet.has_lightning() and self.network: tools_menu.addAction(_("&Lightning"), self.gui_object.show_lightning_dialog) tools_menu.addAction(_("&Watchtower"), self.gui_object.show_watchtower_dialog) tools_menu.addAction(_("&Plugins"), self.plugins_dialog) @@ -889,7 +889,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): self.tray.setToolTip("%s (%s)" % (text, self.wallet.basename())) self.balance_label.setText(text) - self.status_button.setIcon( icon ) + if self.status_button: + self.status_button.setIcon( icon ) def update_wallet(self): self.update_status() @@ -907,6 +908,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): self.utxo_list.update() self.contact_list.update() self.invoice_list.update() + self.channels_list.update_rows.emit(wallet) self.update_completions() def create_channels_tab(self, wallet): @@ -2027,12 +2029,13 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): sb.addPermanentWidget(StatusBarButton(read_QIcon("preferences.png"), _("Preferences"), self.settings_dialog ) ) self.seed_button = StatusBarButton(read_QIcon("seed.png"), _("Seed"), self.show_seed_dialog ) sb.addPermanentWidget(self.seed_button) - if self.wallet.has_lightning(): + if self.wallet.has_lightning() and self.network: self.lightning_button = StatusBarButton(read_QIcon("lightning.png"), _("Lightning Network"), self.gui_object.show_lightning_dialog) sb.addPermanentWidget(self.lightning_button) + self.status_button = None if self.network: self.status_button = StatusBarButton(read_QIcon("status_disconnected.png"), _("Network"), self.gui_object.show_network_dialog) - sb.addPermanentWidget(self.status_button) + sb.addPermanentWidget(self.status_button) run_hook('create_status_bar', sb) self.setStatusBar(sb) diff --git a/electrum/gui/qt/watchtower_dialog.py b/electrum/gui/qt/watchtower_dialog.py @@ -62,6 +62,7 @@ class WatchtowerDialog(QDialog): self.gui_object = gui_object self.config = gui_object.config self.network = gui_object.daemon.network + assert self.network self.lnwatcher = self.network.local_watchtower self.setWindowTitle(_('Watchtower')) self.setMinimumSize(600, 20) diff --git a/electrum/lnworker.py b/electrum/lnworker.py @@ -186,6 +186,7 @@ class LNWorker(Logger): return sum([p.initialized.is_set() for p in self.peers.values()]) def start_network(self, network: 'Network'): + assert network self.network = network self.config = network.config daemon = network.daemon @@ -306,6 +307,7 @@ class LNGossip(LNWorker): assert is_using_fast_ecc(), "verifying LN gossip msgs without libsecp256k1 is hopeless" def start_network(self, network: 'Network'): + assert network super().start_network(network) asyncio.run_coroutine_threadsafe(network.daemon.taskgroup.spawn(self.maintain_db()), self.network.asyncio_loop) @@ -407,6 +409,7 @@ class LNWallet(LNWorker): await watchtower.add_sweep_tx(outpoint, ctn, tx.inputs()[0].prevout.to_str(), tx.serialize()) def start_network(self, network: 'Network'): + assert network self.lnwatcher = LNWatcher(network) self.lnwatcher.start_network(network) self.network = network @@ -731,6 +734,8 @@ class LNWallet(LNWorker): name = sweep_info.name spender_txid = spenders.get(prevout) if spender_txid is not None: + # TODO handle exceptions for network.get_transaction + # TODO don't do network request every time... save tx at least in memory, or maybe wallet file? spender_tx = await self.network.get_transaction(spender_txid) spender_tx = Transaction(spender_tx) e_htlc_tx = chan.sweep_htlc(closing_tx, spender_tx) diff --git a/electrum/wallet.py b/electrum/wallet.py @@ -307,7 +307,7 @@ class Abstract_Wallet(AddressSynchronizer, ABC): def start_network(self, network): AddressSynchronizer.start_network(self, network) - if self.lnworker: + if self.lnworker and network: network.maybe_init_lightning() self.lnworker.start_network(network)