transaction: (move-only) move some methods from Tx to PartialTx cls
What changed, and why it matters
This commit is a pure code reorganization: four helper methods were moved from the base Transaction class to the more specific PartialTransaction subclass. The code itself is unchanged, and the commit message explicitly states it is 'move-only'. There is no security fix or behavior change visible in the diff.
No action required. This is a non-functional refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff relocates replace_output_address, get_change_outputs, has_change, and get_dummy_output from Transaction to PartialTransaction. The methods already used PartialTxOutput and were documented as assuming isinstance(self, PartialTransaction). No logic changes, no new validation, no bug fixes, and no security-relevant modifications are present.
Changed components
electrum/transaction.pyInspect captured patch +24 / −24
diff --git a/electrum/transaction.py b/electrum/transaction.py
index 7126e0c..eed3820 100644
--- a/electrum/transaction.py
+++ b/electrum/transaction.py
@@ -1436,30 +1436,6 @@ class Transaction:
script = bitcoin.address_to_script(addr)
return self.get_output_idxs_from_scriptpubkey(script)
- def replace_output_address(self, old_address: str, new_address: str) -> None:
- idx = list(self.get_output_idxs_from_address(old_address))
- assert len(idx) == 1
- amount = self._outputs[idx[0]].value
- funding_output = PartialTxOutput.from_address_and_value(new_address, amount)
- old_output = PartialTxOutput.from_address_and_value(old_address, amount)
- self._outputs.remove(old_output)
- self.add_outputs([funding_output])
- delattr(self, '_script_to_output_idx')
-
- def get_change_outputs(self):
- return [o for o in self._outputs if o.is_change]
-
- def has_change(self):
- return len(self.get_change_outputs()) > 0
-
- def get_dummy_output(self, dummy_addr: str) -> Optional['PartialTxOutput']:
- idxs = self.get_output_idxs_from_address(dummy_addr)
- if not idxs:
- return
- assert len(idxs) == 1
- for i in idxs:
- return self.outputs()[i]
-
def output_value_for_address(self, addr):
# assumes exactly one output has that address
for o in self.outputs():
@@ -2434,6 +2410,30 @@ class PartialTransaction(Transaction):
self.BIP69_sort(inputs=False)
self.invalidate_ser_cache()
+ def replace_output_address(self, old_address: str, new_address: str) -> None:
+ idx = list(self.get_output_idxs_from_address(old_address))
+ assert len(idx) == 1
+ amount = self._outputs[idx[0]].value
+ funding_output = PartialTxOutput.from_address_and_value(new_address, amount)
+ old_output = PartialTxOutput.from_address_and_value(old_address, amount)
+ self._outputs.remove(old_output)
+ self.add_outputs([funding_output])
+ delattr(self, '_script_to_output_idx')
+
+ def get_change_outputs(self):
+ return [o for o in self._outputs if o.is_change]
+
+ def has_change(self):
+ return len(self.get_change_outputs()) > 0
+
+ def get_dummy_output(self, dummy_addr: str) -> Optional['PartialTxOutput']:
+ idxs = self.get_output_idxs_from_address(dummy_addr)
+ if not idxs:
+ return
+ assert len(idxs) == 1
+ for i in idxs:
+ return self.outputs()[i]
+
def set_rbf(self, rbf: bool) -> None:
nSequence = 0xffffffff - (2 if rbf else 1)
for txin in self.inputs():
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.