mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-02 02:05:19 +00:00
lnworker.pay: small clean-up
This commit is contained in:
parent
7d3eb5d4db
commit
7951f2ed3b
2 changed files with 8 additions and 7 deletions
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
@ -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"))
|
||||
|
|
Loading…
Add table
Reference in a new issue