From d94d443082a6f71b651625e13318ad6b05b11318 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Sun, 11 Jul 2021 16:57:01 +0200 Subject: [PATCH] wallet: fire "request_status" event also when conf number changes --- electrum/address_synchronizer.py | 4 ++-- electrum/wallet.py | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/electrum/address_synchronizer.py b/electrum/address_synchronizer.py index 37fb3b71f..5ed4a35ae 100644 --- a/electrum/address_synchronizer.py +++ b/electrum/address_synchronizer.py @@ -36,7 +36,7 @@ from .util import profiler, bfh, TxMinedInfo, UnrelatedTransactionException, wit from .transaction import Transaction, TxOutput, TxInput, PartialTxInput, TxOutpoint, PartialTransaction from .synchronizer import Synchronizer from .verifier import SPV -from .blockchain import hash_header +from .blockchain import hash_header, Blockchain from .i18n import _ from .logging import Logger @@ -591,7 +591,7 @@ class AddressSynchronizer(Logger): with self.lock: return dict(self.unverified_tx) # copy - def undo_verifications(self, blockchain, above_height): + def undo_verifications(self, blockchain: Blockchain, above_height: int) -> Set[str]: '''Used by the verifier when a reorg has happened''' txs = set() with self.lock: diff --git a/electrum/wallet.py b/electrum/wallet.py index 1c1f1d0ec..0fbc984f2 100644 --- a/electrum/wallet.py +++ b/electrum/wallet.py @@ -2074,7 +2074,7 @@ class Abstract_Wallet(AddressSynchronizer, ABC): def delete_address(self, address: str) -> None: raise Exception("this wallet cannot delete addresses") - def get_onchain_request_status(self, r): + def get_onchain_request_status(self, r: OnchainInvoice) -> Tuple[bool, Optional[int]]: address = r.get_address() amount = r.get_amount_sat() received, sent = self.get_addr_io(address) @@ -2231,6 +2231,24 @@ class Abstract_Wallet(AddressSynchronizer, ABC): def receive_tx_callback(self, tx_hash, tx, tx_height): super().receive_tx_callback(tx_hash, tx, tx_height) + self._update_request_statuses_touched_by_tx(tx_hash) + + def add_verified_tx(self, tx_hash, info): + super().add_verified_tx(tx_hash, info) + self._update_request_statuses_touched_by_tx(tx_hash) + + def undo_verifications(self, blockchain, above_height): + reorged_txids = super().undo_verifications(blockchain, above_height) + for txid in reorged_txids: + self._update_request_statuses_touched_by_tx(txid) + + def _update_request_statuses_touched_by_tx(self, tx_hash: str) -> None: + # FIXME in some cases if tx2 replaces unconfirmed tx1 in the mempool, we are not called. + # For a given receive request, if tx1 touches it but tx2 does not, then + # we were called when tx1 was added, but we will not get called when tx2 replaces tx1. + tx = self.db.get_transaction(tx_hash) + if tx is None: + return for txo in tx.outputs(): addr = txo.address if addr in self.receive_requests: