cometbft_rpc/endpoint/
header_by_hash.rs1use cometbft::{block::Header, Hash};
4use serde::{Deserialize, Serialize};
5
6use crate::dialect::v1;
7use crate::request::RequestMessage;
8
9#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
11pub struct Request {
12 #[serde(default)]
20 #[serde(with = "crate::serializers::option_hash")]
21 pub hash: Option<Hash>,
22}
23
24impl Request {
25 pub fn new<H: Into<Hash>>(hash: H) -> Self {
27 Self {
28 hash: Some(hash.into()),
29 }
30 }
31}
32
33impl RequestMessage for Request {
34 fn method(&self) -> crate::Method {
35 crate::Method::HeaderByHash
36 }
37}
38
39impl crate::Request<v1::Dialect> for Request {
40 type Response = Response;
41}
42
43impl crate::SimpleRequest<v1::Dialect> for Request {
44 type Output = Response;
45}
46
47#[derive(Clone, Debug, Deserialize, Serialize)]
49pub struct Response {
50 pub header: Option<Header>,
52}
53
54impl crate::Response for Response {}
55
56impl From<super::block_by_hash::Response> for Response {
57 fn from(block_resp: super::block_by_hash::Response) -> Self {
58 Response {
59 header: block_resp.block.map(|b| b.header),
60 }
61 }
62}