tendermint/tx/
proof.rs

1use serde::{Deserialize, Serialize};
2use tendermint_proto::v0_37::types::TxProof as RawTxProof;
3use tendermint_proto::Protobuf;
4
5use crate::{merkle, prelude::*, Error, Hash};
6
7/// Merkle proof of the presence of a transaction in the Merkle tree.
8#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
9#[serde(try_from = "RawTxProof", into = "RawTxProof")]
10pub struct Proof {
11    pub root_hash: Hash,
12    pub data: Vec<u8>,
13    pub proof: merkle::Proof,
14}
15
16impl Protobuf<RawTxProof> for Proof {}
17
18impl TryFrom<RawTxProof> for Proof {
19    type Error = Error;
20
21    fn try_from(message: RawTxProof) -> Result<Self, Self::Error> {
22        Ok(Self {
23            root_hash: message.root_hash.try_into()?,
24            data: message.data,
25            proof: message.proof.ok_or_else(Error::missing_data)?.try_into()?,
26        })
27    }
28}
29
30impl From<Proof> for RawTxProof {
31    fn from(value: Proof) -> Self {
32        Self {
33            root_hash: value.root_hash.into(),
34            data: value.data,
35            proof: Some(value.proof.into()),
36        }
37    }
38}