electrum

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

commit 9f8e2c689e0cc5b5144eda383d0c33dd2f85e1f1
parent bbec1dceda76201763d4bfdc33e01db3002f06da
Author: ThomasV <thomasv@electrum.org>
Date:   Mon, 12 Aug 2019 17:54:27 +0200

test funding_txn_minimum_depth, show it in GUI

Diffstat:
Melectrum/commands.py | 3++-
Melectrum/gui/kivy/uix/dialogs/lightning_open_channel.py | 10++++++++--
Melectrum/gui/qt/main_window.py | 12+++++++-----
Melectrum/lnpeer.py | 5++++-
Melectrum/lnworker.py | 2+-
5 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/electrum/commands.py b/electrum/commands.py @@ -782,7 +782,8 @@ class Commands: @command('wpn') def open_channel(self, connection_string, amount, channel_push=0, password=None): - return self.lnworker.open_channel(connection_string, satoshis(amount), satoshis(channel_push), password) + chan = self.lnworker.open_channel(connection_string, satoshis(amount), satoshis(channel_push), password) + return chan.funding_outpoint.to_str() @command('wn') def lnpay(self, invoice, attempts=1, timeout=10): diff --git a/electrum/gui/kivy/uix/dialogs/lightning_open_channel.py b/electrum/gui/kivy/uix/dialogs/lightning_open_channel.py @@ -136,8 +136,14 @@ class LightningOpenChannelDialog(Factory.Popup): def do_open_channel(self, conn_str, amount, password): try: - node_id_hex = self.app.wallet.lnworker.open_channel(conn_str, amount, 0, password=password) + chan = self.app.wallet.lnworker.open_channel(conn_str, amount, 0, password=password) except Exception as e: self.app.show_error(_('Problem opening channel: ') + '\n' + repr(e)) return - self.app.show_info(_('Please wait for confirmation, channel is opening with node ') + node_id_hex[:16]) + n = chan.constraints.funding_txn_minimum_depth + message = '\n'.join([ + _('Channel established.'), + _('Remote peer ID') + ':' + chan.node_id.hex(), + _('This channel will be usable after {} confirmations').format(n) + ]) + self.app.show_info(message) diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py @@ -1839,12 +1839,14 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): def open_channel(self, *args, **kwargs): def task(): return self.wallet.lnworker.open_channel(*args, **kwargs) - def on_success(node_id): - self.show_message('\n'.join([ + def on_success(chan): + n = chan.constraints.funding_txn_minimum_depth + message = '\n'.join([ _('Channel established.'), - _('Remote peer ID') + ':' + node_id, - _('This channel will be usable after 3 confirmations') - ])) + _('Remote peer ID') + ':' + chan.node_id.hex(), + _('This channel will be usable after {} confirmations').format(n) + ]) + self.show_message(message) def on_failure(exc_info): type_, e, traceback = exc_info self.show_error(_('Could not open channel: {}').format(e)) diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py @@ -498,7 +498,10 @@ class Peer(Logger): raise Exception('Remote Lightning peer reported error: ' + repr(payload.get('error'))) remote_per_commitment_point = payload['first_per_commitment_point'] funding_txn_minimum_depth = int.from_bytes(payload['minimum_depth'], 'big') - assert funding_txn_minimum_depth > 0, funding_txn_minimum_depth + if funding_txn_minimum_depth <= 0: + raise Exception(f"minimum depth too low, {funding_txn_minimum_depth}") + if funding_txn_minimum_depth > 30: + raise Exception(f"minimum depth too high, {funding_txn_minimum_depth}") remote_dust_limit_sat = int.from_bytes(payload['dust_limit_satoshis'], byteorder='big') remote_reserve_sat = self.validate_remote_reserve(payload["channel_reserve_satoshis"], remote_dust_limit_sat, funding_sat) if remote_dust_limit_sat > remote_reserve_sat: diff --git a/electrum/lnworker.py b/electrum/lnworker.py @@ -717,7 +717,7 @@ class LNWallet(LNWorker): chan = fut.result(timeout=timeout) except concurrent.futures.TimeoutError: raise Exception(_("open_channel timed out")) - return chan.funding_outpoint.to_str() + return chan def pay(self, invoice, attempts=1, amount_sat=None, timeout=10): """