Browse Source

submarine swaps: improve labels

- claim tx was incorrectly labeled
 - if we send tx change to a swap, display both labels
master
ThomasV 2 years ago
parent
commit
40eba6f780
  1. 14
      electrum/lnworker.py
  2. 13
      electrum/wallet.py

14
electrum/lnworker.py

@ -1044,10 +1044,8 @@ class LNWallet(LNWorker):
if swap:
if swap.is_reverse:
item['group_id'] = swap.spending_txid
item['group_label'] = 'Reverse swap' + ' ' + self.config.format_amount_and_units(swap.lightning_amount)
else:
item['group_id'] = swap.funding_txid
item['group_label'] = 'Forward swap' + ' ' + self.config.format_amount_and_units(swap.onchain_amount)
# done
out[payment_hash] = item
return out
@ -1119,7 +1117,14 @@ class LNWallet(LNWorker):
direction, amount_msat, fee_msat, timestamp = self.get_payment_value(info, plist)
else:
amount_msat = 0
label = 'Reverse swap' if swap.is_reverse else 'Forward swap'
if swap.is_reverse:
group_label = 'Reverse swap' + ' ' + self.config.format_amount_and_units(swap.lightning_amount)
else:
group_label = 'Forward swap' + ' ' + self.config.format_amount_and_units(swap.onchain_amount)
self._labels_cache[txid] = group_label
label = _('Claim transaction') if swap.is_reverse else _('Funding transaction')
delta = current_height - swap.locktime
if self.wallet.adb.is_mine(swap.lockup_address):
tx_height = self.wallet.adb.get_tx_height(swap.funding_txid)
@ -1127,12 +1132,11 @@ class LNWallet(LNWorker):
label += ' (%s)' % _('waiting for funding tx confirmation')
if not swap.is_reverse and not swap.is_redeemed and swap.spending_txid is None and delta < 0:
label += f' (refundable in {-delta} blocks)' # fixme: only if unspent
self._labels_cache[txid] = label
out[txid] = {
'group_id': txid,
'amount_msat': 0, # must be zero for onchain tx
'type': 'swap',
'label': _('Funding transaction'),
'label': label,
}
if not swap.is_reverse:
# if the spending_tx is in the wallet, this will add it

13
electrum/wallet.py

@ -1292,9 +1292,10 @@ class Abstract_Wallet(ABC, Logger, EventListener):
else:
key = 'group:' + group_id
parent = transactions.get(key)
label = self.get_label_for_txid(group_id)
if parent is None:
parent = {
'label': tx_item.get('group_label'),
'label': label,
'fiat_value': Fiat(Decimal(0), fx.ccy) if fx else None,
'bc_value': Satoshis(0),
'ln_value': Satoshis(0),
@ -1527,24 +1528,22 @@ class Abstract_Wallet(ABC, Logger, EventListener):
return self._labels.get(tx_hash) or self._get_default_label_for_txid(tx_hash)
def _get_default_label_for_txid(self, tx_hash: str) -> str:
if self.lnworker and (label:= self.lnworker.get_label_for_txid(tx_hash)):
return label
labels = []
# note: we don't deserialize tx as the history calls us for every tx, and that would be slow
if not self.db.get_txi_addresses(tx_hash):
# no inputs are ismine -> likely incoming payment -> concat labels of output addresses
labels = []
for addr in self.db.get_txo_addresses(tx_hash):
label = self.get_label_for_address(addr)
if label:
labels.append(label)
return ', '.join(labels)
else:
# some inputs are ismine -> likely outgoing payment
labels = []
for invoice in self.get_relevant_invoices_for_tx(tx_hash):
if invoice.message:
labels.append(invoice.message)
return ', '.join(labels)
if not labels and self.lnworker and (label:= self.lnworker.get_label_for_txid(tx_hash)):
labels.append(label)
return ', '.join(labels)
def _get_default_label_for_rhash(self, rhash: str) -> str:
req = self.get_request(rhash)

Loading…
Cancel
Save