Skip to content

feat: expose detailed try_finalize_psbt outcomes#433

Merged
ValuedMammal merged 6 commits into
bitcoindevkit:masterfrom
reez:issue-73
Jul 8, 2026
Merged

feat: expose detailed try_finalize_psbt outcomes#433
ValuedMammal merged 6 commits into
bitcoindevkit:masterfrom
reez:issue-73

Conversation

@reez

@reez reez commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Description

Close #73

This PR keeps the scope to PSBT finalization only:

  • add try_finalize_psbt which returns FinalizePsbtOutcome
  • report per input outcomes via FinalizeInputOutcome

Notes to the reviewers

This is now additive rather than breaking: Wallet::finalize_psbt still returns bool

Intentionally not included here:

  • changing Wallet::sign to return a richer result type
  • any broader redesign beyond the PSBT finalization API surface

Changelog notice

  • Add Wallet::try_finalize_psbt, which returns FinalizePsbtOutcome and exposes per-input finalization outcomes while preserving the existing Wallet::finalize_psbt API.

Checklists

All Submissions:

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

@codecov

codecov Bot commented Apr 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.62921% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.15%. Comparing base (58fe631) to head (72261ce).
⚠️ Report is 5 commits behind head on master.

Files with missing lines Patch % Lines
src/types.rs 82.35% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #433      +/-   ##
==========================================
+ Coverage   80.96%   81.15%   +0.19%     
==========================================
  Files          24       24              
  Lines        5489     5552      +63     
  Branches      247      247              
==========================================
+ Hits         4444     4506      +62     
- Misses        968      970       +2     
+ Partials       77       76       -1     
Flag Coverage Δ
rust 81.15% <96.62%> (+0.19%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@reez reez force-pushed the issue-73 branch 2 times, most recently from c65f534 to e046adc Compare April 7, 2026 20:16
@reez reez changed the title (draft) feat: expose detailed finalize_psbt outcomes (draft) feat: expose detailed try_finalize_psbt outcomes Apr 7, 2026
@reez

reez commented Apr 7, 2026

Copy link
Copy Markdown
Contributor Author

Updated per some good feedback from mammal

@reez reez marked this pull request as ready for review April 9, 2026 19:21
@reez reez changed the title (draft) feat: expose detailed try_finalize_psbt outcomes feat: expose detailed try_finalize_psbt outcomes Apr 9, 2026
@reez reez force-pushed the issue-73 branch 5 times, most recently from f3fb2a6 to 69966b6 Compare April 14, 2026 19:14
@ValuedMammal ValuedMammal added this to the Wallet 3.1.0 milestone Apr 14, 2026
@ValuedMammal ValuedMammal added the new feature New feature or request label Apr 14, 2026
@ValuedMammal ValuedMammal moved this to In Progress in BDK Wallet Apr 14, 2026

@ValuedMammal ValuedMammal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think After and Older are doing much good, and would prefer to leave them out of the new implementation if we plan to support try_finalize_psbt into the future.

@notmandatory

Copy link
Copy Markdown
Member

Concept ACK, glad to see this as a non-breaking change.

@reez

reez commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

Added four commits as small follow-ups from review feedback from mammal: make finalization cleanup more explicit, preserve opaque PSBT/input metadata, stop the new try_finalize_psbt path from redacting output metadata, and clarify the internal timelock inputs without changing legacy finalize_psbt behavior.

Comment thread src/wallet/mod.rs Outdated
Comment thread src/wallet/mod.rs Outdated
Comment thread src/wallet/mod.rs Outdated
Comment thread src/wallet/mod.rs Outdated
Comment thread src/wallet/mod.rs

@oleonardolima oleonardolima left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cACK 09d2cd0

Comment thread src/wallet/mod.rs
@Musab1258

Musab1258 commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

tACK 09d2cd0

The concept and approach make sense. I fetched the branch and ran the tests locally, and they all pass. The documentation also clearly specifies when to use the finalize_psbt and try_finalize_psbt methods.

Comment thread src/types.rs
}

/// Whether all inputs are finalized after this call.
pub fn is_finalized(&self) -> bool {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If outcomes is empty (e.g. a PSBT with no inputs), is_finalized() returns true, since .all() on an empty iterator is true. Is this the intended behavior or worth documenting/guarding against explicitly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is intended since is_finalized() is only answering whether any input failed finalization, so if there are no inputs there is nothing to fail. This also matches the old finalize_psbt behavior where finished started as true and only changed inside the input loop. But that's my take, open to further thoughts

Comment thread src/wallet/mod.rs
Comment thread src/types.rs
@ValuedMammal

Copy link
Copy Markdown
Collaborator

ACK ec3a683

@ValuedMammal

Copy link
Copy Markdown
Collaborator

cargo +nightly fmt produced a diff, and it wasn't caught by CI

                             let final_script_witness =
                                 (!tmp_input.witness.is_empty()).then_some(tmp_input.witness);

-                            // BIP174 finalization clears input metadata except UTXOs, final scripts,
-                            // and opaque fields the finalizer does not understand.
+                            // BIP174 finalization clears input metadata except UTXOs, final
+                            // scripts, and opaque fields the finalizer
+                            // does not understand.
                             *psbt_input = bitcoin::psbt::Input {
                                 non_witness_utxo: original.non_witness_utxo,
                                 witness_utxo: original.witness_utxo,

@ValuedMammal ValuedMammal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 72261ce

@ValuedMammal ValuedMammal merged commit 75e0d30 into bitcoindevkit:master Jul 8, 2026
18 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in BDK Wallet Jul 8, 2026
@reez reez deleted the issue-73 branch July 8, 2026 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new feature New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

additional information for finalize_psbt when returning false

5 participants