URI: 
       twallet history fees: only calculate fees when exporting history - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 960855d0aace0417db1e0bedcaa6bcaad1f79e1d
   DIR parent ebea5b015997271abeb845ca01d58442e7454a7e
  HTML Author: SomberNight <somber.night@protonmail.com>
       Date:   Tue,  4 Dec 2018 16:17:22 +0100
       
       wallet history fees: only calculate fees when exporting history
       
       it's expensive, and it slows down startup of large wallets a lot
       
       Diffstat:
         M electrum/address_synchronizer.py    |       5 ++---
         M electrum/commands.py                |       8 ++++++--
         M electrum/gui/qt/history_list.py     |      11 ++++++++---
         M electrum/wallet.py                  |       9 ++++++---
       
       4 files changed, 22 insertions(+), 11 deletions(-)
       ---
   DIR diff --git a/electrum/address_synchronizer.py b/electrum/address_synchronizer.py
       t@@ -722,9 +722,8 @@ class AddressSynchronizer(PrintError):
                    if fee is None:
                        txid = tx.txid()
                        fee = self.tx_fees.get(txid)
       -            # cache fees. if wallet is synced, cache all;
       -            # otherwise only cache non-None, as None can still change while syncing
       -            if self.up_to_date or fee is not None:
       +            # only cache non-None, as None can still change while syncing
       +            if fee is not None:
                        tx._cached_fee = fee
                return fee
        
   DIR diff --git a/electrum/commands.py b/electrum/commands.py
       t@@ -520,9 +520,12 @@ class Commands:
                return tx.as_dict()
        
            @command('w')
       -    def history(self, year=None, show_addresses=False, show_fiat=False):
       +    def history(self, year=None, show_addresses=False, show_fiat=False, show_fees=False):
                """Wallet history. Returns the transaction history of your wallet."""
       -        kwargs = {'show_addresses': show_addresses}
       +        kwargs = {
       +            'show_addresses': show_addresses,
       +            'show_fees': show_fees,
       +        }
                if year:
                    import time
                    start_date = datetime.datetime(year, 1, 1)
       t@@ -808,6 +811,7 @@ command_options = {
            'paid':        (None, "Show only paid requests."),
            'show_addresses': (None, "Show input and output addresses"),
            'show_fiat':   (None, "Show fiat value of transactions"),
       +    'show_fees':   (None, "Show miner fees paid by transactions"),
            'year':        (None, "Show history for a given year"),
            'fee_method':  (None, "Fee estimation method to use"),
            'fee_level':   (None, "Float between 0.0 and 1.0, representing fee slider position")
   DIR diff --git a/electrum/gui/qt/history_list.py b/electrum/gui/qt/history_list.py
       t@@ -555,10 +555,15 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
                self.parent.show_message(_("Your wallet history has been successfully exported."))
        
            def do_export_history(self, file_name, is_csv):
       -        history = self.transactions.values()
       +        hist = self.wallet.get_full_history(domain=self.get_domain(),
       +                                            from_timestamp=None,
       +                                            to_timestamp=None,
       +                                            fx=self.parent.fx,
       +                                            show_fees=True)
       +        txns = hist['transactions']
                lines = []
                if is_csv:
       -            for item in history:
       +            for item in txns:
                        lines.append([item['txid'],
                                      item.get('label', ''),
                                      item['confirmations'],
       t@@ -583,4 +588,4 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
                            transaction.writerow(line)
                    else:
                        from electrum.util import json_encode
       -                f.write(json_encode(history))
       +                f.write(json_encode(txns))
   DIR diff --git a/electrum/wallet.py b/electrum/wallet.py
       t@@ -394,7 +394,8 @@ class Abstract_Wallet(AddressSynchronizer):
                return balance
        
            @profiler
       -    def get_full_history(self, domain=None, from_timestamp=None, to_timestamp=None, fx=None, show_addresses=False):
       +    def get_full_history(self, domain=None, from_timestamp=None, to_timestamp=None,
       +                         fx=None, show_addresses=False, show_fees=False):
                out = []
                income = 0
                expenditures = 0
       t@@ -420,8 +421,10 @@ class Abstract_Wallet(AddressSynchronizer):
                        'date': timestamp_to_datetime(timestamp),
                        'label': self.get_label(tx_hash),
                    }
       -            tx_fee = self.get_tx_fee(tx)
       -            item['fee'] = Satoshis(tx_fee) if tx_fee is not None else None
       +            tx_fee = None
       +            if show_fees:
       +                tx_fee = self.get_tx_fee(tx)
       +                item['fee'] = Satoshis(tx_fee) if tx_fee is not None else None
                    if show_addresses:
                        item['inputs'] = list(map(lambda x: dict((k, x[k]) for k in ('prevout_hash', 'prevout_n')), tx.inputs()))
                        item['outputs'] = list(map(lambda x:{'address':x.address, 'value':Satoshis(x.value)},