Browse Source

wallet.get_tx_parents: populate cache regardless of self.is_up_to_date()

Fixes #8315
master
ThomasV 3 years ago
parent
commit
6d392a67f9
  1. 4
      electrum/gui/qt/utxo_list.py
  2. 14
      electrum/wallet.py

4
electrum/gui/qt/utxo_list.py

@ -134,8 +134,8 @@ class UTXOList(MyTreeView):
utxo = self._utxo_dict[key]
utxo_item = [self.std_model.item(row, col) for col in self.Columns]
txid = utxo.prevout.txid.hex()
parents = self.wallet.get_tx_parents(txid)
utxo_item[self.Columns.PARENTS].setText('%6s'%len(parents))
num_parents = self.wallet.get_num_parents(txid)
utxo_item[self.Columns.PARENTS].setText('%6s'%num_parents if num_parents else '-')
label = self.wallet.get_label_for_txid(txid) or ''
utxo_item[self.Columns.LABEL].setText(label)
SELECTED_TO_SPEND_TOOLTIP = _('Coin selected to be spent')

14
electrum/wallet.py

@ -884,17 +884,20 @@ class Abstract_Wallet(ABC, Logger, EventListener):
is_related_to_wallet=is_relevant,
)
def get_num_parents(self, txid: str) -> Optional[int]:
if not self.is_up_to_date():
return
return len(self.get_tx_parents(txid))
def get_tx_parents(self, txid: str) -> Dict[str, Tuple[List[str], List[str]]]:
"""
recursively calls itself and returns a flat dict:
returns a flat dict:
txid -> list of parent txids
"""
if not self.is_up_to_date():
return {}
with self.lock, self.transaction_lock:
if self._last_full_history is None:
self._last_full_history = self.get_full_history(None, include_lightning=False)
# populate cache in chronological order to avoid recursion limit
# populate cache in chronological order
for _txid in self._last_full_history.keys():
self.get_tx_parents(_txid)
@ -924,7 +927,8 @@ class Abstract_Wallet(ABC, Logger, EventListener):
for _txid in parents + uncles:
if _txid in self._last_full_history.keys():
result.update(self.get_tx_parents(_txid))
p = self._tx_parents_cache[_txid]
result.update(p)
result[txid] = parents, uncles
self._tx_parents_cache[txid] = result
return result

Loading…
Cancel
Save