Skip to content

feat: add transaction input/output mutation methods#177

Open
shivv23 wants to merge 1 commit into
karask:masterfrom
shivv23:transaction-io-mutation
Open

feat: add transaction input/output mutation methods#177
shivv23 wants to merge 1 commit into
karask:masterfrom
shivv23:transaction-io-mutation

Conversation

@shivv23

@shivv23 shivv23 commented Jun 24, 2026

Copy link
Copy Markdown

Description

Adds 6 mutation methods to the Transaction class, directly addressing the TODO list priority item:

  • add_input(txin) — append an input; auto-appends empty TxWitnessInput([]) when has_segwit=True
  • add_output(txout) — append an output
  • remove_input(index) — remove by index; also removes the corresponding witness entry for segwit transactions
  • remove_output(index) — remove by index
  • update_input(index, txin) — replace input at index
  • update_output(index, txout) — replace output at index

All remove/update methods raise IndexError on out-of-bounds access, matching Python stdlib list semantics.

Testing

  • 40 new tests in ests/test_transaction_mutation.py covering all 6 methods, round-trip serialization, segwit/non-segwit handling, empty transaction edge cases, negative indices, copy isolation, and multi-input witness management
  • All 240 tests pass (200 existing + 40 new) with no regressions

Related

Closes the main TODO item: influences set_witness (add_input should add the empty witness immediately?)

Add add_input, add_output, remove_input, remove_output, update_input,
and update_output methods to the Transaction class.

- add_input/remove_input automatically manage the segwit witness list
  to keep it parallel with inputs, answering the maintainer's TODO:
  'influences set_witness (add_input should add the empty witness
  immediately?)'
- remove_input/remove_output/update_input/update_output raise
  IndexError for out-of-bounds access, matching Python list semantics
- 40 tests covering all methods, round-trip serialization, and edge
  cases (empty tx, segwit/non-segwit, negative indices, copy isolation)

Closes the main item on the project TODO list.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant