wallet.get_tx_parents: populate cache regardless of self.is_up_to_date()
Fixes #8315
This commit is contained in:
@@ -134,8 +134,8 @@ class UTXOList(MyTreeView):
|
|||||||
utxo = self._utxo_dict[key]
|
utxo = self._utxo_dict[key]
|
||||||
utxo_item = [self.std_model.item(row, col) for col in self.Columns]
|
utxo_item = [self.std_model.item(row, col) for col in self.Columns]
|
||||||
txid = utxo.prevout.txid.hex()
|
txid = utxo.prevout.txid.hex()
|
||||||
parents = self.wallet.get_tx_parents(txid)
|
num_parents = self.wallet.get_num_parents(txid)
|
||||||
utxo_item[self.Columns.PARENTS].setText('%6s'%len(parents))
|
utxo_item[self.Columns.PARENTS].setText('%6s'%num_parents if num_parents else '-')
|
||||||
label = self.wallet.get_label_for_txid(txid) or ''
|
label = self.wallet.get_label_for_txid(txid) or ''
|
||||||
utxo_item[self.Columns.LABEL].setText(label)
|
utxo_item[self.Columns.LABEL].setText(label)
|
||||||
SELECTED_TO_SPEND_TOOLTIP = _('Coin selected to be spent')
|
SELECTED_TO_SPEND_TOOLTIP = _('Coin selected to be spent')
|
||||||
|
|||||||
@@ -884,17 +884,20 @@ class Abstract_Wallet(ABC, Logger, EventListener):
|
|||||||
is_related_to_wallet=is_relevant,
|
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]]]:
|
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
|
txid -> list of parent txids
|
||||||
"""
|
"""
|
||||||
if not self.is_up_to_date():
|
|
||||||
return {}
|
|
||||||
with self.lock, self.transaction_lock:
|
with self.lock, self.transaction_lock:
|
||||||
if self._last_full_history is None:
|
if self._last_full_history is None:
|
||||||
self._last_full_history = self.get_full_history(None, include_lightning=False)
|
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():
|
for _txid in self._last_full_history.keys():
|
||||||
self.get_tx_parents(_txid)
|
self.get_tx_parents(_txid)
|
||||||
|
|
||||||
@@ -924,7 +927,8 @@ class Abstract_Wallet(ABC, Logger, EventListener):
|
|||||||
|
|
||||||
for _txid in parents + uncles:
|
for _txid in parents + uncles:
|
||||||
if _txid in self._last_full_history.keys():
|
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
|
result[txid] = parents, uncles
|
||||||
self._tx_parents_cache[txid] = result
|
self._tx_parents_cache[txid] = result
|
||||||
return result
|
return result
|
||||||
|
|||||||
Reference in New Issue
Block a user