tendermint/abci/request/
init_chain.rs1use bytes::Bytes;
2
3use crate::{block, consensus, prelude::*, validator, Time};
4
5#[derive(Clone, PartialEq, Eq, Debug)]
9pub struct InitChain {
10 pub time: Time,
12 pub chain_id: String,
14 pub consensus_params: consensus::Params,
16 pub validators: Vec<validator::Update>,
18 pub app_state_bytes: Bytes,
20 pub initial_height: block::Height,
22}
23
24tendermint_pb_modules! {
29 use super::InitChain;
30 use crate::Error;
31
32 impl From<InitChain> for pb::abci::RequestInitChain {
33 fn from(init_chain: InitChain) -> Self {
34 Self {
35 time: Some(init_chain.time.into()),
36 chain_id: init_chain.chain_id,
37 consensus_params: Some(init_chain.consensus_params.into()),
38 validators: init_chain.validators.into_iter().map(Into::into).collect(),
39 app_state_bytes: init_chain.app_state_bytes,
40 initial_height: init_chain.initial_height.into(),
41 }
42 }
43 }
44
45 impl TryFrom<pb::abci::RequestInitChain> for InitChain {
46 type Error = Error;
47
48 fn try_from(init_chain: pb::abci::RequestInitChain) -> Result<Self, Self::Error> {
49 Ok(Self {
50 time: init_chain
51 .time
52 .ok_or_else(Error::missing_genesis_time)?
53 .try_into()?,
54 chain_id: init_chain.chain_id,
55 consensus_params: init_chain
56 .consensus_params
57 .ok_or_else(Error::missing_consensus_params)?
58 .try_into()?,
59 validators: init_chain
60 .validators
61 .into_iter()
62 .map(TryInto::try_into)
63 .collect::<Result<_, _>>()?,
64 app_state_bytes: init_chain.app_state_bytes,
65 initial_height: init_chain.initial_height.try_into()?,
66 })
67 }
68 }
69
70 impl Protobuf<pb::abci::RequestInitChain> for InitChain {}
71}