Skip to content

Commit 00575de

Browse files
committed
Update fee endpoint
1 parent b9908f4 commit 00575de

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

src/lib.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{borrow::Cow, io::Cursor, net::SocketAddr};
55
use bitcoin::{
66
Block, BlockHash, FeeRate, bip158::BlockFilter, block::Header, consensus::Decodable,
77
};
8-
use models::{Html, ServerStatus, TapTweaks};
8+
use models::{FeeEstimates, Html, ServerStatus, TapTweaks};
99

1010
/// Errors that may occur when querying.
1111
pub mod error;
@@ -21,8 +21,8 @@ pub struct Endpoint<'e>(Cow<'e, str>);
2121
impl<'e> Endpoint<'e> {
2222
/// The original `block-dn` server hosted at `block-dn.org`.
2323
pub const BLOCK_DN_ORG: Self = Self(Cow::Borrowed("https://block-dn.org"));
24-
/// Server with additional capabilities hosted by `2140.dev`.
25-
pub const DEV_2140: Self = Self(Cow::Borrowed("https://taprootdn.xyz"));
24+
// Server with additional capabilities hosted by `2140.dev`.
25+
// pub const DEV_2140: Self = Self(Cow::Borrowed("https://taprootdn.xyz"));
2626
/// Local host at port 8080.
2727
pub const LOCAL_HOST: Self = Self(Cow::Borrowed("https://127.0.0.1:8080"));
2828

@@ -178,16 +178,10 @@ impl<'e> Client<'e> {
178178
pub fn estimate_smart_fee(&self, conf_target: u32) -> Result<FeeRate, Error> {
179179
let route = self
180180
.endpoint
181-
.append_route(format!("fees/estimate-fee/{conf_target}"));
181+
.append_route(format!("fees/estimate/{conf_target}"));
182182
let response = bitreq::get(route).with_timeout(self.timeout.0).send()?;
183-
let sats_vb: [u8; 8] = response.as_bytes().try_into().map_err(|_| {
184-
Error::Decoder(bitcoin::consensus::encode::Error::ParseFailed(
185-
"cannot fit response into 8 byte little endian.",
186-
))
187-
})?;
188-
Ok(FeeRate::from_sat_per_vb_unchecked(u64::from_le_bytes(
189-
sats_vb,
190-
)))
183+
let fees = response.json::<FeeEstimates>()?;
184+
Ok(FeeRate::from_sat_per_kwu(fees.fee_sat_per_kweight))
191185
}
192186
}
193187

src/models.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,14 @@ impl TapTweaks {
6262
})
6363
}
6464
}
65+
66+
/// Fee estimates for a given block confirmation.
67+
#[derive(Debug, Clone, serde::Deserialize)]
68+
pub struct FeeEstimates {
69+
/// sat/kvb.
70+
pub fee_sat_per_kvbyte: u64,
71+
/// sat/kwu.
72+
pub fee_sat_per_kweight: u64,
73+
/// sat/vb.
74+
pub fee_sat_per_vbyte: u64,
75+
}

tests/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@ fn test_block() {
5353

5454
#[test]
5555
fn test_estimate_fee() {
56-
let client = Builder::new().endpoint(Endpoint::DEV_2140).build();
56+
let client = Builder::new().endpoint(Endpoint::BLOCK_DN_ORG).build();
5757
assert!(client.estimate_smart_fee(1).is_ok());
5858
}

0 commit comments

Comments
 (0)