tendermint_rpc/endpoint/
block_results.rs1use serde::{Deserialize, Serialize};
4use tendermint::serializers::allow_empty_object::allow_empty_object;
5use tendermint::{abci, block, consensus, serializers, validator, AppHash};
6
7use crate::dialect::{self, Dialect};
8use crate::prelude::*;
9use crate::request::RequestMessage;
10
11#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
13pub struct Request {
14 pub height: Option<block::Height>,
18}
19
20impl Request {
21 pub fn new(height: block::Height) -> Self {
23 Self {
24 height: Some(height),
25 }
26 }
27}
28
29impl RequestMessage for Request {
30 fn method(&self) -> crate::Method {
31 crate::Method::BlockResults
32 }
33}
34
35impl crate::Request<dialect::v0_34::Dialect> for Request {
36 type Response = self::v0_34::DialectResponse;
37}
38
39impl crate::Request<dialect::v0_37::Dialect> for Request {
40 type Response = Response;
41}
42
43impl crate::Request<dialect::v0_38::Dialect> for Request {
44 type Response = Response;
45}
46
47impl<S: Dialect> crate::SimpleRequest<S> for Request
48where
49 Self: crate::Request<S>,
50 Response: From<Self::Response>,
51{
52 type Output = Response;
53}
54
55#[derive(Clone, Debug, Serialize, Deserialize)]
57pub struct Response {
58 pub height: block::Height,
60
61 pub txs_results: Option<Vec<abci::types::ExecTxResult>>,
63
64 #[serde(default, skip_serializing_if = "Vec::is_empty")]
68 #[serde(deserialize_with = "serializers::nullable::deserialize")]
69 pub finalize_block_events: Vec<abci::Event>,
70
71 pub begin_block_events: Option<Vec<abci::Event>>,
75
76 pub end_block_events: Option<Vec<abci::Event>>,
80
81 #[serde(deserialize_with = "serializers::nullable::deserialize")]
83 pub validator_updates: Vec<validator::Update>,
84
85 #[serde(deserialize_with = "allow_empty_object")]
87 pub consensus_param_updates: Option<consensus::Params>,
88
89 #[serde(default)]
95 #[serde(with = "serializers::apphash")]
96 pub app_hash: AppHash,
97}
98
99impl crate::Response for Response {}
100
101pub mod v0_34 {
103 use super::Response;
104 use crate::dialect::v0_34::Event;
105 use crate::prelude::*;
106 use crate::{dialect, serializers};
107 use serde::{Deserialize, Serialize};
108 use tendermint::serializers::allow_empty_object::allow_empty_object;
109 use tendermint::{block, consensus, validator};
110
111 #[derive(Debug, Serialize, Deserialize)]
113 pub struct DialectResponse {
114 pub height: block::Height,
116
117 pub txs_results: Option<Vec<dialect::DeliverTx<Event>>>,
119
120 pub begin_block_events: Option<Vec<Event>>,
122
123 pub end_block_events: Option<Vec<Event>>,
125
126 #[serde(deserialize_with = "serializers::nullable::deserialize")]
128 pub validator_updates: Vec<validator::Update>,
129
130 #[serde(deserialize_with = "allow_empty_object")]
132 pub consensus_param_updates: Option<consensus::Params>,
133 }
134
135 impl crate::Response for DialectResponse {}
136
137 impl From<DialectResponse> for Response {
138 fn from(msg: DialectResponse) -> Self {
139 Response {
140 height: msg.height,
141 txs_results: msg
142 .txs_results
143 .map(|v| v.into_iter().map(Into::into).collect()),
144 finalize_block_events: vec![],
145 begin_block_events: msg
146 .begin_block_events
147 .map(|v| v.into_iter().map(Into::into).collect()),
148 end_block_events: msg
149 .end_block_events
150 .map(|v| v.into_iter().map(Into::into).collect()),
151 validator_updates: msg.validator_updates,
152 consensus_param_updates: msg.consensus_param_updates,
153 app_hash: Default::default(),
154 }
155 }
156 }
157}