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. 5
      electrum/address_synchronizer.py

5
electrum/address_synchronizer.py

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

Loading…
Cancel
Save