make init_lightning callable at runtime, without reloading the wallet
This commit is contained in:
@@ -1428,8 +1428,5 @@ class ElectrumWindow(App, Logger):
|
|||||||
def _enable_lightning(self, b):
|
def _enable_lightning(self, b):
|
||||||
if not b:
|
if not b:
|
||||||
return
|
return
|
||||||
wallet_path = self.get_wallet_path()
|
|
||||||
self.wallet.init_lightning(password=self.password)
|
self.wallet.init_lightning(password=self.password)
|
||||||
self.show_info(_('Lightning keys have been initialized.'))
|
self.show_info(_('Lightning keys have been initialized.'))
|
||||||
self.stop_wallet()
|
|
||||||
self.load_wallet_by_name(wallet_path)
|
|
||||||
|
|||||||
@@ -71,9 +71,14 @@ class ChannelsList(MyTreeView):
|
|||||||
self.update_rows.connect(self.do_update_rows)
|
self.update_rows.connect(self.do_update_rows)
|
||||||
self.update_single_row.connect(self.do_update_single_row)
|
self.update_single_row.connect(self.do_update_single_row)
|
||||||
self.network = self.parent.network
|
self.network = self.parent.network
|
||||||
self.lnworker = self.parent.wallet.lnworker
|
self.wallet = self.parent.wallet
|
||||||
self.setSortingEnabled(True)
|
self.setSortingEnabled(True)
|
||||||
|
|
||||||
|
@property
|
||||||
|
# property because lnworker might be initialized at runtime
|
||||||
|
def lnworker(self):
|
||||||
|
return self.wallet.lnworker
|
||||||
|
|
||||||
def format_fields(self, chan: AbstractChannel) -> Dict['ChannelsList.Columns', str]:
|
def format_fields(self, chan: AbstractChannel) -> Dict['ChannelsList.Columns', str]:
|
||||||
labels = {}
|
labels = {}
|
||||||
for subject in (REMOTE, LOCAL):
|
for subject in (REMOTE, LOCAL):
|
||||||
|
|||||||
@@ -2245,11 +2245,9 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
|||||||
sb.addPermanentWidget(StatusBarButton(read_QIcon("preferences.png"), _("Preferences"), self.settings_dialog))
|
sb.addPermanentWidget(StatusBarButton(read_QIcon("preferences.png"), _("Preferences"), self.settings_dialog))
|
||||||
self.seed_button = StatusBarButton(read_QIcon("seed.png"), _("Seed"), self.show_seed_dialog)
|
self.seed_button = StatusBarButton(read_QIcon("seed.png"), _("Seed"), self.show_seed_dialog)
|
||||||
sb.addPermanentWidget(self.seed_button)
|
sb.addPermanentWidget(self.seed_button)
|
||||||
self.lightning_button = None
|
self.lightning_button = StatusBarButton(read_QIcon("lightning.png"), _("Lightning Network"), self.gui_object.show_lightning_dialog)
|
||||||
if self.wallet.has_lightning():
|
self.update_lightning_icon()
|
||||||
self.lightning_button = StatusBarButton(read_QIcon("lightning.png"), _("Lightning Network"), self.gui_object.show_lightning_dialog)
|
sb.addPermanentWidget(self.lightning_button)
|
||||||
self.update_lightning_icon()
|
|
||||||
sb.addPermanentWidget(self.lightning_button)
|
|
||||||
self.status_button = None
|
self.status_button = None
|
||||||
if self.network:
|
if self.network:
|
||||||
self.status_button = StatusBarButton(read_QIcon("status_disconnected.png"), _("Network"), self.gui_object.show_network_dialog)
|
self.status_button = StatusBarButton(read_QIcon("status_disconnected.png"), _("Network"), self.gui_object.show_network_dialog)
|
||||||
@@ -2285,12 +2283,12 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
|||||||
self.coincontrol_sb.setVisible(True)
|
self.coincontrol_sb.setVisible(True)
|
||||||
|
|
||||||
def update_lightning_icon(self):
|
def update_lightning_icon(self):
|
||||||
if self.lightning_button is None:
|
if not self.wallet.has_lightning():
|
||||||
|
self.lightning_button.setVisible(False)
|
||||||
return
|
return
|
||||||
if self.network is None or self.network.channel_db is None:
|
if self.network is None or self.network.channel_db is None:
|
||||||
self.lightning_button.setVisible(False)
|
self.lightning_button.setVisible(False)
|
||||||
return
|
return
|
||||||
|
|
||||||
self.lightning_button.setVisible(True)
|
self.lightning_button.setVisible(True)
|
||||||
|
|
||||||
cur, total, progress_percent = self.network.lngossip.get_sync_progress_estimate()
|
cur, total, progress_percent = self.network.lngossip.get_sync_progress_estimate()
|
||||||
@@ -2385,7 +2383,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
|||||||
if d.exec_():
|
if d.exec_():
|
||||||
self.set_contact(line2.text(), line1.text())
|
self.set_contact(line2.text(), line1.text())
|
||||||
|
|
||||||
def init_lightning_dialog(self):
|
def init_lightning_dialog(self, dialog):
|
||||||
assert not self.wallet.has_lightning()
|
assert not self.wallet.has_lightning()
|
||||||
if self.wallet.can_have_deterministic_lightning():
|
if self.wallet.can_have_deterministic_lightning():
|
||||||
msg = messages.MSG_LIGHTNING_SCB_WARNING + "\n" + _("Create lightning keys?")
|
msg = messages.MSG_LIGHTNING_SCB_WARNING + "\n" + _("Create lightning keys?")
|
||||||
@@ -2395,12 +2393,14 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
|||||||
"You will need to backup your wallet everytime you create a new wallet. "
|
"You will need to backup your wallet everytime you create a new wallet. "
|
||||||
"Create lightning keys?")
|
"Create lightning keys?")
|
||||||
if self.question(msg):
|
if self.question(msg):
|
||||||
self._init_lightning_dialog()
|
self._init_lightning_dialog(dialog=dialog)
|
||||||
|
|
||||||
@protected
|
@protected
|
||||||
def _init_lightning_dialog(self, *, password):
|
def _init_lightning_dialog(self, *, dialog, password):
|
||||||
|
dialog.close()
|
||||||
self.wallet.init_lightning(password=password)
|
self.wallet.init_lightning(password=password)
|
||||||
self.show_message("Lightning keys created. Please restart Electrum")
|
self.update_lightning_icon()
|
||||||
|
self.show_message(_('Lightning keys have been initialized.'))
|
||||||
|
|
||||||
def show_wallet_info(self):
|
def show_wallet_info(self):
|
||||||
dialog = WindowModalDialog(self, _("Wallet Information"))
|
dialog = WindowModalDialog(self, _("Wallet Information"))
|
||||||
@@ -2463,7 +2463,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
|||||||
if self.wallet.can_have_lightning():
|
if self.wallet.can_have_lightning():
|
||||||
grid.addWidget(QLabel('Not enabled'), 5, 1)
|
grid.addWidget(QLabel('Not enabled'), 5, 1)
|
||||||
button = QPushButton(_("Enable"))
|
button = QPushButton(_("Enable"))
|
||||||
button.pressed.connect(self.init_lightning_dialog)
|
button.pressed.connect(lambda: self.init_lightning_dialog(dialog))
|
||||||
grid.addWidget(button, 5, 3)
|
grid.addWidget(button, 5, 3)
|
||||||
else:
|
else:
|
||||||
grid.addWidget(QLabel(_("Not available for this wallet.")), 5, 1)
|
grid.addWidget(QLabel(_("Not available for this wallet.")), 5, 1)
|
||||||
|
|||||||
@@ -351,16 +351,20 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
|
|||||||
assert self.can_have_lightning()
|
assert self.can_have_lightning()
|
||||||
assert self.db.get('lightning_xprv') is None
|
assert self.db.get('lightning_xprv') is None
|
||||||
assert self.db.get('lightning_privkey2') is None
|
assert self.db.get('lightning_privkey2') is None
|
||||||
|
|
||||||
if self.can_have_deterministic_lightning():
|
if self.can_have_deterministic_lightning():
|
||||||
ks = self.keystore
|
assert isinstance(self.keystore, keystore.BIP32_KeyStore)
|
||||||
assert isinstance(ks, keystore.BIP32_KeyStore)
|
ln_xprv = self.keystore.get_lightning_xprv(password)
|
||||||
self.db.put('lightning_xprv', ks.get_lightning_xprv(password))
|
self.db.put('lightning_xprv', ln_xprv)
|
||||||
else:
|
else:
|
||||||
seed = os.urandom(32)
|
seed = os.urandom(32)
|
||||||
node = BIP32Node.from_rootseed(seed, xtype='standard')
|
node = BIP32Node.from_rootseed(seed, xtype='standard')
|
||||||
ln_xprv = node.to_xprv()
|
ln_xprv = node.to_xprv()
|
||||||
self.db.put('lightning_privkey2', ln_xprv)
|
self.db.put('lightning_privkey2', ln_xprv)
|
||||||
|
if self.network:
|
||||||
|
self.network.run_from_another_thread(self.stop())
|
||||||
|
self.lnworker = LNWallet(self, ln_xprv)
|
||||||
|
if self.network:
|
||||||
|
self.start_network(self.network)
|
||||||
|
|
||||||
async def stop(self):
|
async def stop(self):
|
||||||
"""Stop all networking and save DB to disk."""
|
"""Stop all networking and save DB to disk."""
|
||||||
|
|||||||
Reference in New Issue
Block a user