From 60c493dc156620931a0b22170ab8c76cc5349b20 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Wed, 17 Aug 2022 10:35:43 +0200 Subject: [PATCH] adb: trigger adb_added_tx event only if the transaction is new --- electrum/address_synchronizer.py | 7 ++++--- electrum/lnwatcher.py | 2 +- electrum/wallet.py | 5 ++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/electrum/address_synchronizer.py b/electrum/address_synchronizer.py index 33f1e226e..e2a3d74e5 100644 --- a/electrum/address_synchronizer.py +++ b/electrum/address_synchronizer.py @@ -242,7 +242,7 @@ class AddressSynchronizer(Logger, EventListener): def get_transaction(self, txid: str) -> Transaction: return self.db.get_transaction(txid) - def add_transaction(self, tx: Transaction, *, allow_unrelated=False, notify_GUI=True) -> bool: + def add_transaction(self, tx: Transaction, *, allow_unrelated=False, is_new=True) -> bool: """ Returns whether the tx was successfully added to the wallet history. Note that a transaction may need to be added several times, if our @@ -337,7 +337,8 @@ class AddressSynchronizer(Logger, EventListener): # save self.db.add_transaction(tx_hash, tx) self.db.add_num_inputs_to_tx(tx_hash, len(tx.inputs())) - util.trigger_callback('adb_added_tx', self, tx_hash, notify_GUI) + if is_new: + util.trigger_callback('adb_added_tx', self, tx_hash) return True def remove_transaction(self, tx_hash: str) -> None: @@ -424,7 +425,7 @@ class AddressSynchronizer(Logger, EventListener): tx = self.db.get_transaction(tx_hash) if tx is None: continue - self.add_transaction(tx, allow_unrelated=True, notify_GUI=False) + self.add_transaction(tx, allow_unrelated=True, is_new=False) # Store fees for tx_hash, fee_sat in tx_fees.items(): diff --git a/electrum/lnwatcher.py b/electrum/lnwatcher.py index 0f8fb9ea6..9760761b2 100644 --- a/electrum/lnwatcher.py +++ b/electrum/lnwatcher.py @@ -529,7 +529,7 @@ class LNWalletWatcher(LNWatcher): # we may have a tx with a different fee, in which case it will be replaced if not old_tx or (old_tx and old_tx.txid() != new_tx.txid()): try: - tx_was_added = self.adb.add_transaction(new_tx, notify_GUI=(old_tx is None)) + tx_was_added = self.adb.add_transaction(new_tx, is_new=(old_tx is None)) except Exception as e: self.logger.info(f'could not add future tx: {name}. prevout: {prevout} {str(e)}') tx_was_added = False diff --git a/electrum/wallet.py b/electrum/wallet.py index a47af2075..ffec64f55 100644 --- a/electrum/wallet.py +++ b/electrum/wallet.py @@ -476,7 +476,7 @@ class Abstract_Wallet(ABC, Logger, EventListener): self.logger.info(f'set_up_to_date: {up_to_date}') @event_listener - def on_event_adb_added_tx(self, adb, tx_hash, notify_GUI): + def on_event_adb_added_tx(self, adb, tx_hash): if self.adb != adb: return tx = self.db.get_transaction(tx_hash) @@ -489,8 +489,7 @@ class Abstract_Wallet(ABC, Logger, EventListener): if self.lnworker: self.lnworker.maybe_add_backup_from_tx(tx) self._update_invoices_and_reqs_touched_by_tx(tx_hash) - if notify_GUI: - util.trigger_callback('new_transaction', self, tx) + util.trigger_callback('new_transaction', self, tx) @event_listener def on_event_adb_added_verified_tx(self, adb, tx_hash):