Browse Source

adb: simplify get_conflicting_transactions

master
SomberNight 2 years ago
parent
commit
de2007e90c
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 17
      electrum/address_synchronizer.py

17
electrum/address_synchronizer.py

@ -221,7 +221,7 @@ class AddressSynchronizer(Logger, EventListener):
self.synchronizer.add(address)
self.up_to_date_changed()
def get_conflicting_transactions(self, tx_hash, tx: Transaction, include_self=False):
def get_conflicting_transactions(self, tx: Transaction, *, include_self: bool = False) -> Set[str]:
"""Returns a set of transaction hashes from the wallet history that are
directly conflicting with tx, i.e. they have common outpoints being
spent with tx.
@ -243,12 +243,13 @@ class AddressSynchronizer(Logger, EventListener):
# annoying assert that has revealed several bugs over time:
assert self.db.get_transaction(spending_tx_hash), "spending tx not in wallet db"
conflicting_txns |= {spending_tx_hash}
if tx_hash in conflicting_txns:
# this tx is already in history, so it conflicts with itself
if len(conflicting_txns) > 1:
raise Exception('Found conflicting transactions already in wallet history.')
if not include_self:
conflicting_txns -= {tx_hash}
if tx_hash := tx.txid():
if tx_hash in conflicting_txns:
# this tx is already in history, so it conflicts with itself
if len(conflicting_txns) > 1:
raise Exception('Found conflicting transactions already in wallet history.')
if not include_self:
conflicting_txns -= {tx_hash}
return conflicting_txns
def get_transaction(self, txid: str) -> Optional[Transaction]:
@ -298,7 +299,7 @@ class AddressSynchronizer(Logger, EventListener):
# When this method exits, there must NOT be any conflict, so
# either keep this txn and remove all conflicting (along with dependencies)
# or drop this txn
conflicting_txns = self.get_conflicting_transactions(tx_hash, tx)
conflicting_txns = self.get_conflicting_transactions(tx)
if conflicting_txns:
existing_mempool_txn = any(
self.get_tx_height(tx_hash2).height in (TX_HEIGHT_UNCONFIRMED, TX_HEIGHT_UNCONF_PARENT)

Loading…
Cancel
Save