Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HashMap<String, f64>, Error> {
pub async fn get_fee_estimates(&self) -> Result<HashMap<u16, f64>, Error> {
let resp = self
.client
.get(&format!("{}/fee-estimates", self.url,))
Expand All @@ -382,7 +382,7 @@ impl AsyncClient {
message: resp.text().await?,
})
} else {
Ok(resp.json::<HashMap<String, f64>>().await?)
Ok(resp.json::<HashMap<u16, f64>>().await?)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HashMap<String, f64>, Error> {
pub fn get_fee_estimates(&self) -> Result<HashMap<u16, f64>, Error> {
self.get_response_json("/fee-estimates")
}

Expand Down
11 changes: 4 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, f64>) -> Result<f32, Error> {
pub fn convert_fee_rate(target: usize, estimates: HashMap<u16, f64>) -> Result<f32, Error> {
let fee_val = {
let mut pairs = estimates
.into_iter()
.filter_map(|(k, v)| Some((k.parse::<usize>().ok()?, v)))
.collect::<Vec<_>>();
let mut pairs = estimates.into_iter().collect::<Vec<(u16, f64)>>();
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)
};
Expand Down Expand Up @@ -336,7 +333,7 @@ mod test {

#[test]
fn feerate_parsing() {
let esplora_fees = serde_json::from_str::<HashMap<String, f64>>(
let esplora_fees = serde_json::from_str::<HashMap<u16, f64>>(
r#"{
"25": 1.015,
"5": 2.3280000000000003,
Expand Down