File tree Expand file tree Collapse file tree 1 file changed +8
-11
lines changed Expand file tree Collapse file tree 1 file changed +8
-11
lines changed Original file line number Diff line number Diff line change @@ -88,17 +88,14 @@ pub use r#async::AsyncClient;
8888
8989/// Get a fee value in sats/vbytes from the estimates
9090/// that matches the confirmation target set as parameter.
91- pub fn convert_fee_rate ( target : usize , estimates : HashMap < u16 , f64 > ) -> Result < f32 , Error > {
92- let fee_val = {
93- let mut pairs = estimates. into_iter ( ) . collect :: < Vec < ( u16 , f64 ) > > ( ) ;
94- pairs. sort_unstable_by_key ( |( k, _) | std:: cmp:: Reverse ( * k) ) ;
95- pairs
96- . into_iter ( )
97- . find ( |( k, _) | * k as usize <= target)
98- . map ( |( _, v) | v)
99- . unwrap_or ( 1.0 )
100- } ;
101- Ok ( fee_val as f32 )
91+ ///
92+ /// Returns `None` if no feerate estimate is found at or below `target` confirmations.
93+ pub fn convert_fee_rate ( target : usize , estimates : HashMap < u16 , f64 > ) -> Option < f32 > {
94+ estimates
95+ . into_iter ( )
96+ . filter ( |( k, _) | * k as usize <= target)
97+ . max_by_key ( |( k, _) | * k)
98+ . map ( |( _, v) | v as f32 )
10299}
103100
104101#[ derive( Debug , Clone ) ]
You can’t perform that action at this time.
0 commit comments