diff --git a/src/lib.rs b/src/lib.rs index de6b0db..30a8cd8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,7 +5,7 @@ use std::{borrow::Cow, io::Cursor, net::SocketAddr}; use bitcoin::{ Block, BlockHash, FeeRate, bip158::BlockFilter, block::Header, consensus::Decodable, }; -use models::{Html, ServerStatus, TapTweaks}; +use models::{FeeEstimates, Html, ServerStatus, TapTweaks}; /// Errors that may occur when querying. pub mod error; @@ -21,8 +21,8 @@ pub struct Endpoint<'e>(Cow<'e, str>); impl<'e> Endpoint<'e> { /// The original `block-dn` server hosted at `block-dn.org`. pub const BLOCK_DN_ORG: Self = Self(Cow::Borrowed("https://block-dn.org")); - /// Server with additional capabilities hosted by `2140.dev`. - pub const DEV_2140: Self = Self(Cow::Borrowed("https://taprootdn.xyz")); + // Server with additional capabilities hosted by `2140.dev`. + // pub const DEV_2140: Self = Self(Cow::Borrowed("https://taprootdn.xyz")); /// Local host at port 8080. pub const LOCAL_HOST: Self = Self(Cow::Borrowed("https://127.0.0.1:8080")); @@ -178,16 +178,10 @@ impl<'e> Client<'e> { pub fn estimate_smart_fee(&self, conf_target: u32) -> Result { let route = self .endpoint - .append_route(format!("fees/estimate-fee/{conf_target}")); + .append_route(format!("fees/estimate/{conf_target}")); let response = bitreq::get(route).with_timeout(self.timeout.0).send()?; - let sats_vb: [u8; 8] = response.as_bytes().try_into().map_err(|_| { - Error::Decoder(bitcoin::consensus::encode::Error::ParseFailed( - "cannot fit response into 8 byte little endian.", - )) - })?; - Ok(FeeRate::from_sat_per_vb_unchecked(u64::from_le_bytes( - sats_vb, - ))) + let fees = response.json::()?; + Ok(FeeRate::from_sat_per_kwu(fees.fee_sat_per_kweight)) } } diff --git a/src/models.rs b/src/models.rs index a4082b5..b504d1a 100644 --- a/src/models.rs +++ b/src/models.rs @@ -62,3 +62,14 @@ impl TapTweaks { }) } } + +/// Fee estimates for a given block confirmation. +#[derive(Debug, Clone, serde::Deserialize)] +pub struct FeeEstimates { + /// sat/kvb. + pub fee_sat_per_kvbyte: u64, + /// sat/kwu. + pub fee_sat_per_kweight: u64, + /// sat/vb. + pub fee_sat_per_vbyte: u64, +} diff --git a/tests/client.rs b/tests/client.rs index a36ae28..9dac49b 100644 --- a/tests/client.rs +++ b/tests/client.rs @@ -53,6 +53,6 @@ fn test_block() { #[test] fn test_estimate_fee() { - let client = Builder::new().endpoint(Endpoint::DEV_2140).build(); + let client = Builder::new().endpoint(Endpoint::BLOCK_DN_ORG).build(); assert!(client.estimate_smart_fee(1).is_ok()); }