adb: trigger adb_added_tx event only if the transaction is new
This commit is contained in:
@@ -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():
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user