diff --git a/src/async.rs b/src/async.rs index 683bedb..850ef3d 100644 --- a/src/async.rs +++ b/src/async.rs @@ -369,7 +369,7 @@ impl AsyncClient { /// Get an map where the key is the confirmation target (in number of blocks) /// and the value is the estimated feerate (in sat/vB). - pub async fn get_fee_estimates(&self) -> Result, Error> { + pub async fn get_fee_estimates(&self) -> Result, Error> { let resp = self .client .get(&format!("{}/fee-estimates", self.url,)) @@ -382,7 +382,7 @@ impl AsyncClient { message: resp.text().await?, }) } else { - Ok(resp.json::>().await?) + Ok(resp.json::>().await?) } } diff --git a/src/blocking.rs b/src/blocking.rs index bc581dd..d2afe7c 100644 --- a/src/blocking.rs +++ b/src/blocking.rs @@ -281,7 +281,7 @@ impl BlockingClient { /// Get an map where the key is the confirmation target (in number of blocks) /// and the value is the estimated feerate (in sat/vB). - pub fn get_fee_estimates(&self) -> Result, Error> { + pub fn get_fee_estimates(&self) -> Result, Error> { self.get_response_json("/fee-estimates") } diff --git a/src/lib.rs b/src/lib.rs index b5db357..94e9471 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -88,16 +88,13 @@ pub use r#async::AsyncClient; /// Get a fee value in sats/vbytes from the estimates /// that matches the confirmation target set as parameter. -pub fn convert_fee_rate(target: usize, estimates: HashMap) -> Result { +pub fn convert_fee_rate(target: usize, estimates: HashMap) -> Result { let fee_val = { - let mut pairs = estimates - .into_iter() - .filter_map(|(k, v)| Some((k.parse::().ok()?, v))) - .collect::>(); + let mut pairs = estimates.into_iter().collect::>(); pairs.sort_unstable_by_key(|(k, _)| std::cmp::Reverse(*k)); pairs .into_iter() - .find(|(k, _)| k <= &target) + .find(|(k, _)| *k as usize <= target) .map(|(_, v)| v) .unwrap_or(1.0) }; @@ -336,7 +333,7 @@ mod test { #[test] fn feerate_parsing() { - let esplora_fees = serde_json::from_str::>( + let esplora_fees = serde_json::from_str::>( r#"{ "25": 1.015, "5": 2.3280000000000003,