commit 7307c800d7f922f0f9a04eac2822d7014bbab39a
parent 6b42e8448c8b95880b5ccad1d1ecd313a4d8044d
Author: SomberNight <somber.night@protonmail.com>
Date: Fri, 3 Aug 2018 16:12:41 +0200
small optimisations for history tab refresh (and related)
Diffstat:
6 files changed, 29 insertions(+), 18 deletions(-)
diff --git a/electrum/address_synchronizer.py b/electrum/address_synchronizer.py
@@ -101,6 +101,9 @@ class AddressSynchronizer(PrintError):
h.append((tx_hash, tx_height))
return h
+ def get_address_history_len(self, addr: str) -> int:
+ return len(self._history_local.get(addr, ()))
+
def get_txin_address(self, txi):
addr = txi.get('address')
if addr and addr != "(pubkey)":
diff --git a/electrum/gui/qt/address_list.py b/electrum/gui/qt/address_list.py
@@ -93,8 +93,9 @@ class AddressList(MyTreeWidget):
else:
addr_list = self.wallet.get_addresses()
self.clear()
+ fx = self.parent.fx
for address in addr_list:
- num = len(self.wallet.get_address_history(address))
+ num = self.wallet.get_address_history_len(address)
label = self.wallet.labels.get(address, '')
c, u, x = self.wallet.get_addr_balance(address)
balance = c + u + x
@@ -106,7 +107,6 @@ class AddressList(MyTreeWidget):
if self.show_used == 3 and not is_used_and_empty:
continue
balance_text = self.parent.format_amount(balance, whitespaces=True)
- fx = self.parent.fx
# create item
if fx and fx.get_fiat_address_config():
rate = fx.exchange_rate()
diff --git a/electrum/gui/qt/history_list.py b/electrum/gui/qt/history_list.py
@@ -229,6 +229,9 @@ class HistoryList(MyTreeWidget, AcceptFileDragDrop):
current_tx = item.data(0, Qt.UserRole) if item else None
self.clear()
if fx: fx.history_used_spot = False
+ blue_brush = QBrush(QColor("#1E1EFF"))
+ red_brush = QBrush(QColor("#BC1E1E"))
+ monospace_font = QFont(MONOSPACE_FONT)
for tx_item in self.transactions:
tx_hash = tx_item['txid']
height = tx_item['height']
@@ -263,12 +266,12 @@ class HistoryList(MyTreeWidget, AcceptFileDragDrop):
if i>3:
item.setTextAlignment(i, Qt.AlignRight | Qt.AlignVCenter)
if i!=2:
- item.setFont(i, QFont(MONOSPACE_FONT))
+ item.setFont(i, monospace_font)
if value and value < 0:
- item.setForeground(3, QBrush(QColor("#BC1E1E")))
- item.setForeground(4, QBrush(QColor("#BC1E1E")))
+ item.setForeground(3, red_brush)
+ item.setForeground(4, red_brush)
if fiat_value and not tx_item['fiat_default']:
- item.setForeground(6, QBrush(QColor("#1E1EFF")))
+ item.setForeground(6, blue_brush)
if tx_hash:
item.setData(0, Qt.UserRole, tx_hash)
self.insertTopLevelItem(0, item)
diff --git a/electrum/plugin.py b/electrum/plugin.py
@@ -26,7 +26,6 @@ from collections import namedtuple
import traceback
import sys
import os
-import imp
import pkgutil
import time
import threading
diff --git a/electrum/util.py b/electrum/util.py
@@ -33,6 +33,7 @@ import threading
import hmac
import stat
import inspect
+from locale import localeconv
from .i18n import _
@@ -120,6 +121,8 @@ class UserCancelled(Exception):
pass
class Satoshis(object):
+ __slots__ = ('value',)
+
def __new__(cls, value):
self = super(Satoshis, cls).__new__(cls)
self.value = value
@@ -132,6 +135,8 @@ class Satoshis(object):
return format_satoshis(self.value) + " BTC"
class Fiat(object):
+ __slots__ = ('value', 'ccy')
+
def __new__(cls, value, ccy):
self = super(Fiat, cls).__new__(cls)
self.ccy = ccy
@@ -477,8 +482,10 @@ def format_satoshis_plain(x, decimal_point = 8):
return "{:.8f}".format(Decimal(x) / scale_factor).rstrip('0').rstrip('.')
+DECIMAL_POINT = localeconv()['decimal_point']
+
+
def format_satoshis(x, num_zeros=0, decimal_point=8, precision=None, is_diff=False, whitespaces=False):
- from locale import localeconv
if x is None:
return 'unknown'
if precision is None:
@@ -488,7 +495,7 @@ def format_satoshis(x, num_zeros=0, decimal_point=8, precision=None, is_diff=Fal
decimal_format = '+' + decimal_format
result = ("{:" + decimal_format + "f}").format(x / pow (10, decimal_point)).rstrip('0')
integer_part, fract_part = result.split(".")
- dp = localeconv()['decimal_point']
+ dp = DECIMAL_POINT
if len(fract_part) < num_zeros:
fract_part += "0" * (num_zeros - len(fract_part))
result = integer_part + dp + fract_part
diff --git a/electrum/wallet.py b/electrum/wallet.py
@@ -43,7 +43,7 @@ from .i18n import _
from .util import (NotEnoughFunds, PrintError, UserCancelled, profiler,
format_satoshis, format_fee_satoshis, NoDynamicFeeEstimates,
TimeoutException, WalletFileException, BitcoinException,
- InvalidPassword)
+ InvalidPassword, format_time)
from .bitcoin import *
from .version import *
@@ -386,11 +386,12 @@ class Abstract_Wallet(AddressSynchronizer):
fiat_income = Decimal(0)
fiat_expenditures = Decimal(0)
h = self.get_history(domain)
+ now = time.time()
for tx_hash, tx_mined_status, value, balance in h:
timestamp = tx_mined_status.timestamp
- if from_timestamp and (timestamp or time.time()) < from_timestamp:
+ if from_timestamp and (timestamp or now) < from_timestamp:
continue
- if to_timestamp and (timestamp or time.time()) >= to_timestamp:
+ if to_timestamp and (timestamp or now) >= to_timestamp:
continue
item = {
'txid': tx_hash,
@@ -398,10 +399,10 @@ class Abstract_Wallet(AddressSynchronizer):
'confirmations': tx_mined_status.conf,
'timestamp': timestamp,
'value': Satoshis(value),
- 'balance': Satoshis(balance)
+ 'balance': Satoshis(balance),
+ 'date': timestamp_to_datetime(timestamp),
+ 'label': self.get_label(tx_hash),
}
- item['date'] = timestamp_to_datetime(timestamp)
- item['label'] = self.get_label(tx_hash)
if show_addresses:
tx = self.transactions.get(tx_hash)
item['inputs'] = list(map(lambda x: dict((k, x[k]) for k in ('prevout_hash', 'prevout_n')), tx.inputs()))
@@ -416,10 +417,9 @@ class Abstract_Wallet(AddressSynchronizer):
income += value
# fiat computations
if fx and fx.is_enabled():
- date = timestamp_to_datetime(timestamp)
fiat_value = self.get_fiat_value(tx_hash, fx.ccy)
fiat_default = fiat_value is None
- fiat_value = fiat_value if fiat_value is not None else value / Decimal(COIN) * self.price_at_timestamp(tx_hash, fx.timestamp_rate)
+ fiat_value = fiat_value if fiat_value is not None else value / Decimal(COIN) * self.price_at_timestamp(tx_hash, fx.timestamp_rate) #
item['fiat_value'] = Fiat(fiat_value, fx.ccy)
item['fiat_default'] = fiat_default
if value < 0:
@@ -487,7 +487,6 @@ class Abstract_Wallet(AddressSynchronizer):
return ''
def get_tx_status(self, tx_hash, tx_mined_status):
- from .util import format_time
extra = []
height = tx_mined_status.height
conf = tx_mined_status.conf