cometbft_rpc/endpoint/
header.rs

1//! `/header` endpoint JSON-RPC wrapper
2
3use cometbft::block::{self, Header};
4use serde::{Deserialize, Serialize};
5
6use crate::dialect::v1;
7use crate::request::RequestMessage;
8
9/// Get information about a specific block
10#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
11pub struct Request {
12    /// Height of the block header to request.
13    ///
14    /// If no height is provided, it will fetch results for the latest block.
15    pub height: Option<block::Height>,
16}
17
18impl Request {
19    /// Create a new request for header information about a particular block
20    pub fn new(height: block::Height) -> Self {
21        Self {
22            height: Some(height),
23        }
24    }
25}
26
27impl RequestMessage for Request {
28    fn method(&self) -> crate::Method {
29        crate::Method::Header
30    }
31}
32
33impl crate::Request<v1::Dialect> for Request {
34    type Response = Response;
35}
36
37impl crate::SimpleRequest<v1::Dialect> for Request {
38    type Output = Response;
39}
40
41/// Header response
42#[derive(Clone, Debug, Deserialize, Serialize)]
43pub struct Response {
44    /// Header data
45    pub header: Header,
46}
47
48impl crate::Response for Response {}
49
50impl From<super::block::Response> for Response {
51    fn from(block_resp: super::block::Response) -> Self {
52        Response {
53            header: block_resp.block.header,
54        }
55    }
56}