mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
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:
parent
1526bc9ccf
commit
6b195437ed
3 changed files with 10 additions and 7 deletions
|
@ -80,7 +80,7 @@ class AddressSynchronizer(Logger):
|
||||||
# locks: if you need to take multiple ones, acquire them in the order they are defined here!
|
# locks: if you need to take multiple ones, acquire them in the order they are defined here!
|
||||||
self.lock = threading.RLock()
|
self.lock = threading.RLock()
|
||||||
self.transaction_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.
|
# Transactions pending verification. txid -> tx_height. Access with self.lock.
|
||||||
self.unverified_tx = defaultdict(int)
|
self.unverified_tx = defaultdict(int)
|
||||||
# true when synchronized
|
# true when synchronized
|
||||||
|
@ -566,7 +566,8 @@ class AddressSynchronizer(Logger):
|
||||||
return cached_local_height
|
return cached_local_height
|
||||||
return self.network.get_local_height() if self.network else self.db.get('stored_height', 0)
|
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:
|
with self.lock:
|
||||||
self.add_transaction(tx.txid(), tx)
|
self.add_transaction(tx.txid(), tx)
|
||||||
self.future_tx[tx.txid()] = num_blocks
|
self.future_tx[tx.txid()] = num_blocks
|
||||||
|
@ -581,9 +582,9 @@ class AddressSynchronizer(Logger):
|
||||||
height = self.unverified_tx[tx_hash]
|
height = self.unverified_tx[tx_hash]
|
||||||
return TxMinedInfo(height=height, conf=0)
|
return TxMinedInfo(height=height, conf=0)
|
||||||
elif tx_hash in self.future_tx:
|
elif tx_hash in self.future_tx:
|
||||||
# FIXME this is ugly
|
num_blocks_remainining = self.future_tx[tx_hash]
|
||||||
conf = self.future_tx[tx_hash]
|
assert num_blocks_remainining > 0, num_blocks_remainining
|
||||||
return TxMinedInfo(height=TX_HEIGHT_FUTURE, conf=conf)
|
return TxMinedInfo(height=TX_HEIGHT_FUTURE, conf=-num_blocks_remainining)
|
||||||
else:
|
else:
|
||||||
# local transaction
|
# local transaction
|
||||||
return TxMinedInfo(height=TX_HEIGHT_LOCAL, conf=0)
|
return TxMinedInfo(height=TX_HEIGHT_LOCAL, conf=0)
|
||||||
|
|
|
@ -1024,7 +1024,7 @@ def ignore_exceptions(func):
|
||||||
|
|
||||||
class TxMinedInfo(NamedTuple):
|
class TxMinedInfo(NamedTuple):
|
||||||
height: int # height of block that mined tx
|
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
|
timestamp: Optional[int] = None # timestamp of block that mined tx
|
||||||
txpos: Optional[int] = None # position of tx in serialized block
|
txpos: Optional[int] = None # position of tx in serialized block
|
||||||
header_hash: Optional[str] = None # hash of block that mined tx
|
header_hash: Optional[str] = None # hash of block that mined tx
|
||||||
|
|
|
@ -817,7 +817,9 @@ class Abstract_Wallet(AddressSynchronizer):
|
||||||
conf = tx_mined_info.conf
|
conf = tx_mined_info.conf
|
||||||
timestamp = tx_mined_info.timestamp
|
timestamp = tx_mined_info.timestamp
|
||||||
if height == TX_HEIGHT_FUTURE:
|
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:
|
if conf == 0:
|
||||||
tx = self.db.get_transaction(tx_hash)
|
tx = self.db.get_transaction(tx_hash)
|
||||||
if not tx:
|
if not tx:
|
||||||
|
|
Loading…
Add table
Reference in a new issue