Browse Source

lnpay: return payment log, increase timeout

master
ThomasV 5 years ago
parent
commit
7b44e27087
  1. 6
      electrum/commands.py
  2. 6
      electrum/lnworker.py

6
electrum/commands.py

@ -1005,16 +1005,17 @@ class Commands:
return parse_lightning_invoice(invoice)
@command('wn')
async def lnpay(self, invoice, attempts=1, timeout=10, wallet: Abstract_Wallet = None):
async def lnpay(self, invoice, attempts=1, timeout=30, wallet: Abstract_Wallet = None):
lnworker = wallet.lnworker
lnaddr = lnworker._check_invoice(invoice, None)
payment_hash = lnaddr.paymenthash
wallet.save_invoice(parse_lightning_invoice(invoice))
success = await lnworker._pay(invoice, attempts=attempts)
success, log = await lnworker._pay(invoice, attempts=attempts)
return {
'payment_hash': payment_hash.hex(),
'success': success,
'preimage': lnworker.get_preimage(payment_hash).hex() if success else None,
'log': [x.formatted_tuple() for x in log]
}
@command('w')
@ -1202,6 +1203,7 @@ arg_types = {
'encrypt_file': eval_bool,
'rbf': eval_bool,
'timeout': float,
'attempts': int,
}
config_variables = {

6
electrum/lnworker.py

@ -807,7 +807,7 @@ class LNWallet(LNWorker):
"""
coro = self._pay(invoice, amount_sat, attempts)
fut = asyncio.run_coroutine_threadsafe(coro, self.network.asyncio_loop)
success = fut.result()
success, log = fut.result()
def get_channel_by_short_id(self, short_channel_id: ShortChannelID) -> Channel:
for chan in self.channels.values():
@ -827,7 +827,7 @@ class LNWallet(LNWorker):
info = PaymentInfo(lnaddr.paymenthash, amount, SENT, PR_UNPAID)
self.save_payment_info(info)
self.wallet.set_label(key, lnaddr.get_description())
log = self.logs[key]
self.logs[key] = log = []
success = False
reason = ''
for i in range(attempts):
@ -856,7 +856,7 @@ class LNWallet(LNWorker):
util.trigger_callback('payment_succeeded', key)
else:
util.trigger_callback('payment_failed', key, reason)
return success
return success, log
async def _pay_to_route(self, route: LNPaymentRoute, lnaddr: LnAddr) -> PaymentAttemptLog:
short_channel_id = route[0].short_channel_id

Loading…
Cancel
Save