File tree Expand file tree Collapse file tree 3 files changed +28
-0
lines changed
Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -221,6 +221,24 @@ impl Requester {
221221 rx. await . map_err ( |_| ClientError :: RecvError )
222222 }
223223
224+ /// Look up the height of a block hash in the locally synced chain of most work.
225+ /// Returns `None` if the hash is not in the header chain.
226+ ///
227+ /// # Errors
228+ ///
229+ /// If the node has stopped running.
230+ pub async fn height_of_hash (
231+ & self ,
232+ hash : BlockHash ,
233+ ) -> Result < Option < u32 > , ClientError > {
234+ let ( tx, rx) = tokio:: sync:: oneshot:: channel :: < Option < u32 > > ( ) ;
235+ let request = ClientRequest :: new ( hash, tx) ;
236+ self . ntx
237+ . send ( ClientMessage :: HeightOfHash ( request) )
238+ . map_err ( |_| ClientError :: SendError ) ?;
239+ rx. await . map_err ( |_| ClientError :: RecvError )
240+ }
241+
224242 /// Check if the node is running.
225243 pub fn is_running ( & self ) -> bool {
226244 self . ntx . send ( ClientMessage :: NoOp ) . is_ok ( )
Original file line number Diff line number Diff line change @@ -153,6 +153,8 @@ pub(crate) enum ClientMessage {
153153 GetBroadcastMinFeeRate ( ClientRequest < ( ) , FeeRate > ) ,
154154 /// Get info on connections
155155 GetPeerInfo ( ClientRequest < ( ) , Vec < ( AddrV2 , ServiceFlags ) > > ) ,
156+ /// Look up the height of a block hash in the chain of most work.
157+ HeightOfHash ( ClientRequest < BlockHash , Option < u32 > > ) ,
156158 /// Send an empty message to see if the node is running.
157159 NoOp ,
158160}
Original file line number Diff line number Diff line change @@ -268,6 +268,14 @@ impl Node {
268268 self . dialog. send_warning( Warning :: ChannelDropped ) ;
269269 } ;
270270 }
271+ ClientMessage :: HeightOfHash ( request) => {
272+ let ( hash, oneshot) = request. into_values( ) ;
273+ let height =
274+ self . chain. header_chain. height_of_hash( hash) ;
275+ if oneshot. send( height) . is_err( ) {
276+ self . dialog. send_warning( Warning :: ChannelDropped ) ;
277+ } ;
278+ }
271279 ClientMessage :: NoOp => ( ) ,
272280 }
273281 }
You can’t perform that action at this time.
0 commit comments