-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathfinalize_block.rs
More file actions
193 lines (175 loc) · 6.88 KB
/
finalize_block.rs
File metadata and controls
193 lines (175 loc) · 6.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
use serde::{Deserialize, Serialize};
use crate::abci::{types::ExecTxResult, Event};
use crate::prelude::*;
use crate::{consensus, serializers, validator, AppHash};
#[doc = include_str!("../doc/response-finalizeblock.md")]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct FinalizeBlock {
/// Set of block events emitted as part of executing the block
///
/// nondeterministic
#[serde(default)]
pub events: Vec<Event>,
/// The result of executing each transaction including the events
/// the particular transaction emitted. This should match the order
/// of the transactions delivered in the block itself
#[serde(default)]
pub tx_results: Vec<ExecTxResult>,
/// A list of updates to the validator set.
/// These will reflect the validator set at current height + 2.
#[serde(with = "serializers::nullable")]
pub validator_updates: Vec<validator::Update>,
/// Updates to the consensus params, if any.
#[serde(default)]
pub consensus_param_updates: Option<consensus::Params>,
/// The hash of the application's state.
#[serde(default, with = "serializers::apphash_base64")]
pub app_hash: AppHash,
}
// =============================================================================
// Protobuf conversions
// =============================================================================
mod v0_38 {
use super::FinalizeBlock;
use cometbft_proto::v0_38::abci as pb;
use cometbft_proto::Protobuf;
impl From<FinalizeBlock> for pb::ResponseFinalizeBlock {
fn from(value: FinalizeBlock) -> Self {
Self {
events: value.events.into_iter().map(Into::into).collect(),
tx_results: value.tx_results.into_iter().map(Into::into).collect(),
validator_updates: value
.validator_updates
.into_iter()
.map(Into::into)
.collect(),
consensus_param_updates: value.consensus_param_updates.map(Into::into),
app_hash: value.app_hash.into(),
}
}
}
impl TryFrom<pb::ResponseFinalizeBlock> for FinalizeBlock {
type Error = crate::Error;
fn try_from(message: pb::ResponseFinalizeBlock) -> Result<Self, Self::Error> {
Ok(Self {
events: message
.events
.into_iter()
.map(TryInto::try_into)
.collect::<Result<_, _>>()?,
tx_results: message
.tx_results
.into_iter()
.map(TryInto::try_into)
.collect::<Result<_, _>>()?,
validator_updates: message
.validator_updates
.into_iter()
.map(TryInto::try_into)
.collect::<Result<_, _>>()?,
consensus_param_updates: message
.consensus_param_updates
.map(TryInto::try_into)
.transpose()?,
app_hash: message.app_hash.try_into()?,
})
}
}
impl Protobuf<pb::ResponseFinalizeBlock> for FinalizeBlock {}
}
mod v1 {
use super::FinalizeBlock;
use cometbft_proto::abci::v1 as pb;
use cometbft_proto::Protobuf;
impl From<FinalizeBlock> for pb::FinalizeBlockResponse {
fn from(value: FinalizeBlock) -> Self {
Self {
events: value.events.into_iter().map(Into::into).collect(),
tx_results: value.tx_results.into_iter().map(Into::into).collect(),
validator_updates: value
.validator_updates
.into_iter()
.map(Into::into)
.collect(),
consensus_param_updates: value.consensus_param_updates.map(Into::into),
app_hash: value.app_hash.into(),
}
}
}
impl TryFrom<pb::FinalizeBlockResponse> for FinalizeBlock {
type Error = crate::Error;
fn try_from(message: pb::FinalizeBlockResponse) -> Result<Self, Self::Error> {
Ok(Self {
events: message
.events
.into_iter()
.map(TryInto::try_into)
.collect::<Result<_, _>>()?,
tx_results: message
.tx_results
.into_iter()
.map(TryInto::try_into)
.collect::<Result<_, _>>()?,
validator_updates: message
.validator_updates
.into_iter()
.map(TryInto::try_into)
.collect::<Result<_, _>>()?,
consensus_param_updates: message
.consensus_param_updates
.map(TryInto::try_into)
.transpose()?,
app_hash: message.app_hash.try_into()?,
})
}
}
impl Protobuf<pb::FinalizeBlockResponse> for FinalizeBlock {}
}
mod v1beta3 {
use super::FinalizeBlock;
use cometbft_proto::abci::v1beta3 as pb;
use cometbft_proto::Protobuf;
impl From<FinalizeBlock> for pb::ResponseFinalizeBlock {
fn from(value: FinalizeBlock) -> Self {
Self {
events: value.events.into_iter().map(Into::into).collect(),
tx_results: value.tx_results.into_iter().map(Into::into).collect(),
validator_updates: value
.validator_updates
.into_iter()
.map(Into::into)
.collect(),
consensus_param_updates: value.consensus_param_updates.map(Into::into),
app_hash: value.app_hash.into(),
}
}
}
impl TryFrom<pb::ResponseFinalizeBlock> for FinalizeBlock {
type Error = crate::Error;
fn try_from(message: pb::ResponseFinalizeBlock) -> Result<Self, Self::Error> {
Ok(Self {
events: message
.events
.into_iter()
.map(TryInto::try_into)
.collect::<Result<_, _>>()?,
tx_results: message
.tx_results
.into_iter()
.map(TryInto::try_into)
.collect::<Result<_, _>>()?,
validator_updates: message
.validator_updates
.into_iter()
.map(TryInto::try_into)
.collect::<Result<_, _>>()?,
consensus_param_updates: message
.consensus_param_updates
.map(TryInto::try_into)
.transpose()?,
app_hash: message.app_hash.try_into()?,
})
}
}
impl Protobuf<pb::ResponseFinalizeBlock> for FinalizeBlock {}
}