Browse Source

wallet history fees: only calculate fees when exporting history

it's expensive, and it slows down startup of large wallets a lot
3.3.3.1
SomberNight 6 years ago
parent
commit
960855d0aa
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 5
      electrum/address_synchronizer.py
  2. 8
      electrum/commands.py
  3. 11
      electrum/gui/qt/history_list.py
  4. 9
      electrum/wallet.py

5
electrum/address_synchronizer.py

@ -722,9 +722,8 @@ class AddressSynchronizer(PrintError):
if fee is None: if fee is None:
txid = tx.txid() txid = tx.txid()
fee = self.tx_fees.get(txid) fee = self.tx_fees.get(txid)
# cache fees. if wallet is synced, cache all; # only cache non-None, as None can still change while syncing
# otherwise only cache non-None, as None can still change while syncing if fee is not None:
if self.up_to_date or fee is not None:
tx._cached_fee = fee tx._cached_fee = fee
return fee return fee

8
electrum/commands.py

@ -520,9 +520,12 @@ class Commands:
return tx.as_dict() return tx.as_dict()
@command('w') @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.""" """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: if year:
import time import time
start_date = datetime.datetime(year, 1, 1) start_date = datetime.datetime(year, 1, 1)
@ -808,6 +811,7 @@ command_options = {
'paid': (None, "Show only paid requests."), 'paid': (None, "Show only paid requests."),
'show_addresses': (None, "Show input and output addresses"), 'show_addresses': (None, "Show input and output addresses"),
'show_fiat': (None, "Show fiat value of transactions"), '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"), 'year': (None, "Show history for a given year"),
'fee_method': (None, "Fee estimation method to use"), 'fee_method': (None, "Fee estimation method to use"),
'fee_level': (None, "Float between 0.0 and 1.0, representing fee slider position") 'fee_level': (None, "Float between 0.0 and 1.0, representing fee slider position")

11
electrum/gui/qt/history_list.py

@ -555,10 +555,15 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
self.parent.show_message(_("Your wallet history has been successfully exported.")) self.parent.show_message(_("Your wallet history has been successfully exported."))
def do_export_history(self, file_name, is_csv): 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 = [] lines = []
if is_csv: if is_csv:
for item in history: for item in txns:
lines.append([item['txid'], lines.append([item['txid'],
item.get('label', ''), item.get('label', ''),
item['confirmations'], item['confirmations'],
@ -583,4 +588,4 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
transaction.writerow(line) transaction.writerow(line)
else: else:
from electrum.util import json_encode from electrum.util import json_encode
f.write(json_encode(history)) f.write(json_encode(txns))

9
electrum/wallet.py

@ -394,7 +394,8 @@ class Abstract_Wallet(AddressSynchronizer):
return balance return balance
@profiler @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 = [] out = []
income = 0 income = 0
expenditures = 0 expenditures = 0
@ -420,8 +421,10 @@ class Abstract_Wallet(AddressSynchronizer):
'date': timestamp_to_datetime(timestamp), 'date': timestamp_to_datetime(timestamp),
'label': self.get_label(tx_hash), 'label': self.get_label(tx_hash),
} }
tx_fee = self.get_tx_fee(tx) tx_fee = None
item['fee'] = Satoshis(tx_fee) if tx_fee is not None else 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: if show_addresses:
item['inputs'] = list(map(lambda x: dict((k, x[k]) for k in ('prevout_hash', 'prevout_n')), tx.inputs())) 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)}, item['outputs'] = list(map(lambda x:{'address':x.address, 'value':Satoshis(x.value)},

Loading…
Cancel
Save