Skip to content

Attach inputs and outputs added through PSBT2.AddInput and AddOutput - #1363

Merged
NicolasDorier merged 1 commit into
MetacoSA:masterfrom
allenpiscitello:fix/psbt2-add-attaches
Oct 27, 2026
Merged

NicolasDorier merged 1 commit into
MetacoSA:masterfrom
allenpiscitello:fix/psbt2-add-attaches

Conversation

@allenpiscitello

Copy link
Copy Markdown
Contributor

PSBT2.AddInput and PSBT2.AddOutput build a new input or output but never add it to the PSBT. Callers outside NBitcoin cannot attach it themselves, because PSBTInputList.Add and PSBTOutputList.Add are internal. So the PSBT is left unchanged.

Both methods now add what they build before returning it, like TxInList.Add and TxOutList.Add do. Also:

  • AddOutput reports "Outputs are not modifiable" instead of "Inputs are not modifiable".
  • An unused TxOut in AddOutput is removed.
  • AddOutputUsesOutputIndex no longer attaches the first output by hand, which would now add it twice. It was the only caller doing that.

If you'd rather keep AddInput/AddOutput as builders, the alternative is to make the list Add methods public. That would let callers skip the modifiable-flag check, which is why I went this way. Happy to switch if you prefer it.

New tests cover attaching, a serialization round trip, and the modifiable-flag errors. The PSBT, Miniscript and Taproot tests pass on net10.0, except the ones that download bitcoind, which fail the same way without this change.

🤖 Generated with Claude Code

PSBT2.AddInput and PSBT2.AddOutput built a new input or output but
never added it to the PSBT, and callers outside NBitcoin cannot attach
it themselves because PSBTInputList.Add and PSBTOutputList.Add are
internal. Both methods now add what they build before returning it.

AddOutput now reports "Outputs are not modifiable" instead of "Inputs
are not modifiable", and no longer builds an unused TxOut.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@NicolasDorier
NicolasDorier merged commit 03328f3 into MetacoSA:master Oct 27, 2026
6 checks passed
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.

2 participants