Skip to content

fix(bitcoin-wallet-snap): preserve template output order when filling a PSBT - #157

Draft
jeremytsng wants to merge 1 commit into
mainfrom
fix/btc-output-reordering-fx-fail
Draft

fix(bitcoin-wallet-snap): preserve template output order when filling a PSBT#157
jeremytsng wants to merge 1 commit into
mainfrom
fix/btc-output-reordering-fx-fail

Conversation

@jeremytsng

@jeremytsng jeremytsng commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@jeremytsng
jeremytsng force-pushed the fix/btc-output-reordering-fx-fail branch from d5812af to 30f6166 Compare August 17, 2026 16:57
… a PSBT

Only treat a wallet-owned template output as the drain output when it is the
last output. BDK appends the drain output, so a wallet-owned output placed
anywhere earlier was silently moved to the end of the transaction, reordering
templates that put change before another output.

Verify the built transaction against the template before returning it: every
template output must appear at its original index with its original script and
value, except the drain output, which takes the excess. The previous check
compared only the number of outputs, so a transaction whose outputs diverged
from the template could still be signed and broadcast.
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