Browse Source

Allow user to remove onchain backups.

patch-4
ThomasV 4 years ago
parent
commit
a5fea043d1
  1. 12
      electrum/gui/kivy/uix/dialogs/lightning_channels.py
  2. 4
      electrum/gui/qt/channels_list.py
  3. 6
      electrum/lnchannel.py
  4. 16
      electrum/lnworker.py

12
electrum/gui/kivy/uix/dialogs/lightning_channels.py

@ -225,7 +225,7 @@ Builder.load_string(r'''
id: popuproot
data: []
is_closed: False
is_redeemed: False
can_be_deleted: False
node_id:''
short_id:''
initiator:''
@ -334,13 +334,13 @@ Builder.load_string(r'''
height: '48dp'
text: _('Delete')
on_release: root.remove_channel()
disabled: not root.is_redeemed
disabled: not root.can_be_deleted
<ChannelBackupPopup@Popup>:
id: popuproot
data: []
is_funded: False
is_imported: False
can_be_deleted: False
node_id:''
short_id:''
initiator:''
@ -412,7 +412,7 @@ Builder.load_string(r'''
height: '48dp'
text: _('Delete')
on_release: root.remove_backup()
disabled: not root.is_imported
disabled: not root.can_be_deleted
''')
@ -423,7 +423,7 @@ class ChannelBackupPopup(Popup, Logger):
Logger.__init__(self)
self.chan = chan
self.is_funded = chan.get_state() == ChannelState.FUNDED
self.is_imported = chan.is_imported
self.can_be_deleted = chan.can_be_deleted()
self.funding_txid = chan.funding_outpoint.txid
self.app = app
self.short_id = format_short_channel_id(chan.short_channel_id)
@ -464,7 +464,7 @@ class ChannelDetailsPopup(Popup, Logger):
Popup.__init__(self, **kwargs)
Logger.__init__(self)
self.is_closed = chan.is_closed()
self.is_redeemed = chan.is_redeemed()
self.can_be_deleted = chan.can_be_deleted()
self.app = app
self.chan = chan
self.title = _('Channel details')

4
electrum/gui/qt/channels_list.py

@ -214,7 +214,7 @@ class ChannelsList(MyTreeView):
menu.addAction(_("View funding transaction"), lambda: self.parent.show_transaction(funding_tx))
if chan.get_state() == ChannelState.FUNDED:
menu.addAction(_("Request force-close"), lambda: self.request_force_close(channel_id))
if chan.is_imported:
if chan.can_be_deleted():
menu.addAction(_("Delete"), lambda: self.remove_channel_backup(channel_id))
menu.exec_(self.viewport().mapToGlobal(position))
return
@ -252,7 +252,7 @@ class ChannelsList(MyTreeView):
menu.addAction(_("View closing transaction"), lambda: self.parent.show_transaction(closing_tx))
menu.addSeparator()
menu.addAction(_("Export backup"), lambda: self.export_channel_backup(channel_id))
if chan.is_redeemed():
if chan.can_be_deleted():
menu.addSeparator()
menu.addAction(_("Delete"), lambda: self.remove_channel(channel_id))
menu.exec_(self.viewport().mapToGlobal(position))

6
electrum/lnchannel.py

@ -456,6 +456,9 @@ class ChannelBackup(AbstractChannel):
current_per_commitment_point=None,
upfront_shutdown_script='')
def can_be_deleted(self):
return self.is_imported or self.is_redeemed()
def get_capacity(self):
return self.lnworker.lnwatcher.get_tx_delta(self.funding_outpoint.txid, self.cb.funding_address)
@ -550,6 +553,9 @@ class Channel(AbstractChannel):
self.should_request_force_close = False
self.force_close_detected = False # not a state, only for GUI
def can_be_deleted(self):
return self.is_redeemed()
def get_capacity(self):
return self.constraints.capacity

16
electrum/lnworker.py

@ -1970,8 +1970,8 @@ class LNWallet(LNWorker):
await self.network.try_broadcasting(tx, 'force-close')
def remove_channel(self, chan_id):
chan = self._channels[chan_id]
assert chan.get_state() == ChannelState.REDEEMED
chan = self.channels[chan_id]
assert chan.can_be_deleted()
with self.lock:
self._channels.pop(chan_id)
self.db.get('channels').pop(chan_id.hex())
@ -2099,11 +2099,17 @@ class LNWallet(LNWorker):
self.lnwatcher.add_channel(cb.funding_outpoint.to_str(), cb.get_funding_address())
def remove_channel_backup(self, channel_id):
d = self.db.get_dict("imported_channel_backups")
if channel_id.hex() not in d:
chan = self.channel_backups[channel_id]
assert chan.can_be_deleted()
onchain_backups = self.db.get_dict("onchain_channel_backups")
imported_backups = self.db.get_dict("onchain_channel_backups")
if channel_id.hex() in onchain_backups:
onchain_backups.pop(channel_id.hex())
elif channel_id.hex() in imported_backups:
imported_backups.pop(channel_id.hex())
else:
raise Exception('Channel not found')
with self.lock:
d.pop(channel_id.hex())
self._channel_backups.pop(channel_id)
self.wallet.save_db()
util.trigger_callback('channels_updated', self.wallet)

Loading…
Cancel
Save