URI: 
       tQt: show amounts sent to channels in show_transaction - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 64a8de8bae437c76535eec663f8d2f1d07561241
   DIR parent d319680d166da130396af24a0019f85c670b2b80
  HTML Author: ThomasV <thomasv@electrum.org>
       Date:   Sat, 22 Feb 2020 16:02:02 +0100
       
       Qt: show amounts sent to channels in show_transaction
       
       Diffstat:
         M electrum/gui/qt/transaction_dialog… |      36 ++++++++++++++++++++++++++-----
         M electrum/lnworker.py                |      19 +++++++++++++------
       
       2 files changed, 44 insertions(+), 11 deletions(-)
       ---
   DIR diff --git a/electrum/gui/qt/transaction_dialog.py b/electrum/gui/qt/transaction_dialog.py
       t@@ -376,6 +376,15 @@ class BaseTxDialog(QDialog, MessageBoxMixin):
                exp_n = tx_details.mempool_depth_bytes
                amount, fee = tx_details.amount, tx_details.fee
                size = self.tx.estimated_size()
       +        txid = self.tx.txid()
       +        lnworker_history = self.wallet.lnworker.get_onchain_history() if self.wallet.lnworker else {}
       +        if txid in lnworker_history:
       +            item = lnworker_history[txid]
       +            ln_amount = item['amount_msat'] / 1000
       +            if amount is None:
       +                tx_mined_status = self.wallet.lnworker.lnwatcher.get_tx_height(txid)
       +        else:
       +            ln_amount = None
                self.broadcast_button.setEnabled(tx_details.can_broadcast)
                can_sign = not self.tx.is_complete() and \
                    (self.wallet.can_sign(self.tx) or bool(self.external_keypairs))
       t@@ -409,12 +418,18 @@ class BaseTxDialog(QDialog, MessageBoxMixin):
                else:
                    self.block_hash_label.hide()
                    self.block_height_label.hide()
       -        if amount is None:
       +        if amount is None and ln_amount is None:
                    amount_str = _("Transaction unrelated to your wallet")
       +        elif amount is None:
       +            amount_str = ''
                elif amount > 0:
                    amount_str = _("Amount received:") + ' %s'% format_amount(amount) + ' ' + base_unit
                else:
                    amount_str = _("Amount sent:") + ' %s'% format_amount(-amount) + ' ' + base_unit
       +        if amount_str:
       +            self.amount_label.setText(amount_str)
       +        else:
       +            self.amount_label.hide()
                size_str = _("Size:") + ' %d bytes'% size
                fee_str = _("Fee") + ': %s' % (format_amount(fee) + ' ' + base_unit if fee is not None else _('unknown'))
                if fee is not None:
       t@@ -427,10 +442,18 @@ class BaseTxDialog(QDialog, MessageBoxMixin):
                    risk_of_burning_coins = (can_sign and fee is not None
                                             and self.tx.is_there_risk_of_burning_coins_as_fees())
                    self.fee_warning_icon.setVisible(risk_of_burning_coins)
       -        self.amount_label.setText(amount_str)
                self.fee_label.setText(fee_str)
                self.size_label.setText(size_str)
       -
       +        if ln_amount is None:
       +            ln_amount_str = ''
       +        elif ln_amount > 0:
       +            ln_amount_str = _('Amount received in channels') + ': ' + format_amount(ln_amount) + ' ' + base_unit
       +        elif ln_amount < 0:
       +            ln_amount_str = _('Amount withdrawn from channels') + ': ' + format_amount(-ln_amount) + ' ' + base_unit
       +        if ln_amount_str:
       +            self.ln_amount_label.setText(ln_amount_str)
       +        else:
       +            self.ln_amount_label.hide()
                show_psbt_only_widgets = self.finalized and isinstance(self.tx, PartialTransaction)
                for widget in self.psbt_only_widgets:
                    if isinstance(widget, QMenu):
       t@@ -521,6 +544,8 @@ class BaseTxDialog(QDialog, MessageBoxMixin):
                vbox_left.addWidget(self.date_label)
                self.amount_label = TxDetailLabel()
                vbox_left.addWidget(self.amount_label)
       +        self.ln_amount_label = TxDetailLabel()
       +        vbox_left.addWidget(self.ln_amount_label)
        
                fee_hbox = QHBoxLayout()
                self.fee_label = TxDetailLabel()
       t@@ -561,8 +586,6 @@ class BaseTxDialog(QDialog, MessageBoxMixin):
        
                self.locktime_label = TxDetailLabel()
                vbox_right.addWidget(self.locktime_label)
       -        self.block_hash_label = TxDetailLabel(word_wrap=True)
       -        vbox_right.addWidget(self.block_hash_label)
                self.block_height_label = TxDetailLabel()
                vbox_right.addWidget(self.block_height_label)
                vbox_right.addStretch(1)
       t@@ -570,6 +593,9 @@ class BaseTxDialog(QDialog, MessageBoxMixin):
        
                vbox.addLayout(hbox_stats)
        
       +        self.block_hash_label = TxDetailLabel(word_wrap=True)
       +        vbox.addWidget(self.block_hash_label)
       +
                # set visibility after parenting can be determined by Qt
                self.rbf_label.setVisible(self.finalized)
                self.rbf_cb.setVisible(not self.finalized)
   DIR diff --git a/electrum/lnworker.py b/electrum/lnworker.py
       t@@ -495,8 +495,8 @@ class LNWallet(LNWorker):
                    'rhash': lnaddr.paymenthash.hex(),
                }
        
       -    def get_history(self):
       -        out = []
       +    def get_lightning_history(self):
       +        out = {}
                for key, plist in self.get_settled_payments().items():
                    if len(plist) == 0:
                        continue
       t@@ -524,7 +524,6 @@ class LNWallet(LNWorker):
        
                    payment_hash = bytes.fromhex(key)
                    preimage = self.get_preimage(payment_hash).hex()
       -
                    item = {
                        'type': 'payment',
                        'label': label,
       t@@ -536,7 +535,11 @@ class LNWallet(LNWorker):
                        'payment_hash': key,
                        'preimage': preimage,
                    }
       -            out.append(item)
       +            out[payment_hash] = item
       +        return out
       +
       +    def get_onchain_history(self):
       +        out = {}
                # add funding events
                with self.lock:
                    channels = list(self.channels.values())
       t@@ -555,7 +558,7 @@ class LNWallet(LNWorker):
                        'timestamp': funding_timestamp,
                        'fee_msat': None,
                    }
       -            out.append(item)
       +            out[funding_txid] = item
                    if not chan.is_closed():
                        continue
                    assert closing_txid
       t@@ -569,7 +572,11 @@ class LNWallet(LNWorker):
                        'timestamp': closing_timestamp,
                        'fee_msat': None,
                    }
       -            out.append(item)
       +            out[closing_txid] = item
       +        return out
       +
       +    def get_history(self):
       +        out = list(self.get_lightning_history().values()) + list(self.get_onchain_history().values())
                # sort by timestamp
                out.sort(key=lambda x: (x.get('timestamp') or float("inf")))
                balance_msat = 0