commit 6b195437ed191db0cfde67a364280982b47143bf
parent 1526bc9ccf1125cd2c8c650748116050da95d778
Author: SomberNight <somber.night@protonmail.com>
Date: Thu, 21 Nov 2019 05:01:59 +0100
wallet: "future" txns num conf is now negative
flipped the sign so that TxMinedInfo.conf can be consistently used in inequalities
Diffstat:
3 files changed, 10 insertions(+), 7 deletions(-)
diff --git 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
@@ -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
@@ -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: