From a13cea6f8ac47b37ad1740539072321e2418bf8c Mon Sep 17 00:00:00 2001 From: ThomasV Date: Mon, 14 Oct 2019 11:18:57 +0200 Subject: [PATCH] add remove_lightning command --- electrum/commands.py | 5 +++++ electrum/gui/qt/main_window.py | 18 ++++++++++++++++-- electrum/wallet.py | 9 +++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/electrum/commands.py b/electrum/commands.py index 44740aac3..c06cc6126 100644 --- a/electrum/commands.py +++ b/electrum/commands.py @@ -628,6 +628,11 @@ class Commands: wallet.init_lightning() return "Lightning keys have been created." + @command('w') + async def remove_lightning(self, wallet: Abstract_Wallet = None): + """Disable lightning payments""" + wallet.remove_lightning() + @command('w') async def lightning_history(self, show_fiat=False, wallet: Abstract_Wallet = None): """ lightning history """ diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py index 28bbd4900..ec7f9e6cb 100644 --- a/electrum/gui/qt/main_window.py +++ b/electrum/gui/qt/main_window.py @@ -2390,6 +2390,15 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): if d.exec_(): self.set_contact(line2.text(), line1.text()) + def disable_lightning(self): + warning = _('This will delete your lightning private keys') + r = self.question(_('Disable Lightning payments?') + '\n\n' + warning) + if not r: + return + self.wallet.remove_lightning() + self.show_warning(_('Lightning keys have been removed. This wallet will be closed')) + self.close() + def enable_lightning(self): warning1 = _("Lightning support in Electrum is experimental. Do not put large amounts in lightning channels.") warning2 = _("Funds stored in lightning channels are not recoverable from your seed. You must backup your wallet file everytime you crate a new channel.") @@ -2397,7 +2406,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): if not r: return self.wallet.init_lightning() - self.show_warning(_('Lightning keys have been initialized. Please restart Electrum')) + self.show_warning(_('Lightning keys have been initialized. This wallet will be closed')) + self.close() def show_wallet_info(self): dialog = WindowModalDialog(self, _("Wallet Information")) @@ -2425,10 +2435,14 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): grid.addWidget(QLabel(ks_type), 4, 1) # lightning if self.wallet.has_lightning(): - lightning_b = None + lightning_b = QPushButton(_('Disable')) + lightning_b.clicked.connect(dialog.close) + lightning_b.clicked.connect(self.disable_lightning) lightning_label = QLabel(_('Enabled')) + lightning_b.setDisabled(bool(self.wallet.lnworker.channels)) else: lightning_b = QPushButton(_('Enable')) + lightning_b.clicked.connect(dialog.close) lightning_b.clicked.connect(self.enable_lightning) lightning_label = QLabel(_('Disabled')) grid.addWidget(QLabel(_('Lightning')), 5, 0) diff --git a/electrum/wallet.py b/electrum/wallet.py index 8edfd0b70..12a544e6b 100644 --- a/electrum/wallet.py +++ b/electrum/wallet.py @@ -260,6 +260,15 @@ class Abstract_Wallet(AddressSynchronizer): node = BIP32Node.from_rootseed(seed, xtype='standard') ln_xprv = node.to_xprv() self.storage.put('lightning_privkey2', ln_xprv) + self.storage.write() + + def remove_lightning(self): + if not self.storage.get('lightning_privkey2'): + return + if bool(self.lnworker.channels): + raise Exception('Error: This wallet has channels') + self.storage.put('lightning_privkey2', None) + self.storage.write() def stop_threads(self): super().stop_threads()