22#![ warn( missing_docs) ]
33use std:: { borrow:: Cow , io:: Cursor , net:: SocketAddr } ;
44
5- use bitcoin:: { Block , BlockHash , bip158:: BlockFilter , block:: Header , consensus:: Decodable } ;
5+ use bitcoin:: {
6+ Block , BlockHash , FeeRate , bip158:: BlockFilter , block:: Header , consensus:: Decodable ,
7+ } ;
68use models:: { Html , ServerStatus , TapTweaks } ;
79
810/// Errors that may occur when querying.
@@ -19,8 +21,8 @@ pub struct Endpoint<'e>(Cow<'e, str>);
1921impl < ' e > Endpoint < ' e > {
2022 /// The original `block-dn` server hosted at `block-dn.org`.
2123 pub const BLOCK_DN_ORG : Self = Self ( Cow :: Borrowed ( "https://block-dn.org" ) ) ;
22- // Taproot-specific filters hosted by `2140.dev`.
23- // pub const TAPROOT_DN : 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" ) ) ;
2426 /// Local host at port 8080.
2527 pub const LOCAL_HOST : Self = Self ( Cow :: Borrowed ( "https://127.0.0.1:8080" ) ) ;
2628
@@ -170,6 +172,23 @@ impl<'e> Client<'e> {
170172 let block = bitcoin:: consensus:: deserialize :: < Block > ( response. as_bytes ( ) ) ?;
171173 Ok ( block)
172174 }
175+
176+ /// Get the fee rate estimated for inclusion in the target block. Only available on
177+ /// [`Endpoint::DEV_2140`].
178+ pub fn estimate_smart_fee ( & self , conf_target : u32 ) -> Result < FeeRate , Error > {
179+ let route = self
180+ . endpoint
181+ . append_route ( format ! ( "fees/estimate-fee/{conf_target}" ) ) ;
182+ 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+ ) ) )
191+ }
173192}
174193
175194#[ cfg( test) ]
0 commit comments