What changed, and why it matters
This is a small code cleanup in Electrum's transaction handling. It simplifies how raw transaction bytes are converted to hex strings. There is no obvious security bug being fixed here; it appears to be a follow-up simplification to a previous change.
No security action required. Treat as routine refactoring. If reviewing in context of a prior commit, verify that the previous commit did not introduce a vulnerability that this cleanup is meant to address.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors convert_raw_tx_to_hex() in electrum/transaction.py. Previously, the function kept a separate raw_unstripped reference so that if the input was raw bytes, it could return those bytes as hex without first stripping whitespace. The new code treats bytes and bytearray uniformly and calls .hex() directly. The tx_from_any() function only gets a formatting change (trailing comma and closing parenthesis on a new line). No security-relevant behavior change is evident from the diff alone.
Changed components
electrum/transaction.pyconvert_raw_tx_to_hex()tx_from_any()Inspect captured patch +5 / −7
diff --git a/electrum/transaction.py b/electrum/transaction.py
index 591d1ed..98af76d 100644
--- a/electrum/transaction.py
+++ b/electrum/transaction.py
@@ -1491,7 +1491,6 @@ def convert_raw_tx_to_hex(raw: Union[str, bytes]) -> str:
raw tx hex string."""
if not raw:
raise ValueError("empty string")
- raw_unstripped = raw
# try hex
try:
return binascii.unhexlify(raw).hex()
@@ -1508,18 +1507,17 @@ def convert_raw_tx_to_hex(raw: Union[str, bytes]) -> str:
return base64.b64decode(raw, validate=True).hex()
except Exception:
pass
- # raw bytes (do not strip whitespaces in this case)
- if isinstance(raw, bytearray):
- raw = bytes(raw)
- if isinstance(raw_unstripped, bytes):
- return raw_unstripped.hex()
+ # raw bytes
+ if isinstance(raw, (bytes, bytearray)):
+ return raw.hex()
raise ValueError(f"failed to recognize transaction encoding for txt: {raw[:30]}...")
def tx_from_any(
raw: Union[str, bytes], *,
deserialize: bool = True,
- sanitize: bool = True) -> Union['PartialTransaction', 'Transaction']:
+ sanitize: bool = True,
+) -> Union['PartialTransaction', 'Transaction']:
# re.sub is expensive, set sanitize to False if raw data is not from user input
if isinstance(raw, str) and sanitize:
# remove all whitespace characters, anywhere, for convenience
Why this scored 11/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.