mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
Save and read lighting backups (Qt)
This commit is contained in:
parent
edc00b448f
commit
62eceeb573
4 changed files with 43 additions and 14 deletions
|
@ -233,6 +233,7 @@ class ElectrumGui(Logger):
|
||||||
run_hook('on_new_window', w)
|
run_hook('on_new_window', w)
|
||||||
w.warn_if_testnet()
|
w.warn_if_testnet()
|
||||||
w.warn_if_watching_only()
|
w.warn_if_watching_only()
|
||||||
|
w.warn_if_lightning_backup()
|
||||||
return w
|
return w
|
||||||
|
|
||||||
def count_wizards_in_progress(func):
|
def count_wizards_in_progress(func):
|
||||||
|
|
|
@ -8,7 +8,7 @@ from PyQt5.QtWidgets import QMenu, QHBoxLayout, QLabel, QVBoxLayout, QGridLayout
|
||||||
|
|
||||||
from electrum.util import bh2u, NotEnoughFunds, NoDynamicFeeEstimates
|
from electrum.util import bh2u, NotEnoughFunds, NoDynamicFeeEstimates
|
||||||
from electrum.i18n import _
|
from electrum.i18n import _
|
||||||
from electrum.lnchannel import Channel
|
from electrum.lnchannel import Channel, peer_states
|
||||||
from electrum.wallet import Abstract_Wallet
|
from electrum.wallet import Abstract_Wallet
|
||||||
from electrum.lnutil import LOCAL, REMOTE, format_short_channel_id, LN_MAX_FUNDING_SAT
|
from electrum.lnutil import LOCAL, REMOTE, format_short_channel_id, LN_MAX_FUNDING_SAT
|
||||||
|
|
||||||
|
@ -84,10 +84,14 @@ class ChannelsList(MyTreeView):
|
||||||
WaitingDialog(self, 'please wait..', task, self.on_success, self.on_failure)
|
WaitingDialog(self, 'please wait..', task, self.on_success, self.on_failure)
|
||||||
|
|
||||||
def force_close(self, channel_id):
|
def force_close(self, channel_id):
|
||||||
|
if self.lnworker.wallet.is_lightning_backup():
|
||||||
|
msg = _('<b>WARNING<b>: force-closing from an old state might result in fund loss.\nAre you sure?')
|
||||||
|
else:
|
||||||
|
msg = _('Force-close channel?\nReclaimed funds will not be immediately available.')
|
||||||
|
if self.parent.question(msg):
|
||||||
def task():
|
def task():
|
||||||
coro = self.lnworker.force_close_channel(channel_id)
|
coro = self.lnworker.force_close_channel(channel_id)
|
||||||
return self.network.run_from_another_thread(coro)
|
return self.network.run_from_another_thread(coro)
|
||||||
if self.parent.question('Force-close channel?\nReclaimed funds will not be immediately available.'):
|
|
||||||
WaitingDialog(self, 'please wait..', task, self.on_success, self.on_failure)
|
WaitingDialog(self, 'please wait..', task, self.on_success, self.on_failure)
|
||||||
|
|
||||||
def remove_channel(self, channel_id):
|
def remove_channel(self, channel_id):
|
||||||
|
@ -105,6 +109,7 @@ class ChannelsList(MyTreeView):
|
||||||
menu.addAction(_("Details..."), lambda: self.details(channel_id))
|
menu.addAction(_("Details..."), lambda: self.details(channel_id))
|
||||||
self.add_copy_menu(menu, idx)
|
self.add_copy_menu(menu, idx)
|
||||||
if not chan.is_closed():
|
if not chan.is_closed():
|
||||||
|
if chan.peer_state == peer_states.GOOD:
|
||||||
menu.addAction(_("Close channel"), lambda: self.close_channel(channel_id))
|
menu.addAction(_("Close channel"), lambda: self.close_channel(channel_id))
|
||||||
menu.addAction(_("Force-close channel"), lambda: self.force_close(channel_id))
|
menu.addAction(_("Force-close channel"), lambda: self.force_close(channel_id))
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -513,6 +513,18 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
||||||
])
|
])
|
||||||
self.show_warning(msg, title=_('Watch-only wallet'))
|
self.show_warning(msg, title=_('Watch-only wallet'))
|
||||||
|
|
||||||
|
def warn_if_lightning_backup(self):
|
||||||
|
if self.wallet.is_lightning_backup():
|
||||||
|
msg = '\n\n'.join([
|
||||||
|
_("This file is a backup of a lightning wallet."),
|
||||||
|
_("You will not be able to perform lightning payments using this file, and the lightning balance displayed in this wallet might be outdated.") + ' ' + \
|
||||||
|
_("If you have lost the original wallet file, you can use this file to trigger a forced closure of your channels."),
|
||||||
|
_("Do you want to have your channels force-closed?")
|
||||||
|
])
|
||||||
|
if self.question(msg, title=_('Lightning Backup')):
|
||||||
|
self.network.maybe_init_lightning()
|
||||||
|
self.wallet.lnworker.start_network(self.network)
|
||||||
|
|
||||||
def warn_if_testnet(self):
|
def warn_if_testnet(self):
|
||||||
if not constants.net.TESTNET:
|
if not constants.net.TESTNET:
|
||||||
return
|
return
|
||||||
|
@ -549,7 +561,6 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
||||||
return
|
return
|
||||||
self.gui_object.new_window(filename)
|
self.gui_object.new_window(filename)
|
||||||
|
|
||||||
|
|
||||||
def backup_wallet(self):
|
def backup_wallet(self):
|
||||||
path = self.wallet.storage.path
|
path = self.wallet.storage.path
|
||||||
wallet_folder = os.path.dirname(path)
|
wallet_folder = os.path.dirname(path)
|
||||||
|
@ -557,12 +568,14 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
||||||
if not filename:
|
if not filename:
|
||||||
return
|
return
|
||||||
new_path = os.path.join(wallet_folder, filename)
|
new_path = os.path.join(wallet_folder, filename)
|
||||||
if new_path != path:
|
if new_path == path:
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
shutil.copy2(path, new_path)
|
self.wallet.save_backup(new_path)
|
||||||
self.show_message(_("A copy of your wallet file was created in")+" '%s'" % str(new_path), title=_("Wallet backup created"))
|
|
||||||
except BaseException as reason:
|
except BaseException as reason:
|
||||||
self.show_critical(_("Electrum was unable to copy your wallet file to the specified location.") + "\n" + str(reason), title=_("Unable to create backup"))
|
self.show_critical(_("Electrum was unable to copy your wallet file to the specified location.") + "\n" + str(reason), title=_("Unable to create backup"))
|
||||||
|
return
|
||||||
|
self.show_message(_("A copy of your wallet file was created in")+" '%s'" % str(new_path), title=_("Wallet backup created"))
|
||||||
|
|
||||||
def update_recently_visited(self, filename):
|
def update_recently_visited(self, filename):
|
||||||
recent = self.config.get('recently_open', [])
|
recent = self.config.get('recently_open', [])
|
||||||
|
|
|
@ -263,6 +263,13 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
|
||||||
if self.storage:
|
if self.storage:
|
||||||
self.db.write(self.storage)
|
self.db.write(self.storage)
|
||||||
|
|
||||||
|
def save_backup(self, path):
|
||||||
|
# fixme: we need to change password...
|
||||||
|
new_storage = WalletStorage(path)
|
||||||
|
self.db.put('is_backup', True)
|
||||||
|
self.db.write(new_storage)
|
||||||
|
self.db.put('is_backup', None)
|
||||||
|
|
||||||
def has_lightning(self):
|
def has_lightning(self):
|
||||||
return bool(self.lnworker)
|
return bool(self.lnworker)
|
||||||
|
|
||||||
|
@ -285,6 +292,9 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
|
||||||
self.db.put('lightning_privkey2', None)
|
self.db.put('lightning_privkey2', None)
|
||||||
self.save_db()
|
self.save_db()
|
||||||
|
|
||||||
|
def is_lightning_backup(self):
|
||||||
|
return self.has_lightning() and self.db.get('is_backup')
|
||||||
|
|
||||||
def stop_threads(self):
|
def stop_threads(self):
|
||||||
super().stop_threads()
|
super().stop_threads()
|
||||||
if any([ks.is_requesting_to_be_rewritten_to_wallet_file for ks in self.get_keystores()]):
|
if any([ks.is_requesting_to_be_rewritten_to_wallet_file for ks in self.get_keystores()]):
|
||||||
|
@ -301,7 +311,7 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
|
||||||
|
|
||||||
def start_network(self, network):
|
def start_network(self, network):
|
||||||
AddressSynchronizer.start_network(self, network)
|
AddressSynchronizer.start_network(self, network)
|
||||||
if self.lnworker and network:
|
if self.lnworker and network and not self.is_lightning_backup():
|
||||||
network.maybe_init_lightning()
|
network.maybe_init_lightning()
|
||||||
self.lnworker.start_network(network)
|
self.lnworker.start_network(network)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue