Skip to main content

tendermint_rpc/endpoint/
header.rs

1//! `/header` endpoint JSON-RPC wrapper
2
3use serde::{Deserialize, Serialize};
4use tendermint::block::{self, Header};
5
6use crate::dialect::{v0_37, v0_38, Dialect};
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<v0_37::Dialect> for Request {
34    type Response = Response;
35}
36
37impl crate::Request<v0_38::Dialect> for Request {
38    type Response = Response;
39}
40
41impl<S: Dialect> crate::SimpleRequest<S> for Request
42where
43    Self: crate::Request<S>,
44    Response: From<Self::Response>,
45{
46    type Output = Response;
47}
48
49/// Header response
50#[derive(Clone, Debug, Deserialize, Serialize)]
51pub struct Response {
52    /// Header data
53    pub header: Header,
54}
55
56impl crate::Response for Response {}
57
58impl From<super::block::Response> for Response {
59    fn from(block_resp: super::block::Response) -> Self {
60        Response {
61            header: block_resp.block.header,
62        }
63    }
64}