Browse Source

fix #6125: detect self-payments

master
ThomasV 5 years ago
parent
commit
984da7515a
  1. 6
      electrum/gui/kivy/uix/dialogs/lightning_tx_dialog.py
  2. 4
      electrum/lnchannel.py
  3. 29
      electrum/lnworker.py

6
electrum/gui/kivy/uix/dialogs/lightning_tx_dialog.py

@ -98,7 +98,6 @@ class LightningTxDialog(Factory.Popup):
self.app = app # type: ElectrumWindow
self.wallet = self.app.wallet
self._action_button_fn = lambda btn: None
self.is_sent = bool(tx_item['direction'] == 'sent')
self.description = tx_item['label']
self.timestamp = tx_item['timestamp']
self.date_str = datetime.fromtimestamp(self.timestamp).isoformat(' ')[:-3]
@ -106,6 +105,7 @@ class LightningTxDialog(Factory.Popup):
self.payment_hash = tx_item['payment_hash']
self.preimage = tx_item['preimage']
format_amount = self.app.format_amount_and_units
self.amount_str = format_amount(self.amount)
if self.is_sent:
self.is_sent = self.amount < 0
self.amount_str = format_amount(-self.amount if self.is_sent else self.amount)
if tx_item.get('fee_msat'):
self.fee_str = format_amount(Decimal(tx_item['fee_msat']) / 1000)

4
electrum/lnchannel.py

@ -631,14 +631,14 @@ class Channel(AbstractChannel):
return out
def get_settled_payments(self):
out = {}
out = defaultdict(list)
for subject in LOCAL, REMOTE:
log = self.hm.log[subject]
for htlc_id, htlc in log.get('adds', {}).items():
if htlc_id in log.get('settles',{}):
direction = SENT if subject is LOCAL else RECEIVED
rhash = bh2u(htlc.payment_hash)
out[rhash] = (self.channel_id, htlc, direction)
out[rhash].append((self.channel_id, htlc, direction))
return out
def open_with_first_pcp(self, remote_pcp: bytes, remote_sig: bytes) -> None:

29
electrum/lnworker.py

@ -593,7 +593,7 @@ class LNWallet(LNWorker):
for chan in self.channels.values():
d = chan.get_settled_payments()
for k, v in d.items():
out[k].append(v)
out[k] += v
return out
def get_lightning_history(self):
@ -601,26 +601,21 @@ class LNWallet(LNWorker):
for key, plist in self.get_settled_payments().items():
if len(plist) == 0:
continue
elif len(plist) == 1:
chan_id, htlc, _direction = plist[0]
direction = 'sent' if _direction == SENT else 'received'
amount_msat = int(_direction) * htlc.amount_msat
timestamp = htlc.timestamp
payment_hash = bytes.fromhex(key)
info = self.get_payment_info(payment_hash)
timestamp = min([htlc.timestamp for chan_id, htlc, _direction in plist])
amount_msat = 0
fee_msat = None
for chan_id, htlc, _direction in plist:
amount_msat += int(_direction) * htlc.amount_msat
if _direction == SENT and info and info.amount:
fee_msat = (fee_msat or 0) - info.amount*1000 - amount_msat
if info is not None:
label = self.wallet.get_label(key)
if _direction == SENT:
info = self.get_payment_info(bfh(key))
fee_msat = - info.amount*1000 - amount_msat if info and info.amount else None
else:
fee_msat = None
direction = ('sent' if info.direction == SENT else 'received') if len(plist)==1 else 'self-payment'
else:
# assume forwarding
direction = 'forwarding'
amount_msat = sum([int(_direction) * htlc.amount_msat for chan_id, htlc, _direction in plist])
label = _('Forwarding')
timestamp = min([htlc.timestamp for chan_id, htlc, _direction in plist])
fee_msat = None # fixme
payment_hash = bytes.fromhex(key)
preimage = self.get_preimage(payment_hash).hex()
item = {
'type': 'payment',

Loading…
Cancel
Save