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
18 changes: 6 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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"));

Expand Down Expand Up @@ -178,16 +178,10 @@ impl<'e> Client<'e> {
pub fn estimate_smart_fee(&self, conf_target: u32) -> Result<FeeRate, Error> {
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::<FeeEstimates>()?;
Ok(FeeRate::from_sat_per_kwu(fees.fee_sat_per_kweight))
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
2 changes: 1 addition & 1 deletion tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Loading