@@ -6,7 +6,7 @@ use tokio::sync::oneshot;
66
77use crate :: chain:: block_subsidy;
88use crate :: messages:: ClientRequest ;
9- use crate :: { Event , Info , TrustedPeer , Warning } ;
9+ use crate :: { Event , HeaderCheckpoint , Info , TrustedPeer , Warning } ;
1010
1111use super :: { error:: ClientError , messages:: ClientMessage } ;
1212use super :: { error:: FetchBlockError , IndexedBlock } ;
@@ -188,6 +188,20 @@ impl Requester {
188188 . map_err ( |_| ClientError :: SendError )
189189 }
190190
191+ /// The height and hash of the block in the chain of most work.
192+ ///
193+ /// # Errors
194+ ///
195+ /// If the node has stopped running.
196+ pub async fn chain_tip ( & self ) -> Result < HeaderCheckpoint , ClientError > {
197+ let ( tx, rx) = tokio:: sync:: oneshot:: channel :: < HeaderCheckpoint > ( ) ;
198+ let request = ClientRequest :: new ( ( ) , tx) ;
199+ self . ntx
200+ . send ( ClientMessage :: BestBlock ( request) )
201+ . map_err ( |_| ClientError :: SendError ) ?;
202+ rx. await . map_err ( |_| ClientError :: RecvError )
203+ }
204+
191205 /// Check if the node is running.
192206 pub fn is_running ( & self ) -> bool {
193207 self . ntx . send ( ClientMessage :: NoOp ) . is_ok ( )
0 commit comments