Skip to content

fix(types): avoid reachable panics in Utxo::txout for Foreign variant#487

Merged
ValuedMammal merged 1 commit into
bitcoindevkit:masterfrom
muhahahmad68:fix/utxo-txout-reachable-panic
May 13, 2026
Merged

fix(types): avoid reachable panics in Utxo::txout for Foreign variant#487
ValuedMammal merged 1 commit into
bitcoindevkit:masterfrom
muhahahmad68:fix/utxo-txout-reachable-panic

Conversation

@muhahahmad68
Copy link
Copy Markdown
Contributor

@muhahahmad68 muhahahmad68 commented May 13, 2026

Description

Utxo::txout() contained two reachable panics for the Foreign variant:

  1. prev_tx.output[outpoint.vout as usize] — panics if non_witness_utxo has fewer outputs than outpoint.vout
  2. unreachable!("Foreign UTXOs will always have one of these set") — asserts an invariant the type does not enforce, reachable via direct construction of Utxo::Foreign with an empty psbt::Input

Addresses part of #474

Notes to the reviewers

Collapsed the two if let arms and the unreachable! into a single chained Option, replacing the index access with .get() to safely handle out-of-bounds vout, and replacing unreachable! with .expect().

This is the short-term non-breaking fix. A follow-up will change the function signature to pub fn txout(&self) -> Option<&TxOut> as a breaking change targeting Wallet 4.0.0.

All Submissions:

New Features:

  • N/A

Bugfixes:

  • This pull request breaks the existing API
  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

@codecov
Copy link
Copy Markdown

codecov Bot commented May 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.55%. Comparing base (4b612f5) to head (edb0f52).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #487      +/-   ##
==========================================
+ Coverage   80.30%   80.55%   +0.25%     
==========================================
  Files          24       24              
  Lines        5417     5472      +55     
  Branches      245      243       -2     
==========================================
+ Hits         4350     4408      +58     
+ Misses        989      987       -2     
+ Partials       78       77       -1     
Flag Coverage Δ
rust 80.55% <100.00%> (+0.25%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 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.

@ValuedMammal ValuedMammal added the bug Something isn't working label May 13, 2026
@ValuedMammal ValuedMammal moved this to Needs Review in BDK Wallet May 13, 2026
@ValuedMammal ValuedMammal added this to the Wallet 3.1.0 milestone May 13, 2026
Copy link
Copy Markdown
Collaborator

@ValuedMammal ValuedMammal left a comment

Choose a reason for hiding this comment

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

ACK edb0f52

@ValuedMammal ValuedMammal merged commit 6dca318 into bitcoindevkit:master May 13, 2026
18 checks passed
@github-project-automation github-project-automation Bot moved this from Needs Review to Done in BDK Wallet May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants