14
14
use std:: collections:: HashMap ;
15
15
use std:: io;
16
16
use std:: io:: Read ;
17
+ use std:: str:: FromStr ;
17
18
use std:: time:: Duration ;
18
19
19
20
#[ allow( unused_imports) ]
@@ -24,7 +25,7 @@ use ureq::{Agent, Proxy, Response};
24
25
use bitcoin:: consensus:: { deserialize, serialize} ;
25
26
use bitcoin:: hashes:: hex:: { FromHex , ToHex } ;
26
27
use bitcoin:: hashes:: { sha256, Hash } ;
27
- use bitcoin:: { BlockHeader , Script , Transaction , Txid } ;
28
+ use bitcoin:: { BlockHash , BlockHeader , Script , Transaction , Txid } ;
28
29
29
30
use crate :: { Builder , Error , MerkleProof , OutputStatus , Tx , TxStatus } ;
30
31
@@ -186,7 +187,7 @@ impl BlockingClient {
186
187
}
187
188
}
188
189
189
- /// Get the current height of the blockchain tip
190
+ /// Get the height of the current blockchain tip.
190
191
pub fn get_height ( & self ) -> Result < u32 , Error > {
191
192
let resp = self
192
193
. agent
@@ -200,6 +201,20 @@ impl BlockingClient {
200
201
}
201
202
}
202
203
204
+ /// Get the [`BlockHash`] of the current blockchain tip.
205
+ pub fn get_tip_hash ( & self ) -> Result < BlockHash , Error > {
206
+ let resp = self
207
+ . agent
208
+ . get ( & format ! ( "{}/blocks/tip/hash" , self . url) )
209
+ . call ( ) ;
210
+
211
+ match resp {
212
+ Ok ( resp) => Ok ( BlockHash :: from_str ( & resp. into_string ( ) ?) ?) ,
213
+ Err ( ureq:: Error :: Status ( code, _) ) => Err ( Error :: HttpResponse ( code) ) ,
214
+ Err ( e) => Err ( Error :: Ureq ( e) ) ,
215
+ }
216
+ }
217
+
203
218
/// Get an map where the key is the confirmation target (in number of blocks)
204
219
/// and the value is the estimated feerate (in sat/vB).
205
220
pub fn get_fee_estimates ( & self ) -> Result < HashMap < String , f64 > , Error > {
0 commit comments