tendermint_rpc/endpoint/
block_by_hash.rs1use serde::{Deserialize, Serialize};
4use tendermint::{
5 block::{self, Block},
6 Hash,
7};
8
9use crate::dialect::{self, Dialect};
10use crate::request::RequestMessage;
11
12#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
14pub struct Request {
15 #[serde(default)]
23 #[serde(with = "crate::serializers::opt_tm_hash_base64")]
24 pub hash: Option<Hash>,
25}
26
27impl Request {
28 pub fn new<H: Into<Hash>>(hash: H) -> Self {
30 Self {
31 hash: Some(hash.into()),
32 }
33 }
34}
35
36impl RequestMessage for Request {
37 fn method(&self) -> crate::Method {
38 crate::Method::BlockByHash
39 }
40}
41
42impl crate::Request<dialect::v0_34::Dialect> for Request {
43 type Response = Response;
44}
45
46impl crate::Request<dialect::v0_37::Dialect> for Request {
47 type Response = Response;
48}
49
50impl crate::Request<dialect::v0_38::Dialect> for Request {
51 type Response = self::v0_38::DialectResponse;
52}
53
54impl<S: Dialect> crate::SimpleRequest<S> for Request
55where
56 Self: crate::Request<S>,
57 Response: From<Self::Response>,
58{
59 type Output = Response;
60}
61
62#[derive(Clone, Debug, Deserialize, Serialize)]
64pub struct Response {
65 pub block_id: block::Id,
67
68 pub block: Option<Block>,
70}
71
72impl crate::Response for Response {}
73
74pub mod v0_38 {
75 use super::*;
76 use crate::endpoint::block::v0_38::DialectBlock;
77
78 #[derive(Clone, Debug, Deserialize, Serialize)]
79 pub struct DialectResponse {
80 pub block_id: block::Id,
82
83 pub block: Option<DialectBlock>,
85 }
86
87 impl crate::Response for DialectResponse {}
88
89 impl From<DialectResponse> for Response {
90 fn from(msg: DialectResponse) -> Self {
91 Self {
92 block_id: msg.block_id,
93 block: msg.block.map(Into::into),
94 }
95 }
96 }
97}