@@ -16,19 +16,14 @@ use crate::{
1616#[ must_use]
1717#[ derive( Debug , Clone ) ]
1818pub struct InputCandidates {
19- contains : HashSet < OutPoint > ,
19+ /// Pre-selected input group that is included before optional candidates.
2020 must_select : Option < InputGroup > ,
21+ /// Optional input groups that coin selection may add.
2122 can_select : Vec < InputGroup > ,
23+ /// Cached coin-select candidate metadata, kept in the same order as [`Self::groups`].
2224 cs_candidates : Vec < Candidate > ,
23- }
24-
25- fn cs_candidate_from_group ( group : & InputGroup ) -> Candidate {
26- Candidate {
27- value : group. value ( ) . to_sat ( ) ,
28- weight : group. weight ( ) ,
29- input_count : group. input_count ( ) ,
30- is_segwit : group. is_segwit ( ) ,
31- }
25+ /// Cached outpoints used for deduplication and O(1) membership checks.
26+ contains : HashSet < OutPoint > ,
3227}
3328
3429impl InputCandidates {
@@ -53,10 +48,10 @@ impl InputCandidates {
5348 . collect :: < Vec < _ > > ( ) ;
5449 let cs_candidates = Self :: build_cs_candidates ( & must_select, & can_select) ;
5550 InputCandidates {
56- contains,
5751 must_select,
5852 can_select,
5953 cs_candidates,
54+ contains,
6055 }
6156 }
6257
@@ -67,7 +62,12 @@ impl InputCandidates {
6762 must_select
6863 . iter ( )
6964 . chain ( can_select)
70- . map ( cs_candidate_from_group)
65+ . map ( |group| Candidate {
66+ value : group. value ( ) . to_sat ( ) ,
67+ weight : group. weight ( ) ,
68+ input_count : group. input_count ( ) ,
69+ is_segwit : group. is_segwit ( ) ,
70+ } )
7171 . collect ( )
7272 }
7373
@@ -76,7 +76,7 @@ impl InputCandidates {
7676 self . groups ( ) . flat_map ( InputGroup :: inputs)
7777 }
7878
79- /// Consume and iterate over all conatined inputs of all groups.
79+ /// Consume and iterate over all contained inputs of all groups.
8080 pub fn into_inputs ( self ) -> impl Iterator < Item = Input > {
8181 self . into_groups ( ) . flat_map ( InputGroup :: into_inputs)
8282 }
@@ -91,17 +91,17 @@ impl InputCandidates {
9191 self . must_select . into_iter ( ) . chain ( self . can_select )
9292 }
9393
94- /// Can select
94+ /// Inputs that coin selection may choose from.
9595 pub fn can_select ( & self ) -> & [ InputGroup ] {
9696 & self . can_select
9797 }
9898
99- /// Must select
99+ /// Inputs that must be selected, if any.
100100 pub fn must_select ( & self ) -> Option < & InputGroup > {
101101 self . must_select . as_ref ( )
102102 }
103103
104- /// cs candidates
104+ /// Cached candidate metadata used by `bdk_coin_select`.
105105 pub fn coin_select_candidates ( & self ) -> & Vec < Candidate > {
106106 & self . cs_candidates
107107 }
@@ -160,10 +160,10 @@ impl InputCandidates {
160160 let no_dup = self . contains ;
161161
162162 Self {
163- contains : no_dup,
164163 must_select,
165164 can_select,
166165 cs_candidates,
166+ contains : no_dup,
167167 }
168168 }
169169
0 commit comments