tlnworker.pay: small clean-up - electrum - Electrum Bitcoin wallet (HTM) git clone https://git.parazyd.org/electrum (DIR) Log (DIR) Files (DIR) Refs (DIR) Submodules --- (DIR) commit 7951f2ed3b652e12dfaf7f9685d1428a2a9e4deb (DIR) parent 7d3eb5d4dbf465b248dd9e77fb6b3ded09fecf5a (HTM) Author: SomberNight <somber.night@protonmail.com> Date: Wed, 6 May 2020 04:02:59 +0200 lnworker.pay: small clean-up Diffstat: M electrum/gui/qt/main_window.py | 2 +- M electrum/lnworker.py | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) --- (DIR) diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py t@@ -1473,7 +1473,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): def pay_lightning_invoice(self, invoice, amount_sat=None): attempts = LN_NUM_PAYMENT_ATTEMPTS def task(): - self.wallet.lnworker.pay(invoice, amount_sat, attempts) + self.wallet.lnworker.pay(invoice, amount_sat, attempts=attempts) self.do_clear() self.wallet.thread.add(task) self.invoice_list.update() (DIR) diff --git a/electrum/lnworker.py b/electrum/lnworker.py t@@ -801,20 +801,21 @@ class LNWallet(LNWorker): raise Exception(_("open_channel timed out")) return chan, funding_tx - def pay(self, invoice, amount_sat=None, attempts=1): + def pay(self, invoice: str, amount_sat: int = None, *, attempts: int = 1) -> Tuple[bool, List[PaymentAttemptLog]]: """ Can be called from other threads """ - coro = self._pay(invoice, amount_sat, attempts) + coro = self._pay(invoice, amount_sat, attempts=attempts) fut = asyncio.run_coroutine_threadsafe(coro, self.network.asyncio_loop) - success, log = fut.result() + return fut.result() - def get_channel_by_short_id(self, short_channel_id: ShortChannelID) -> Channel: + def get_channel_by_short_id(self, short_channel_id: bytes) -> Optional[Channel]: for chan in self.channels.values(): if chan.short_channel_id == short_channel_id: return chan - async def _pay(self, invoice, amount_sat=None, attempts=1) -> bool: + async def _pay(self, invoice: str, amount_sat: int = None, *, + attempts: int = 1) -> Tuple[bool, List[PaymentAttemptLog]]: lnaddr = self._check_invoice(invoice, amount_sat) payment_hash = lnaddr.paymenthash key = payment_hash.hex() t@@ -958,7 +959,7 @@ class LNWallet(LNWorker): return blacklist @staticmethod - def _check_invoice(invoice, amount_sat=None): + def _check_invoice(invoice: str, amount_sat: int = None) -> LnAddr: addr = lndecode(invoice, expected_hrp=constants.net.SEGWIT_HRP) if addr.is_expired(): raise InvoiceError(_("This invoice has expired"))