cometbft_rpc/endpoint/
block_results.rs1use cometbft::{abci, block, consensus, serializers, validator, AppHash};
4use serde::{Deserialize, Serialize};
5
6use crate::dialect::{self, Dialect};
7use crate::prelude::*;
8use crate::request::RequestMessage;
9
10#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
12pub struct Request {
13 pub height: Option<block::Height>,
17}
18
19impl Request {
20 pub fn new(height: block::Height) -> Self {
22 Self {
23 height: Some(height),
24 }
25 }
26}
27
28impl RequestMessage for Request {
29 fn method(&self) -> crate::Method {
30 crate::Method::BlockResults
31 }
32}
33
34impl crate::Request<dialect::v0_34::Dialect> for Request {
35 type Response = self::v0_34::DialectResponse;
36}
37
38impl crate::Request<dialect::v1::Dialect> for Request {
39 type Response = Response;
40}
41
42impl<S: Dialect> crate::SimpleRequest<S> for Request
43where
44 Self: crate::Request<S>,
45 Response: From<Self::Response>,
46{
47 type Output = Response;
48}
49
50#[derive(Clone, Debug, Serialize, Deserialize)]
52pub struct Response {
53 pub height: block::Height,
55
56 pub txs_results: Option<Vec<abci::types::ExecTxResult>>,
58
59 #[serde(default, skip_serializing_if = "Vec::is_empty")]
63 #[serde(deserialize_with = "serializers::nullable::deserialize")]
64 pub finalize_block_events: Vec<abci::Event>,
65
66 pub begin_block_events: Option<Vec<abci::Event>>,
70
71 pub end_block_events: Option<Vec<abci::Event>>,
75
76 #[serde(deserialize_with = "serializers::nullable::deserialize")]
78 pub validator_updates: Vec<validator::Update>,
79
80 pub consensus_param_updates: Option<consensus::Params>,
82
83 #[serde(default)]
89 #[serde(with = "serializers::apphash")]
90 pub app_hash: AppHash,
91}
92
93impl crate::Response for Response {}
94
95pub mod v0_34 {
97 use super::Response;
98 use crate::dialect::v0_34::Event;
99 use crate::prelude::*;
100 use crate::{dialect, serializers};
101 use cometbft::{block, consensus, validator};
102 use serde::{Deserialize, Serialize};
103
104 #[derive(Debug, Serialize, Deserialize)]
106 pub struct DialectResponse {
107 pub height: block::Height,
109
110 pub txs_results: Option<Vec<dialect::DeliverTx<Event>>>,
112
113 pub begin_block_events: Option<Vec<Event>>,
115
116 pub end_block_events: Option<Vec<Event>>,
118
119 #[serde(deserialize_with = "serializers::nullable::deserialize")]
121 pub validator_updates: Vec<validator::Update>,
122
123 pub consensus_param_updates: Option<consensus::Params>,
125 }
126
127 impl crate::Response for DialectResponse {}
128
129 impl From<DialectResponse> for Response {
130 fn from(msg: DialectResponse) -> Self {
131 Response {
132 height: msg.height,
133 txs_results: msg
134 .txs_results
135 .map(|v| v.into_iter().map(Into::into).collect()),
136 finalize_block_events: vec![],
137 begin_block_events: msg
138 .begin_block_events
139 .map(|v| v.into_iter().map(Into::into).collect()),
140 end_block_events: msg
141 .end_block_events
142 .map(|v| v.into_iter().map(Into::into).collect()),
143 validator_updates: msg.validator_updates,
144 consensus_param_updates: msg.consensus_param_updates,
145 app_hash: Default::default(),
146 }
147 }
148 }
149}