diff --git a/gui/qt/history_list.py b/gui/qt/history_list.py index a5ca141b3..32aec4982 100644 --- a/gui/qt/history_list.py +++ b/gui/qt/history_list.py @@ -182,19 +182,26 @@ class HistoryList(MyTreeWidget): menu.addAction(_("View on block explorer"), lambda: webbrowser.open(tx_URL)) menu.exec_(self.viewport().mapToGlobal(position)) - def remove_local_tx(self, tx_hash): - answer = QMessageBox.question(self.parent, - _("Please confirm"), - _("Are you sure you want to remove this transaction?"), - QMessageBox.Yes, - QMessageBox.No) + def remove_local_tx(self, delete_tx): + to_delete = {delete_tx} + to_delete |= self.wallet.get_depending_transactions(delete_tx) + + question = _("Are you sure you want to remove this transaction?") + if len(to_delete) > 1: + question = _( + "Are you sure you want to remove this transaction and {} child transactions?".format(len(to_delete) - 1) + ) + + answer = QMessageBox.question(self.parent, _("Please confirm"), question, QMessageBox.Yes, QMessageBox.No) if answer == QMessageBox.No: return - self.wallet.remove_transaction(tx_hash) + for tx in to_delete: + self.wallet.remove_transaction(tx) root = self.invisibleRootItem() child_count = root.childCount() + _offset = 0 for i in range(child_count): - item = root.child(i) - if item.data(0, Qt.UserRole) == tx_hash: + item = root.child(i - _offset) + if item.data(0, Qt.UserRole) in to_delete: root.removeChild(item) - return + _offset += 1 diff --git a/lib/wallet.py b/lib/wallet.py index 8a7770d82..ae2c2a745 100644 --- a/lib/wallet.py +++ b/lib/wallet.py @@ -1377,6 +1377,16 @@ class Abstract_Wallet(PrintError): index = self.get_address_index(addr) return self.keystore.decrypt_message(index, message, password) + def get_depending_transactions(self, tx_hash): + """Returns all (grand-)children of tx_hash in this wallet.""" + children = set() + for other_hash, tx in self.transactions.items(): + for input in (tx.inputs()): + if input["prevout_hash"] == tx_hash: + children.add(other_hash) + children |= self.get_depending_transactions(other_hash) + return children + class Simple_Wallet(Abstract_Wallet): # wallet with a single keystore