What changed, and why it matters
This is a small internal code cleanup in the Electrum Bitcoin wallet. It moves the logic that builds a compact transaction identifier (like '123x4') into one shared helper method, and removes a duplicate helper class. There is no user-facing behavior change and no security fix.
No action required. This is a benign refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit consolidates construction of the ‘short_id’ string across Qt GUI code and util.py. Previously, transaction_dialog.py and utxo_dialog.py each extracted tx_height and tx_pos from TxMinedInfo and assembled the short ID manually. Now they call TxMinedInfo.short_id(), which was updated to return the formatted string only when height > 0 and txpos >= 0. The standalone ShortID class is no longer imported. The change is behavior-preserving: the same conditions produce the same output, and the assert was replaced with an equivalent guard.
Changed components
electrum/gui/qt/transaction_dialog.pyelectrum/gui/qt/utxo_dialog.pyelectrum/util.pyInspect captured patch +7 / −13
### electrum/gui/qt/transaction_dialog.py
@@ -47,7 +47,7 @@
from electrum.plugin import run_hook
from electrum.transaction import SerializationError, Transaction, PartialTransaction, TxOutpoint, TxinDataFetchProgress
from electrum.logging import get_logger
-from electrum.util import (ShortID, get_asyncio_loop, UI_UNIT_NAME_TXSIZE_VBYTES, delta_time_str,
+from electrum.util import (get_asyncio_loop, UI_UNIT_NAME_TXSIZE_VBYTES, delta_time_str,
UserCancelled)
from electrum.network import Network
from electrum.wallet import TxSighashRiskLevel, TxSighashDanger
@@ -278,16 +278,12 @@ def insert_tx_io(
o_text.clear()
o_text.setFont(QFont(MONOSPACE_FONT))
o_text.setReadOnly(True)
- tx_height, tx_pos = None, None
tx_hash = self.tx.txid()
- if tx_hash:
- tx_mined_info = self.wallet.adb.get_tx_height(tx_hash)
- tx_height = tx_mined_info.height()
- tx_pos = tx_mined_info.txpos
+ tx_mined_info = self.wallet.adb.get_tx_height(tx_hash) if tx_hash else None
cursor = o_text.textCursor()
for txout_idx, o in enumerate(self.tx.outputs()):
- if tx_height is not None and tx_pos is not None and tx_pos >= 0:
- short_id = ShortID.from_components(tx_height, tx_pos, txout_idx)
+ if tx_mined_info and tx_mined_info.short_id():
+ short_id = f"{tx_mined_info.short_id()}x{txout_idx}"
elif tx_hash:
short_id = TxOutpoint(bytes.fromhex(tx_hash), txout_idx).short_name()
else:
### electrum/gui/qt/utxo_dialog.py
@@ -108,9 +108,7 @@ def print_ascii_tree(_txid, prefix, is_last, is_uncle):
if _txid not in parents:
return
tx_mined_info = self.wallet.adb.get_tx_height(_txid)
- tx_height = tx_mined_info.height()
- tx_pos = tx_mined_info.txpos
- key = "%dx%d"%(tx_height, tx_pos) if tx_pos is not None else _txid[0:8]
+ key = tx_mined_info.short_id() or _txid[0:8]
label = self.wallet.get_label_for_txid(_txid) or ""
if _txid not in parents_copy:
label = '[duplicate]'
### electrum/util.py
@@ -1283,8 +1283,8 @@ def height(self) -> int:
return h
def short_id(self) -> Optional[str]:
- if self.txpos is not None and self.txpos >= 0:
- assert self.height() > 0
+ """'<height>x<txpos>' if mined and SPV-verified, else None."""
+ if self.height() > 0 and self.txpos is not None and self.txpos >= 0:
return f"{self.height()}x{self.txpos}"
return None
Why 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.