transaction: add set_mined_info setter to TxInput
What changed, and why it matters
This commit is a simple code cleanup: it replaces two repeated lines that set a transaction input's block height and position with a single helper method called set_mined_info. There is no change in behavior, no bug fix, and no security relevance visible in the diff.
No security action needed. Treat as ordinary refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change introduces TxInput.set_mined_info(self, info: TxMinedInfo), which assigns block_height and block_txpos from a TxMinedInfo object. Two call sites in address_synchronizer.py and wallet.py are updated to use this setter. The logic is functionally identical to the previous inline assignments; it only deduplicates code.
Changed components
electrum/transaction.pyelectrum/address_synchronizer.pyelectrum/wallet.pyInspect captured patch +7 / −7
### electrum/address_synchronizer.py
@@ -275,9 +275,7 @@ def get_transaction(self, txid: str) -> Optional[Transaction]:
if tx:
tx.deserialize()
for txin in tx._inputs:
- tx_mined_info = self.get_tx_height(txin.prevout.txid.hex())
- txin.block_height = tx_mined_info.height()
- txin.block_txpos = tx_mined_info.txpos
+ txin.set_mined_info(self.get_tx_height(txin.prevout.txid.hex()))
return tx
def add_transaction(self, tx: Transaction, *, allow_unrelated=False, is_new=True) -> bool:
### electrum/transaction.py
@@ -51,7 +51,7 @@
)
from .crypto import sha256d, sha256
from .logging import get_logger
-from .util import ShortID, OldTaskGroup
+from .util import ShortID, OldTaskGroup, TxMinedInfo
from .descriptor import Descriptor, MissingSolutionPiece, create_dummy_descriptor_from_address, DUMMY_DER_SIG
if TYPE_CHECKING:
@@ -363,6 +363,10 @@ def get_block_based_relative_locktime(self) -> Optional[int]:
return self.nsequence & 0xffff
return None
+ def set_mined_info(self, info: TxMinedInfo) -> None:
+ self.block_height = info.height()
+ self.block_txpos = info.txpos
+
def has_short_id(self) -> bool:
return (self.block_height is not None and self.block_height > 0
and self.block_txpos is not None and self.block_txpos >= 0)
### electrum/wallet.py
@@ -2737,9 +2737,7 @@ def add_input_info(
txin.script_descriptor = desc
txin.is_mine = True
self._add_txinout_derivation_info(txin, address, only_der_suffix=only_der_suffix)
- tx_mined_info = self.adb.get_tx_height(txin.prevout.txid.hex())
- txin.block_height = tx_mined_info.height()
- txin.block_txpos = tx_mined_info.txpos
+ txin.set_mined_info(self.adb.get_tx_height(txin.prevout.txid.hex()))
def has_support_for_slip_19_ownership_proofs(self) -> bool:
return FalseWhy this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.