transaction: SPV-verify TxInput.block_height and .spent_height

This commit is contained in:
SomberNight
2025-09-10 15:38:45 +00:00
parent b944371ffd
commit a4293c483e
2 changed files with 5 additions and 4 deletions

View File

@@ -140,6 +140,7 @@ class AddressSynchronizer(Logger, EventListener):
def get_address_history(self, addr: str) -> Dict[str, int]: def get_address_history(self, addr: str) -> Dict[str, int]:
"""Returns the history for the address, as a txid->height dict. """Returns the history for the address, as a txid->height dict.
In addition to what we have from the server, this includes local and future txns. In addition to what we have from the server, this includes local and future txns.
Note: heights are SPV-verified.
Also see related method db.get_addr_history, which stores the response from the server, Also see related method db.get_addr_history, which stores the response from the server,
so that only includes txns the server sees. so that only includes txns the server sees.
@@ -841,8 +842,8 @@ class AddressSynchronizer(Logger, EventListener):
@with_lock @with_lock
def get_addr_io(self, address: str): def get_addr_io(self, address: str):
h = self.get_address_history(address).items() h = self.get_address_history(address).items()
received = {} received = {} # type: Dict[str, tuple[int, int, int, bool]]
sent = {} sent = {} # type: Dict[str, tuple[str, int, int]]
for tx_hash, height in h: for tx_hash, height in h:
tx_mined_info = self.get_tx_height(tx_hash) tx_mined_info = self.get_tx_height(tx_hash)
txpos = tx_mined_info.txpos if tx_mined_info.txpos is not None else -1 txpos = tx_mined_info.txpos if tx_mined_info.txpos is not None else -1

View File

@@ -336,9 +336,9 @@ class TxInput:
self.witness = witness self.witness = witness
self._is_coinbase_output = is_coinbase_output self._is_coinbase_output = is_coinbase_output
# blockchain fields # blockchain fields
self.block_height = None # type: Optional[int] # height at which the TXO is mined; None means unknown. not SPV-ed. self.block_height = None # type: Optional[int] # height at which the TXO is mined; None means unknown. SPV-ed.
self.block_txpos = None # type: Optional[int] # position of tx in block, if TXO is mined; otherwise None or -1 self.block_txpos = None # type: Optional[int] # position of tx in block, if TXO is mined; otherwise None or -1
self.spent_height = None # type: Optional[int] # height at which the TXO got spent self.spent_height = None # type: Optional[int] # height at which the TXO got spent. SPV-ed.
self.spent_txid = None # type: Optional[str] # txid of the spender self.spent_txid = None # type: Optional[str] # txid of the spender
self._utxo = None # type: Optional[Transaction] self._utxo = None # type: Optional[Transaction]
self.__scriptpubkey = None # type: Optional[bytes] self.__scriptpubkey = None # type: Optional[bytes]