Browse Source

kivy: show payment log details

hard-fail-on-bad-server-string
ThomasV 5 years ago
parent
commit
6c2ef176cc
  1. 5
      electrum/gui/kivy/uix/dialogs/invoice_dialog.py
  2. 31
      electrum/gui/qt/invoice_list.py
  3. 20
      electrum/lnutil.py

5
electrum/gui/kivy/uix/dialogs/invoice_dialog.py

@ -137,5 +137,8 @@ class InvoiceDialog(Factory.Popup):
def show_log(self): def show_log(self):
if self.log: if self.log:
log_str = _('Payment log:') + '\n\n' + '\n'.join([str(x.exception) for x in self.log]) log_str = _('Payment log:') + '\n\n'
for payment_attempt_log in self.log:
route_str, chan_str, message = payment_attempt_log.formatted_tuple()
log_str += chan_str + ' --- ' + message + '\n'
self.app.show_info(log_str) self.app.show_info(log_str)

31
electrum/gui/qt/invoice_list.py

@ -29,7 +29,7 @@ from typing import Sequence
from PyQt5.QtCore import Qt, QItemSelectionModel from PyQt5.QtCore import Qt, QItemSelectionModel
from PyQt5.QtGui import QStandardItemModel, QStandardItem from PyQt5.QtGui import QStandardItemModel, QStandardItem
from PyQt5.QtWidgets import QAbstractItemView from PyQt5.QtWidgets import QAbstractItemView
from PyQt5.QtWidgets import QMenu, QVBoxLayout, QTreeWidget, QTreeWidgetItem from PyQt5.QtWidgets import QMenu, QVBoxLayout, QTreeWidget, QTreeWidgetItem, QHeaderView
from electrum.i18n import _ from electrum.i18n import _
from electrum.util import format_time, PR_UNPAID, PR_PAID, PR_INFLIGHT, PR_FAILED from electrum.util import format_time, PR_UNPAID, PR_PAID, PR_INFLIGHT, PR_FAILED
@ -173,32 +173,15 @@ class InvoiceList(MyTreeView):
def show_log(self, key, log: Sequence[PaymentAttemptLog]): def show_log(self, key, log: Sequence[PaymentAttemptLog]):
d = WindowModalDialog(self, _("Payment log")) d = WindowModalDialog(self, _("Payment log"))
d.setMinimumWidth(800) d.setMinimumWidth(600)
vbox = QVBoxLayout(d) vbox = QVBoxLayout(d)
log_w = QTreeWidget() log_w = QTreeWidget()
log_w.setHeaderLabels([_('Route'), _('Channel ID'), _('Message'), _('Blacklist')]) log_w.setHeaderLabels([_('Hops'), _('Channel ID'), _('Message')])
log_w.header().setSectionResizeMode(2, QHeaderView.Stretch)
log_w.header().setSectionResizeMode(1, QHeaderView.ResizeToContents)
for payment_attempt_log in log: for payment_attempt_log in log:
if not payment_attempt_log.exception: route_str, chan_str, message = payment_attempt_log.formatted_tuple()
route = payment_attempt_log.route x = QTreeWidgetItem([route_str, chan_str, message])
route_str = '%d'%len(route)
if not payment_attempt_log.success:
sender_idx = payment_attempt_log.failure_details.sender_idx
failure_msg = payment_attempt_log.failure_details.failure_msg
blacklist_msg = str(payment_attempt_log.failure_details.is_blacklisted)
short_channel_id = route[sender_idx+1].short_channel_id
data = failure_msg.data
message = repr(failure_msg.code)
else:
short_channel_id = route[-1].short_channel_id
message = _('Success')
blacklist_msg = str(False)
chan_str = str(short_channel_id)
else:
route_str = 'None'
chan_str = 'N/A'
message = str(payment_attempt_log.exception)
blacklist_msg = 'N/A'
x = QTreeWidgetItem([route_str, chan_str, message, blacklist_msg])
log_w.addTopLevelItem(x) log_w.addTopLevelItem(x)
vbox.addWidget(log_w) vbox.addWidget(log_w)
vbox.addLayout(Buttons(CloseButton(d))) vbox.addLayout(Buttons(CloseButton(d)))

20
electrum/lnutil.py

@ -119,6 +119,26 @@ class PaymentAttemptLog(NamedTuple):
failure_details: Optional[PaymentAttemptFailureDetails] = None failure_details: Optional[PaymentAttemptFailureDetails] = None
exception: Optional[Exception] = None exception: Optional[Exception] = None
def formatted_tuple(self):
if not self.exception:
route = self.route
route_str = '%d'%len(route)
if not self.success:
sender_idx = self.failure_details.sender_idx
failure_msg = self.failure_details.failure_msg
short_channel_id = route[sender_idx+1].short_channel_id
data = failure_msg.data
message = str(failure_msg.code.name)
else:
short_channel_id = route[-1].short_channel_id
message = _('Success')
chan_str = str(short_channel_id)
else:
route_str = 'None'
chan_str = 'N/A'
message = str(self.exception)
return route_str, chan_str, message
class LightningError(Exception): pass class LightningError(Exception): pass
class LightningPeerConnectionClosed(LightningError): pass class LightningPeerConnectionClosed(LightningError): pass

Loading…
Cancel
Save