Browse Source

enable lightning through command line option

dependabot/pip/contrib/deterministic-build/ecdsa-0.13.3
ThomasV 6 years ago
parent
commit
842fff832f
  1. 3
      electrum/commands.py
  2. 2
      electrum/daemon.py
  3. 5
      electrum/gui/qt/channels_list.py
  4. 11
      electrum/gui/qt/history_list.py
  5. 3
      electrum/gui/qt/invoice_list.py
  6. 22
      electrum/gui/qt/main_window.py
  7. 3
      electrum/gui/qt/request_list.py
  8. 2
      electrum/gui/qt/watchtower_window.py
  9. 15
      electrum/network.py
  10. 6
      electrum/tests/regtest/regtest.sh
  11. 7
      electrum/wallet.py
  12. 2
      run_electrum

3
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("--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("--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("--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(): def get_parser():
# create main parser # create main parser

2
electrum/daemon.py

@ -166,11 +166,9 @@ class Daemon(DaemonThread):
self.init_server(config, fd) self.init_server(config, fd)
# server-side watchtower # server-side watchtower
self.watchtower = WatchTower(self.config, self.network.lnwatcher) if self.config.get('watchtower_host') else None self.watchtower = WatchTower(self.config, self.network.lnwatcher) if self.config.get('watchtower_host') else None
# client-side
if self.network: if self.network:
self.network.start([ self.network.start([
self.fx.run, self.fx.run,
self.network.lnwatcher.watchtower_task,
]) ])
self.start() self.start()

5
electrum/gui/qt/channels_list.py

@ -104,8 +104,11 @@ class ChannelsList(MyTreeView):
return h return h
def update_status(self): def update_status(self):
network = self.parent.network
if network.lngossip is None:
return
channel_db = self.parent.network.channel_db 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) msg = _('{} peers, {} nodes, {} channels.').format(num_peers, channel_db.num_nodes, channel_db.num_channels)
self.status.setText(msg) self.status.setText(msg)

11
electrum/gui/qt/history_list.py

@ -272,8 +272,9 @@ class HistoryModel(QAbstractItemModel, Logger):
selected_row = selected.row() selected_row = selected.row()
fx = self.parent.fx fx = self.parent.fx
if fx: fx.history_used_spot = False 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) wallet = self.parent.wallet
lightning_history = self.parent.wallet.lnworker.get_history() 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() self.set_visibility_of_columns()
#if r['transactions'] == list(self.transactions.values()): #if r['transactions'] == list(self.transactions.values()):
# return # return
@ -433,12 +434,14 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
def __init__(self, parent, model: HistoryModel): def __init__(self, parent, model: HistoryModel):
super().__init__(parent, self.create_menu, stretch_column=HistoryColumns.DESCRIPTION) super().__init__(parent, self.create_menu, stretch_column=HistoryColumns.DESCRIPTION)
self.config = parent.config
self.hm = model self.hm = model
self.proxy = HistorySortModel(self) self.proxy = HistorySortModel(self)
self.proxy.setSourceModel(model) self.proxy.setSourceModel(model)
self.setModel(self.proxy) self.setModel(self.proxy)
if not self.config.get('lightning'):
self.config = parent.config self.setColumnHidden(HistoryColumns.LN_BALANCE, True)
self.setColumnHidden(HistoryColumns.LN_AMOUNT, True)
AcceptFileDragDrop.__init__(self, ".txn") AcceptFileDragDrop.__init__(self, ".txn")
self.setSortingEnabled(True) self.setSortingEnabled(True)
self.start_timestamp = None self.start_timestamp = None

3
electrum/gui/qt/invoice_list.py

@ -92,7 +92,8 @@ class InvoiceList(MyTreeView):
self.model().insertRow(idx, items) self.model().insertRow(idx, items)
lnworker = self.parent.wallet.lnworker 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: if direction == RECEIVED:
continue continue
status = lnworker.get_invoice_status(key) status = lnworker.get_invoice_status(key)

22
electrum/gui/qt/main_window.py

@ -431,7 +431,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
def load_wallet(self, wallet): def load_wallet(self, wallet):
wallet.thread = TaskThread(self, self.on_error) wallet.thread = TaskThread(self, self.on_error)
self.update_recently_visited(wallet.storage.path) self.update_recently_visited(wallet.storage.path)
wallet.lnworker.on_channels_updated() if wallet.lnworker:
wallet.lnworker.on_channels_updated()
self.need_update.set() 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 # 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 # update menus
@ -626,7 +627,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
view_menu = menubar.addMenu(_("&View")) view_menu = menubar.addMenu(_("&View"))
add_toggle_action(view_menu, self.addresses_tab) add_toggle_action(view_menu, self.addresses_tab)
add_toggle_action(view_menu, self.utxo_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.contacts_tab)
add_toggle_action(view_menu, self.console_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 # 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(_("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(_("&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.addAction(_("&Plugins"), self.plugins_dialog)
tools_menu.addSeparator() tools_menu.addSeparator()
tools_menu.addAction(_("&Sign/verify message"), self.sign_verify_message) 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()) text += " [%s unconfirmed]"%(self.format_amount(u, is_diff=True).strip())
if x: if x:
text += " [%s unmatured]"%(self.format_amount(x, is_diff=True).strip()) text += " [%s unmatured]"%(self.format_amount(x, is_diff=True).strip())
l = self.wallet.lnworker.get_balance() if self.wallet.lnworker:
if l: l = self.wallet.lnworker.get_balance()
text += u' \U0001f5f2 %s'%(self.format_amount_and_units(l).strip()) text += u' \U0001f5f2 %s'%(self.format_amount_and_units(l).strip())
# append fiat balance and price # 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 = QPushButton(_('On-chain'))
self.create_invoice_button.setIcon(read_QIcon("bitcoin.png")) self.create_invoice_button.setIcon(read_QIcon("bitcoin.png"))
self.create_invoice_button.clicked.connect(lambda: self.create_invoice(False)) 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() self.receive_buttons = buttons = QHBoxLayout()
buttons.addStretch(1) buttons.addStretch(1)
buttons.addWidget(self.create_invoice_button) 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) grid.addLayout(buttons, 4, 3, 1, 2)
self.receive_address_e = ButtonsTextEdit() self.receive_address_e = ButtonsTextEdit()

3
electrum/gui/qt/request_list.py

@ -136,7 +136,8 @@ class RequestList(MyTreeView):
self.filter() self.filter()
# lightning # lightning
lnworker = self.wallet.lnworker 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: if direction == SENT:
continue continue
status = lnworker.get_invoice_status(key) status = lnworker.get_invoice_status(key)

2
electrum/gui/qt/watchtower_window.py

@ -50,6 +50,8 @@ class WatcherList(MyTreeView):
pass pass
def update(self): def update(self):
if self.parent.lnwatcher is None:
return
self.model().clear() self.model().clear()
self.update_headers({0:_('Outpoint'), 1:_('Tx'), 2:_('Status')}) self.update_headers({0:_('Outpoint'), 1:_('Tx'), 2:_('Status')})
sweepstore = self.parent.lnwatcher.sweepstore sweepstore = self.parent.lnwatcher.sweepstore

15
electrum/network.py

@ -302,8 +302,12 @@ class Network(Logger):
from . import lnrouter from . import lnrouter
self.channel_db = lnrouter.ChannelDB(self) self.channel_db = lnrouter.ChannelDB(self)
self.path_finder = lnrouter.LNPathFinder(self.channel_db) self.path_finder = lnrouter.LNPathFinder(self.channel_db)
self.lnwatcher = lnwatcher.LNWatcher(self) if self.config.get('lightning'):
self.lngossip = lnworker.LNGossip(self) self.lnwatcher = lnwatcher.LNWatcher(self)
self.lngossip = lnworker.LNGossip(self)
else:
self.lnwatcher = None
self.lngossip = None
def run_from_another_thread(self, coro): def run_from_another_thread(self, coro):
assert self._loop_thread != threading.current_thread(), 'must not be called from network thread' 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._set_oneserver(self.config.get('oneserver', False))
self._start_interface(self.default_server) 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(): async def main():
try: try:
await self._init_headers_file() await self._init_headers_file()
@ -1160,8 +1169,6 @@ class Network(Logger):
asyncio.run_coroutine_threadsafe(main(), self.asyncio_loop) asyncio.run_coroutine_threadsafe(main(), self.asyncio_loop)
self.trigger_callback('network_updated') self.trigger_callback('network_updated')
#
self.lngossip.start_network(self)
def start(self, jobs: List=None): def start(self, jobs: List=None):
self._jobs = jobs or [] self._jobs = jobs or []

6
electrum/tests/regtest/regtest.sh

@ -4,9 +4,9 @@ set -eu
# alice -> bob -> carol # alice -> bob -> carol
alice="./run_electrum --regtest -D /tmp/alice" alice="./run_electrum --regtest --lightning -D /tmp/alice"
bob="./run_electrum --regtest -D /tmp/bob" bob="./run_electrum --regtest --lightning -D /tmp/bob"
carol="./run_electrum --regtest -D /tmp/carol" carol="./run_electrum --regtest --lightning -D /tmp/carol"
if [[ $# -eq 0 ]]; then if [[ $# -eq 0 ]]; then
echo "syntax: init|start|open|status|pay|close|stop" echo "syntax: init|start|open|status|pay|close|stop"

7
electrum/wallet.py

@ -229,8 +229,7 @@ class Abstract_Wallet(AddressSynchronizer):
if self.storage.get('wallet_type') is None: if self.storage.get('wallet_type') is None:
self.storage.put('wallet_type', self.wallet_type) self.storage.put('wallet_type', self.wallet_type)
# lightning self.lnworker = None
self.lnworker = LNWallet(self)
# invoices and contacts # invoices and contacts
self.invoices = InvoiceStore(self.storage) self.invoices = InvoiceStore(self.storage)
self.contacts = Contacts(self.storage) self.contacts = Contacts(self.storage)
@ -250,7 +249,9 @@ class Abstract_Wallet(AddressSynchronizer):
def start_network(self, network): def start_network(self, network):
AddressSynchronizer.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): def load_and_cleanup(self):
self.load_keystore() self.load_keystore()

2
run_electrum

@ -352,7 +352,7 @@ if __name__ == '__main__':
constants.set_regtest() constants.set_regtest()
elif config.get('simnet'): elif config.get('simnet'):
constants.set_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') raise Exception('lightning branch not available on mainnet')
if cmdname == 'gui': if cmdname == 'gui':

Loading…
Cancel
Save