commit 570167a2c469c6da5928cf2dc8badae421a0c695
parent 2255b0715704bf9e32a4e5b9d1fda511be7b5938
Author: ThomasV <thomasv@electrum.org>
Date: Thu, 20 Feb 2020 20:54:26 +0100
restrict lightning to p2wpkh wallets
Diffstat:
4 files changed, 26 insertions(+), 17 deletions(-)
diff --git a/electrum/gui/kivy/uix/ui_screens/status.kv b/electrum/gui/kivy/uix/ui_screens/status.kv
@@ -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)
@@ -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()
diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py
@@ -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():
diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py
@@ -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)
diff --git a/electrum/wallet.py b/electrum/wallet.py
@@ -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