electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 842fff832fd5e51bd7793a69f86063ed67e58d35
parent 9a3a63d18e5782e4fad5253c5e76bac3d8ca80a4
Author: ThomasV <thomasv@electrum.org>
Date:   Fri,  3 May 2019 16:42:52 +0200

enable lightning through command line option

Diffstat:
Melectrum/commands.py | 3++-
Melectrum/daemon.py | 2--
Melectrum/gui/qt/channels_list.py | 5++++-
Melectrum/gui/qt/history_list.py | 11+++++++----
Melectrum/gui/qt/invoice_list.py | 3++-
Melectrum/gui/qt/main_window.py | 22+++++++++++++---------
Melectrum/gui/qt/request_list.py | 3++-
Melectrum/gui/qt/watchtower_window.py | 2++
Melectrum/network.py | 15+++++++++++----
Melectrum/tests/regtest/regtest.sh | 6+++---
Melectrum/wallet.py | 7++++---
Mrun_electrum | 2+-
12 files changed, 51 insertions(+), 30 deletions(-)

diff --git a/electrum/commands.py b/electrum/commands.py @@ -1026,7 +1026,8 @@ def add_global_options(parser): group.add_argument("--testnet", action="store_true", dest="testnet", default=False, help="Use Testnet") group.add_argument("--regtest", action="store_true", dest="regtest", default=False, help="Use Regtest") group.add_argument("--simnet", action="store_true", dest="simnet", default=False, help="Use Simnet") - group.add_argument("--reckless", action="store_true", dest="reckless", default=False, help="Play with real money") + group.add_argument("--lightning", action="store_true", dest="lightning", default=False, help="Enable lightning") + group.add_argument("--reckless", action="store_true", dest="reckless", default=False, help="Allow to enable lightning on mainnet") def get_parser(): # create main parser diff --git a/electrum/daemon.py b/electrum/daemon.py @@ -166,11 +166,9 @@ class Daemon(DaemonThread): self.init_server(config, fd) # server-side watchtower self.watchtower = WatchTower(self.config, self.network.lnwatcher) if self.config.get('watchtower_host') else None - # client-side if self.network: self.network.start([ self.fx.run, - self.network.lnwatcher.watchtower_task, ]) self.start() diff --git a/electrum/gui/qt/channels_list.py b/electrum/gui/qt/channels_list.py @@ -104,8 +104,11 @@ class ChannelsList(MyTreeView): return h def update_status(self): + network = self.parent.network + if network.lngossip is None: + return channel_db = self.parent.network.channel_db - num_peers = sum([p.initialized.is_set() for p in self.parent.wallet.lnworker.peers.values()]) + num_peers = sum([p.initialized.is_set() for p in network.lngossip.peers.values()]) msg = _('{} peers, {} nodes, {} channels.').format(num_peers, channel_db.num_nodes, channel_db.num_channels) self.status.setText(msg) diff --git a/electrum/gui/qt/history_list.py b/electrum/gui/qt/history_list.py @@ -272,8 +272,9 @@ class HistoryModel(QAbstractItemModel, Logger): selected_row = selected.row() fx = self.parent.fx if fx: fx.history_used_spot = False - r = self.parent.wallet.get_full_history(domain=self.get_domain(), from_timestamp=None, to_timestamp=None, fx=fx) - lightning_history = self.parent.wallet.lnworker.get_history() + wallet = self.parent.wallet + r = wallet.get_full_history(domain=self.get_domain(), from_timestamp=None, to_timestamp=None, fx=fx) + lightning_history = wallet.lnworker.get_history() if wallet.lnworker else [] self.set_visibility_of_columns() #if r['transactions'] == list(self.transactions.values()): # return @@ -433,12 +434,14 @@ class HistoryList(MyTreeView, AcceptFileDragDrop): def __init__(self, parent, model: HistoryModel): super().__init__(parent, self.create_menu, stretch_column=HistoryColumns.DESCRIPTION) + self.config = parent.config self.hm = model self.proxy = HistorySortModel(self) self.proxy.setSourceModel(model) self.setModel(self.proxy) - - self.config = parent.config + if not self.config.get('lightning'): + self.setColumnHidden(HistoryColumns.LN_BALANCE, True) + self.setColumnHidden(HistoryColumns.LN_AMOUNT, True) AcceptFileDragDrop.__init__(self, ".txn") self.setSortingEnabled(True) self.start_timestamp = None diff --git a/electrum/gui/qt/invoice_list.py b/electrum/gui/qt/invoice_list.py @@ -92,7 +92,8 @@ class InvoiceList(MyTreeView): self.model().insertRow(idx, items) lnworker = self.parent.wallet.lnworker - for key, (invoice, direction, is_paid) in lnworker.invoices.items(): + items = lnworker.invoices.items() if lnworker else [] + for key, (invoice, direction, is_paid) in items: if direction == RECEIVED: continue status = lnworker.get_invoice_status(key) diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py @@ -431,7 +431,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): def load_wallet(self, wallet): wallet.thread = TaskThread(self, self.on_error) self.update_recently_visited(wallet.storage.path) - wallet.lnworker.on_channels_updated() + if wallet.lnworker: + wallet.lnworker.on_channels_updated() self.need_update.set() # Once GUI has been initialized check if we want to announce something since the callback has been called before the GUI was initialized # update menus @@ -626,7 +627,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): view_menu = menubar.addMenu(_("&View")) add_toggle_action(view_menu, self.addresses_tab) add_toggle_action(view_menu, self.utxo_tab) - add_toggle_action(view_menu, self.channels_tab) + if self.config.get('lightning'): + add_toggle_action(view_menu, self.channels_tab) add_toggle_action(view_menu, self.contacts_tab) add_toggle_action(view_menu, self.console_tab) @@ -635,7 +637,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): # Settings / Preferences are all reserved keywords in macOS using this as work around tools_menu.addAction(_("Electrum preferences") if sys.platform == 'darwin' else _("Preferences"), self.settings_dialog) tools_menu.addAction(_("&Network"), lambda: self.gui_object.show_network_dialog(self)) - tools_menu.addAction(_("&Watchtower"), lambda: self.gui_object.show_watchtower_dialog(self)) + if self.config.get('lightning'): + tools_menu.addAction(_("&Watchtower"), lambda: self.gui_object.show_watchtower_dialog(self)) tools_menu.addAction(_("&Plugins"), self.plugins_dialog) tools_menu.addSeparator() tools_menu.addAction(_("&Sign/verify message"), self.sign_verify_message) @@ -858,8 +861,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): text += " [%s unconfirmed]"%(self.format_amount(u, is_diff=True).strip()) if x: text += " [%s unmatured]"%(self.format_amount(x, is_diff=True).strip()) - l = self.wallet.lnworker.get_balance() - if l: + if self.wallet.lnworker: + l = self.wallet.lnworker.get_balance() text += u' \U0001f5f2 %s'%(self.format_amount_and_units(l).strip()) # append fiat balance and price @@ -967,13 +970,14 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): self.create_invoice_button = QPushButton(_('On-chain')) self.create_invoice_button.setIcon(read_QIcon("bitcoin.png")) self.create_invoice_button.clicked.connect(lambda: self.create_invoice(False)) - self.create_lightning_invoice_button = QPushButton(_('Lightning')) - self.create_lightning_invoice_button.setIcon(read_QIcon("lightning.png")) - self.create_lightning_invoice_button.clicked.connect(lambda: self.create_invoice(True)) self.receive_buttons = buttons = QHBoxLayout() buttons.addStretch(1) buttons.addWidget(self.create_invoice_button) - buttons.addWidget(self.create_lightning_invoice_button) + if self.config.get('lightning'): + self.create_lightning_invoice_button = QPushButton(_('Lightning')) + self.create_lightning_invoice_button.setIcon(read_QIcon("lightning.png")) + self.create_lightning_invoice_button.clicked.connect(lambda: self.create_invoice(True)) + buttons.addWidget(self.create_lightning_invoice_button) grid.addLayout(buttons, 4, 3, 1, 2) self.receive_address_e = ButtonsTextEdit() diff --git a/electrum/gui/qt/request_list.py b/electrum/gui/qt/request_list.py @@ -136,7 +136,8 @@ class RequestList(MyTreeView): self.filter() # lightning lnworker = self.wallet.lnworker - for key, (invoice, direction, is_paid) in lnworker.invoices.items(): + items = lnworker.invoices.items() if lnworker else [] + for key, (invoice, direction, is_paid) in items: if direction == SENT: continue status = lnworker.get_invoice_status(key) diff --git a/electrum/gui/qt/watchtower_window.py b/electrum/gui/qt/watchtower_window.py @@ -50,6 +50,8 @@ class WatcherList(MyTreeView): pass def update(self): + if self.parent.lnwatcher is None: + return self.model().clear() self.update_headers({0:_('Outpoint'), 1:_('Tx'), 2:_('Status')}) sweepstore = self.parent.lnwatcher.sweepstore diff --git a/electrum/network.py b/electrum/network.py @@ -302,8 +302,12 @@ class Network(Logger): from . import lnrouter self.channel_db = lnrouter.ChannelDB(self) self.path_finder = lnrouter.LNPathFinder(self.channel_db) - self.lnwatcher = lnwatcher.LNWatcher(self) - self.lngossip = lnworker.LNGossip(self) + if self.config.get('lightning'): + self.lnwatcher = lnwatcher.LNWatcher(self) + self.lngossip = lnworker.LNGossip(self) + else: + self.lnwatcher = None + self.lngossip = None def run_from_another_thread(self, coro): assert self._loop_thread != threading.current_thread(), 'must not be called from network thread' @@ -1146,6 +1150,11 @@ class Network(Logger): self._set_oneserver(self.config.get('oneserver', False)) self._start_interface(self.default_server) + if self.lnwatcher: + self._jobs.append(self.lnwatcher.watchtower_task) + if self.lngossip: + self.lngossip.start_network(self) + async def main(): try: await self._init_headers_file() @@ -1160,8 +1169,6 @@ class Network(Logger): asyncio.run_coroutine_threadsafe(main(), self.asyncio_loop) self.trigger_callback('network_updated') - # - self.lngossip.start_network(self) def start(self, jobs: List=None): self._jobs = jobs or [] diff --git a/electrum/tests/regtest/regtest.sh b/electrum/tests/regtest/regtest.sh @@ -4,9 +4,9 @@ set -eu # alice -> bob -> carol -alice="./run_electrum --regtest -D /tmp/alice" -bob="./run_electrum --regtest -D /tmp/bob" -carol="./run_electrum --regtest -D /tmp/carol" +alice="./run_electrum --regtest --lightning -D /tmp/alice" +bob="./run_electrum --regtest --lightning -D /tmp/bob" +carol="./run_electrum --regtest --lightning -D /tmp/carol" if [[ $# -eq 0 ]]; then echo "syntax: init|start|open|status|pay|close|stop" diff --git a/electrum/wallet.py b/electrum/wallet.py @@ -229,8 +229,7 @@ class Abstract_Wallet(AddressSynchronizer): if self.storage.get('wallet_type') is None: self.storage.put('wallet_type', self.wallet_type) - # lightning - self.lnworker = LNWallet(self) + self.lnworker = None # invoices and contacts self.invoices = InvoiceStore(self.storage) self.contacts = Contacts(self.storage) @@ -250,7 +249,9 @@ class Abstract_Wallet(AddressSynchronizer): def start_network(self, network): AddressSynchronizer.start_network(self, network) - self.lnworker.start_network(network) + if network.config.get('lightning'): + self.lnworker = LNWallet(self) + self.lnworker.start_network(network) def load_and_cleanup(self): self.load_keystore() diff --git a/run_electrum b/run_electrum @@ -352,7 +352,7 @@ if __name__ == '__main__': constants.set_regtest() elif config.get('simnet'): constants.set_simnet() - elif not config.get('reckless'): + elif config.get('lightning') and not config.get('reckless'): raise Exception('lightning branch not available on mainnet') if cmdname == 'gui':