cosm_tome_wasm_deploy_fork/modules/tendermint/
model.rs

1use cosmrs::proto::{
2    cosmos::base::tendermint::v1beta1::GetLatestBlockResponse,
3    tendermint::types::{Block, BlockId},
4};
5use serde::{Deserialize, Serialize};
6
7use super::error::TendermintError;
8
9#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
10pub struct BlockResponse {
11    pub id: BlockId,
12    pub block: Block,
13}
14
15impl TryFrom<GetLatestBlockResponse> for BlockResponse {
16    type Error = TendermintError;
17
18    fn try_from(res: GetLatestBlockResponse) -> Result<Self, Self::Error> {
19        Ok(Self {
20            id: res.block_id.ok_or(TendermintError::MissingBlockId)?,
21            block: res.block.ok_or(TendermintError::MissingBlock)?,
22        })
23    }
24}
25
26impl From<BlockResponse> for GetLatestBlockResponse {
27    fn from(res: BlockResponse) -> Self {
28        Self {
29            block_id: Some(res.id),
30            block: Some(res.block),
31        }
32    }
33}