URI: 
       trestrict lightning to p2wpkh wallets - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 570167a2c469c6da5928cf2dc8badae421a0c695
   DIR parent 2255b0715704bf9e32a4e5b9d1fda511be7b5938
  HTML Author: ThomasV <thomasv@electrum.org>
       Date:   Thu, 20 Feb 2020 20:54:26 +0100
       
       restrict lightning to p2wpkh wallets
       
       Diffstat:
         M electrum/gui/kivy/uix/ui_screens/s… |       3 ++-
         M electrum/gui/qt/main_window.py      |      29 +++++++++++++++--------------
         M electrum/lnpeer.py                  |       6 ++++--
         M electrum/wallet.py                  |       5 +++++
       
       4 files changed, 26 insertions(+), 17 deletions(-)
       ---
   DIR diff --git a/electrum/gui/kivy/uix/ui_screens/status.kv b/electrum/gui/kivy/uix/ui_screens/status.kv
       t@@ -31,7 +31,7 @@ Popup:
                                value: app.wallet.wallet_type
                            BoxLabel:
                                text: _("Lightning:")
       -                        value: _('Enabled') if app.wallet.has_lightning() else _('Disabled')
       +                        value: (_('Enabled') if app.wallet.has_lightning() else _('Disabled')) if app.wallet.can_have_lightning() else _('Not available')
                            BoxLabel:
                                text: _("Balance") + ':'
                                value: app.format_amount_and_units(root.confirmed + root.unconfirmed + root.unmatured)
       t@@ -90,6 +90,7 @@ Popup:
                    Button:
                        size_hint: 0.5, None
                        height: '48dp'
       +                disabled: not app.wallet.can_have_lightning()
                        text: _('Disable LN') if app.wallet.has_lightning() else _('Enable LN')
                        on_release:
                            root.dismiss()
   DIR diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py
       t@@ -2190,20 +2190,21 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
                    ks_type = str(keystore_types[0]) if keystore_types else _('No keystore')
                    grid.addWidget(QLabel(ks_type), 4, 1)
                # lightning
       -        if self.wallet.has_lightning():
       -            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)
       -        grid.addWidget(lightning_label, 5, 1)
       -        grid.addWidget(lightning_b, 5, 2)
       +        if self.wallet.can_have_lightning():
       +            if self.wallet.has_lightning():
       +                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)
       +            grid.addWidget(lightning_label, 5, 1)
       +            grid.addWidget(lightning_b, 5, 2)
                vbox.addLayout(grid)
        
                if self.wallet.is_deterministic():
   DIR diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py
       t@@ -474,8 +474,10 @@ class Peer(Logger):
                    initial_msat = push_msat
        
                if self.is_static_remotekey():
       -            addr = self.lnworker.wallet.get_unused_address()
       -            static_key = self.lnworker.wallet.get_public_key(addr) # just a pubkey
       +            wallet = self.lnworker.wallet
       +            assert wallet.txin_type == 'p2wpkh'
       +            addr = wallet.get_unused_address()
       +            static_key = wallet.get_public_key(addr) # just a pubkey
                    payment_basepoint = OnlyPubkeyKeypair(bfh(static_key))
                else:
                    payment_basepoint = keypair_generator(LnKeyFamily.PAYMENT_BASE)
   DIR diff --git a/electrum/wallet.py b/electrum/wallet.py
       t@@ -280,7 +280,12 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
            def has_lightning(self):
                return bool(self.lnworker)
        
       +    def can_have_lightning(self):
       +        # we want static_remotekey to be a wallet address
       +        return self.txin_type == 'p2wpkh'
       +
            def init_lightning(self):
       +        assert self.can_have_lightning()
                if self.db.get('lightning_privkey2'):
                    return
                # TODO derive this deterministically from wallet.keystore at keystore generation time