electrum

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

commit 557987d4ebfca40902e741254734f13e9150f1d9
parent 038036f350349812c2affa8a7a77188fd2dc5b3a
Author: SomberNight <somber.night@protonmail.com>
Date:   Sat, 23 Nov 2019 20:28:46 +0100

add/fix some open_channel related type hints

Diffstat:
Melectrum/address_synchronizer.py | 3++-
Melectrum/commands.py | 6+++++-
Melectrum/gui/kivy/uix/dialogs/lightning_open_channel.py | 15+++++++++++++--
Melectrum/gui/qt/main_window.py | 6+++++-
Melectrum/lnpeer.py | 3++-
Melectrum/lnworker.py | 13+++++++++----
6 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/electrum/address_synchronizer.py b/electrum/address_synchronizer.py @@ -212,7 +212,8 @@ class AddressSynchronizer(Logger): assert tx, tx assert tx.is_complete() tx_hash = tx.txid() - # assert tx_hash == tx.txid() # disabled as expensive; test done by Synchronizer. + if tx_hash is None: + raise Exception("cannot add tx without txid to wallet history") # we need self.transaction_lock but get_tx_height will take self.lock # so we need to take that too here, to enforce order of locks with self.lock, self.transaction_lock: diff --git a/electrum/commands.py b/electrum/commands.py @@ -929,7 +929,11 @@ class Commands: push_sat = satoshis(push_amount) dummy_output = PartialTxOutput.from_address_and_value(ln_dummy_address(), funding_sat) funding_tx = wallet.mktx(outputs = [dummy_output], rbf=False, sign=False, nonlocal_only=True) - chan, funding_tx = await wallet.lnworker._open_channel_coroutine(connection_string, funding_tx, funding_sat, push_sat, password) + chan, funding_tx = await wallet.lnworker._open_channel_coroutine(connect_str=connection_string, + funding_tx=funding_tx, + funding_sat=funding_sat, + push_sat=push_sat, + password=password) return chan.funding_outpoint.to_str() @command('wn') diff --git a/electrum/gui/kivy/uix/dialogs/lightning_open_channel.py b/electrum/gui/kivy/uix/dialogs/lightning_open_channel.py @@ -1,12 +1,20 @@ +from typing import TYPE_CHECKING + from kivy.lang import Builder from kivy.factory import Factory + from electrum.gui.kivy.i18n import _ from electrum.lnaddr import lndecode from electrum.util import bh2u from electrum.bitcoin import COIN import electrum.simple_config as config + from .label_dialog import LabelDialog +if TYPE_CHECKING: + from ...main_window import ElectrumWindow + + Builder.load_string(''' <LightningOpenChannelDialog@Popup> id: s @@ -100,7 +108,7 @@ class LightningOpenChannelDialog(Factory.Popup): def __init__(self, app, lnaddr=None, msg=None): super(LightningOpenChannelDialog, self).__init__() - self.app = app + self.app = app # type: ElectrumWindow self.lnaddr = lnaddr self.msg = msg @@ -138,7 +146,10 @@ class LightningOpenChannelDialog(Factory.Popup): def do_open_channel(self, conn_str, amount, password): try: - chan, funding_tx = self.app.wallet.lnworker.open_channel(conn_str, amount, 0, password=password) + chan, funding_tx = self.app.wallet.lnworker.open_channel(connect_str=conn_str, + funding_sat=amount, + push_amt_sat=0, + password=password) except Exception as e: self.app.show_error(_('Problem opening channel: ') + '\n' + repr(e)) return diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py @@ -1635,7 +1635,11 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): # read funding_sat from tx; converts '!' to int value funding_sat = funding_tx.output_value_for_address(ln_dummy_address()) def task(): - return self.wallet.lnworker.open_channel(connect_str, funding_tx, funding_sat, push_amt, password) + return self.wallet.lnworker.open_channel(connect_str=connect_str, + funding_tx=funding_tx, + funding_sat=funding_sat, + push_amt_sat=push_amt, + password=password) def on_success(args): chan, funding_tx = args n = chan.constraints.funding_txn_minimum_depth diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py @@ -491,7 +491,7 @@ class Peer(Logger): @log_exceptions async def channel_establishment_flow(self, password: Optional[str], funding_tx: 'PartialTransaction', funding_sat: int, - push_msat: int, temp_channel_id: bytes) -> Channel: + push_msat: int, temp_channel_id: bytes) -> Tuple[Channel, 'PartialTransaction']: await asyncio.wait_for(self.initialized.wait(), LN_P2P_NETWORK_TIMEOUT) feerate = self.lnworker.current_feerate_per_kw() local_config = self.make_local_config(funding_sat, push_msat, LOCAL) @@ -578,6 +578,7 @@ class Peer(Logger): if not funding_tx.is_complete() and not funding_tx.is_segwit(): raise Exception('Funding transaction is not complete') funding_txid = funding_tx.txid() + assert funding_txid funding_index = funding_tx.outputs().index(funding_output) # remote commitment transaction channel_id, funding_txid_bytes = channel_id_from_funding_tx(funding_txid, funding_index) diff --git a/electrum/lnworker.py b/electrum/lnworker.py @@ -53,7 +53,7 @@ from .lnutil import (Outpoint, LNPeerAddr, UpdateAddHtlc, Direction, LnLocalFeatures, format_short_channel_id, ShortChannelID) from .lnutil import ln_dummy_address -from .transaction import PartialTxOutput +from .transaction import PartialTxOutput, PartialTransaction from .lnonion import OnionFailureCode from .lnmsg import decode_msg from .i18n import _ @@ -808,7 +808,9 @@ class LNWallet(LNWorker): return total_value_sat > min_value_worth_closing_channel_over_sat @log_exceptions - async def _open_channel_coroutine(self, connect_str, funding_tx, funding_sat, push_sat, password): + async def _open_channel_coroutine(self, *, connect_str: str, funding_tx: PartialTransaction, + funding_sat: int, push_sat: int, + password: Optional[str]) -> Tuple[Channel, PartialTransaction]: peer = await self.add_peer(connect_str) # peer might just have been connected to await asyncio.wait_for(peer.initialized.wait(), LN_P2P_NETWORK_TIMEOUT) @@ -856,9 +858,12 @@ class LNWallet(LNWorker): tx.set_rbf(False) return tx - def open_channel(self, connect_str, funding_tx, funding_sat, push_amt_sat, password=None, timeout=20): + def open_channel(self, *, connect_str: str, funding_tx: PartialTransaction, + funding_sat: int, push_amt_sat: int, password: str = None, + timeout: Optional[int] = 20) -> Tuple[Channel, PartialTransaction]: assert funding_sat <= LN_MAX_FUNDING_SAT - coro = self._open_channel_coroutine(connect_str, funding_tx, funding_sat, push_amt_sat, password) + coro = self._open_channel_coroutine(connect_str=connect_str, funding_tx=funding_tx, funding_sat=funding_sat, + push_sat=push_amt_sat, password=password) fut = asyncio.run_coroutine_threadsafe(coro, self.network.asyncio_loop) try: chan, funding_tx = fut.result(timeout=timeout)