Browse Source

add/fix some open_channel related type hints

hard-fail-on-bad-server-string
SomberNight 5 years ago
parent
commit
557987d4eb
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 3
      electrum/address_synchronizer.py
  2. 6
      electrum/commands.py
  3. 15
      electrum/gui/kivy/uix/dialogs/lightning_open_channel.py
  4. 6
      electrum/gui/qt/main_window.py
  5. 3
      electrum/lnpeer.py
  6. 13
      electrum/lnworker.py

3
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:

6
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')

15
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

6
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

3
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)

13
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)

Loading…
Cancel
Save