1
0

wallet.remove_transaction: also rm dependent/child txs

Main motivation is that I often use wallet.remove_transaction
from the Qt console, and would find this behaviour more intuitive.
Note that previously if one were to call this on a tx with children,
the crash reporter would appear with "wallet.get_history() failed balance sanity-check".

related: https://github.com/spesmilo/electrum/issues/6960#issuecomment-764716533
This commit is contained in:
SomberNight
2021-01-21 18:05:48 +01:00
parent 4f3a28b87e
commit c4e9afa019
4 changed files with 23 additions and 21 deletions

View File

@@ -292,11 +292,7 @@ class AddressSynchronizer(Logger):
# this is a local tx that conflicts with non-local txns; drop.
return False
# keep this txn and remove all conflicting
to_remove = set()
to_remove |= conflicting_txns
for conflicting_tx_hash in conflicting_txns:
to_remove |= self.get_depending_transactions(conflicting_tx_hash)
for tx_hash2 in to_remove:
for tx_hash2 in conflicting_txns:
self.remove_transaction(tx_hash2)
# add inputs
def add_value_from_prev_output():
@@ -342,6 +338,19 @@ class AddressSynchronizer(Logger):
return True
def remove_transaction(self, tx_hash: str) -> None:
"""Removes a transaction AND all its dependents/children
from the wallet history.
"""
with self.lock, self.transaction_lock:
to_remove = {tx_hash}
to_remove |= self.get_depending_transactions(tx_hash)
for txid in to_remove:
self._remove_transaction(txid)
def _remove_transaction(self, tx_hash: str) -> None:
"""Removes a single transaction from the wallet history, and attempts
to undo all effects of the tx (spending inputs, creating outputs, etc).
"""
def remove_from_spent_outpoints():
# undo spends in spent_outpoints
if tx is not None: