wallet: "future" txns num conf is now negative

flipped the sign so that TxMinedInfo.conf can be consistently used in inequalities
This commit is contained in:
SomberNight 2019-11-21 05:01:59 +01:00
parent 1526bc9ccf
commit 6b195437ed
No known key found for this signature in database
GPG key ID: B33B5F232C6271E9
3 changed files with 10 additions and 7 deletions

View file

@ -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)

View file

@ -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

View file

@ -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: