tendermint/abci/response/
init_chain.rs

1use crate::AppHash;
2
3use crate::{consensus, prelude::*, validator};
4
5#[doc = include_str!("../doc/response-initchain.md")]
6#[derive(Clone, PartialEq, Eq, Debug, Default)]
7pub struct InitChain {
8    /// Initial consensus-critical parameters (optional).
9    pub consensus_params: Option<consensus::Params>,
10    /// Initial validator set (optional).
11    ///
12    /// If this list is empty, the initial validator set will be the one given in
13    /// [`request::InitChain::validators`](super::super::request::InitChain::validators).
14    ///
15    /// If this list is nonempty, it will be the initial validator set, instead
16    /// of the one given in
17    /// [`request::InitChain::validators`](super::super::request::InitChain::validators).
18    pub validators: Vec<validator::Update>,
19    /// Initial application hash.
20    pub app_hash: AppHash,
21}
22
23// =============================================================================
24// Protobuf conversions
25// =============================================================================
26
27tendermint_pb_modules! {
28    use super::InitChain;
29
30    impl From<InitChain> for pb::abci::ResponseInitChain {
31        fn from(init_chain: InitChain) -> Self {
32            Self {
33                consensus_params: init_chain.consensus_params.map(Into::into),
34                validators: init_chain.validators.into_iter().map(Into::into).collect(),
35                app_hash: init_chain.app_hash.into(),
36            }
37        }
38    }
39
40    impl TryFrom<pb::abci::ResponseInitChain> for InitChain {
41        type Error = crate::Error;
42
43        fn try_from(init_chain: pb::abci::ResponseInitChain) -> Result<Self, Self::Error> {
44            Ok(Self {
45                consensus_params: init_chain
46                    .consensus_params
47                    .map(TryInto::try_into)
48                    .transpose()?,
49                validators: init_chain
50                    .validators
51                    .into_iter()
52                    .map(TryInto::try_into)
53                    .collect::<Result<_, _>>()?,
54                app_hash: init_chain.app_hash.try_into()?,
55            })
56        }
57    }
58
59    impl Protobuf<pb::abci::ResponseInitChain> for InitChain {}
60}