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) return parse_lightning_invoice(invoice)
@command('wn') @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 lnworker = wallet.lnworker
lnaddr = lnworker._check_invoice(invoice, None) lnaddr = lnworker._check_invoice(invoice, None)
payment_hash = lnaddr.paymenthash payment_hash = lnaddr.paymenthash
wallet.save_invoice(parse_lightning_invoice(invoice)) wallet.save_invoice(parse_lightning_invoice(invoice))
success = await lnworker._pay(invoice, attempts=attempts) success, log = await lnworker._pay(invoice, attempts=attempts)
return { return {
'payment_hash': payment_hash.hex(), 'payment_hash': payment_hash.hex(),
'success': success, 'success': success,
'preimage': lnworker.get_preimage(payment_hash).hex() if success else None, 'preimage': lnworker.get_preimage(payment_hash).hex() if success else None,
'log': [x.formatted_tuple() for x in log]
} }
@command('w') @command('w')
@ -1202,6 +1203,7 @@ arg_types = {
'encrypt_file': eval_bool, 'encrypt_file': eval_bool,
'rbf': eval_bool, 'rbf': eval_bool,
'timeout': float, 'timeout': float,
'attempts': int,
} }
config_variables = { config_variables = {

6
electrum/lnworker.py

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

Loading…
Cancel
Save