twallet: get_full_history should populate acq_price/cap_gains if enabled - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit c64da9448fb521ce5433c2d63f826afe1fc42b33 DIR parent 928e43fc530ba5befa062db788e4e04d56324161 HTML Author: SomberNight <somber.night@protonmail.com> Date: Mon, 24 Aug 2020 18:17:05 +0200 wallet: get_full_history should populate acq_price/cap_gains if enabled fixes #6370 qt history tab is calling get_full_history; so this is needed to populate cap_gains columns Diffstat: M electrum/wallet.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) --- DIR diff --git a/electrum/wallet.py b/electrum/wallet.py t@@ -873,11 +873,16 @@ class Abstract_Wallet(AddressSynchronizer, ABC): item['value'] = Satoshis(value) balance += value item['balance'] = Satoshis(balance) - if fx: - timestamp = item['timestamp'] or now - fiat_value = value / Decimal(bitcoin.COIN) * fx.timestamp_rate(timestamp) - item['fiat_value'] = Fiat(fiat_value, fx.ccy) - item['fiat_default'] = True + if fx and fx.is_enabled() and fx.get_history_config(): + txid = item.get('txid') + if not item.get('lightning') and txid: + fiat_fields = self.get_tx_item_fiat(txid, value, fx, item['fee_sat']) + item.update(fiat_fields) + else: + timestamp = item['timestamp'] or now + fiat_value = value / Decimal(bitcoin.COIN) * fx.timestamp_rate(timestamp) + item['fiat_value'] = Fiat(fiat_value, fx.ccy) + item['fiat_default'] = True return transactions @profiler t@@ -1973,11 +1978,14 @@ class Abstract_Wallet(AddressSynchronizer, ABC): lp = sum([coin.value_sats() for coin in coins]) * p / Decimal(COIN) return lp - ap - def average_price(self, txid, price_func, ccy): + def average_price(self, txid, price_func, ccy) -> Decimal: """ Average acquisition price of the inputs of a transaction """ input_value = 0 total_price = 0 - for addr in self.db.get_txi_addresses(txid): + txi_addresses = self.db.get_txi_addresses(txid) + if not txi_addresses: + return Decimal('NaN') + for addr in txi_addresses: d = self.db.get_txi_addr(txid, addr) for ser, v in d: input_value += v t@@ -1987,7 +1995,7 @@ class Abstract_Wallet(AddressSynchronizer, ABC): def clear_coin_price_cache(self): self._coin_price_cache = {} - def coin_price(self, txid, price_func, ccy, txin_value): + def coin_price(self, txid, price_func, ccy, txin_value) -> Decimal: """ Acquisition price of a coin. This assumes that either all inputs are mine, or no input is mine.