Skip to content

Commit

Permalink
feat(client): get header in blocking context
Browse files Browse the repository at this point in the history
  • Loading branch information
rustaceanrob committed Nov 1, 2024
1 parent 5b576bf commit 51e0080
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/core/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,30 @@ macro_rules! impl_core_client {
rx.await.map_err(|_| FetchHeaderError::RecvError)?
}

/// Get a header at the specified height in a synchronus context, if it exists.
///
/// # Note
///
/// The height of the chain is the canonical index of the header in the chain.
/// For example, the genesis block is at a height of zero.
///
/// # Errors
///
/// If the node has stopped running.
pub fn get_header_blocking(
&self,
height: u32,
) -> Result<Option<Header>, FetchHeaderError> {
let (tx, rx) =
tokio::sync::oneshot::channel::<Result<Option<Header>, FetchHeaderError>>();
let message = HeaderRequest::new(tx, height);
self.ntx
.blocking_send(ClientMessage::GetHeader(message))
.map_err(|_| FetchHeaderError::SendError)?;
rx.blocking_recv()
.map_err(|_| FetchHeaderError::RecvError)?
}

/// Starting at the configured anchor checkpoint, look for block inclusions with newly added scripts.
///
/// # Errors
Expand Down

0 comments on commit 51e0080

Please sign in to comment.