diff --git a/electrum/address_synchronizer.py b/electrum/address_synchronizer.py index f40e3fc37..ee4f8c51b 100644 --- a/electrum/address_synchronizer.py +++ b/electrum/address_synchronizer.py @@ -80,7 +80,7 @@ class AddressSynchronizer(Logger): # locks: if you need to take multiple ones, acquire them in the order they are defined here! self.lock = threading.RLock() self.transaction_lock = threading.RLock() - self.future_tx = {} # txid -> blocks remaining + self.future_tx = {} # type: Dict[str, int] # txid -> blocks remaining # Transactions pending verification. txid -> tx_height. Access with self.lock. self.unverified_tx = defaultdict(int) # true when synchronized @@ -566,7 +566,8 @@ class AddressSynchronizer(Logger): return cached_local_height return self.network.get_local_height() if self.network else self.db.get('stored_height', 0) - def add_future_tx(self, tx: Transaction, num_blocks): + def add_future_tx(self, tx: Transaction, num_blocks: int) -> None: + assert num_blocks > 0, num_blocks with self.lock: self.add_transaction(tx.txid(), tx) self.future_tx[tx.txid()] = num_blocks @@ -581,9 +582,9 @@ class AddressSynchronizer(Logger): height = self.unverified_tx[tx_hash] return TxMinedInfo(height=height, conf=0) elif tx_hash in self.future_tx: - # FIXME this is ugly - conf = self.future_tx[tx_hash] - return TxMinedInfo(height=TX_HEIGHT_FUTURE, conf=conf) + num_blocks_remainining = self.future_tx[tx_hash] + assert num_blocks_remainining > 0, num_blocks_remainining + return TxMinedInfo(height=TX_HEIGHT_FUTURE, conf=-num_blocks_remainining) else: # local transaction return TxMinedInfo(height=TX_HEIGHT_LOCAL, conf=0) diff --git a/electrum/util.py b/electrum/util.py index 84598ee68..c60a29770 100644 --- a/electrum/util.py +++ b/electrum/util.py @@ -1024,7 +1024,7 @@ def ignore_exceptions(func): class TxMinedInfo(NamedTuple): height: int # height of block that mined tx - conf: Optional[int] = None # number of confirmations (None means unknown) + conf: Optional[int] = None # number of confirmations, SPV verified (None means unknown) timestamp: Optional[int] = None # timestamp of block that mined tx txpos: Optional[int] = None # position of tx in serialized block header_hash: Optional[str] = None # hash of block that mined tx diff --git a/electrum/wallet.py b/electrum/wallet.py index da27c51c9..1919fc6b7 100644 --- a/electrum/wallet.py +++ b/electrum/wallet.py @@ -817,7 +817,9 @@ class Abstract_Wallet(AddressSynchronizer): conf = tx_mined_info.conf timestamp = tx_mined_info.timestamp if height == TX_HEIGHT_FUTURE: - return 2, 'in %d blocks'%conf + assert conf < 0, conf + num_blocks_remainining = -conf + return 2, f'in {num_blocks_remainining} blocks' if conf == 0: tx = self.db.get_transaction(tx_hash) if not tx: