use serde::{Deserialize, Serialize};
use tendermint::{block::Header, Hash};
use crate::dialect::{v0_37, v0_38, Dialect};
use crate::request::RequestMessage;
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct Request {
#[serde(default)]
#[serde(with = "crate::serializers::option_hash")]
pub hash: Option<Hash>,
}
impl Request {
pub fn new<H: Into<Hash>>(hash: H) -> Self {
Self {
hash: Some(hash.into()),
}
}
}
impl RequestMessage for Request {
fn method(&self) -> crate::Method {
crate::Method::HeaderByHash
}
}
impl crate::Request<v0_37::Dialect> for Request {
type Response = Response;
}
impl crate::Request<v0_38::Dialect> for Request {
type Response = Response;
}
impl<S: Dialect> crate::SimpleRequest<S> for Request
where
Self: crate::Request<S>,
Response: From<Self::Response>,
{
type Output = Response;
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Response {
pub header: Option<Header>,
}
impl crate::Response for Response {}
impl From<super::block_by_hash::Response> for Response {
fn from(block_resp: super::block_by_hash::Response) -> Self {
Response {
header: block_resp.block.map(|b| b.header),
}
}
}