add future transactions to address synchronizer
This commit is contained in:
@@ -43,6 +43,7 @@ if TYPE_CHECKING:
|
||||
from .json_db import JsonDB
|
||||
|
||||
|
||||
TX_HEIGHT_FUTURE = -3
|
||||
TX_HEIGHT_LOCAL = -2
|
||||
TX_HEIGHT_UNCONF_PARENT = -1
|
||||
TX_HEIGHT_UNCONFIRMED = 0
|
||||
@@ -71,6 +72,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
|
||||
# Transactions pending verification. txid -> tx_height. Access with self.lock.
|
||||
self.unverified_tx = defaultdict(int)
|
||||
# true when synchronized
|
||||
@@ -556,6 +558,11 @@ 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, num_blocks):
|
||||
with self.lock:
|
||||
self.add_transaction(tx.txid(), tx)
|
||||
self.future_tx[tx.txid()] = num_blocks
|
||||
|
||||
def get_tx_height(self, tx_hash: str) -> TxMinedInfo:
|
||||
with self.lock:
|
||||
verified_tx_mined_info = self.db.get_verified_tx(tx_hash)
|
||||
@@ -565,6 +572,9 @@ class AddressSynchronizer(Logger):
|
||||
elif tx_hash in self.unverified_tx:
|
||||
height = self.unverified_tx[tx_hash]
|
||||
return TxMinedInfo(height=height, conf=0)
|
||||
elif tx_hash in self.future_tx:
|
||||
conf = self.future_tx[tx_hash]
|
||||
return TxMinedInfo(height=TX_HEIGHT_FUTURE, conf=conf)
|
||||
else:
|
||||
# local transaction
|
||||
return TxMinedInfo(height=TX_HEIGHT_LOCAL, conf=0)
|
||||
|
||||
Reference in New Issue
Block a user