celestia-core 0.34.0

This is a hard fork of tendermint to make it compatible with Celestia network. Tendermint is a high-performance blockchain consensus engine that powers Byzantine fault tolerant applications written in any programming language. This crate provides core types for representing information about Tendermint blockchain networks, including chain information types, secret connections, and remote procedure calls (JSON-RPC).
Documentation
use celestia_core_proto::v0_34::types::TxProof as RawTxProof;
use celestia_core_proto::Protobuf;
use serde::{Deserialize, Serialize};

use crate::{merkle, prelude::*, Error, Hash};

/// Merkle proof of the presence of a transaction in the Merkle tree.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(try_from = "RawTxProof", into = "RawTxProof")]
pub struct Proof {
    pub root_hash: Hash,
    pub data: Vec<u8>,
    pub proof: merkle::Proof,
}

impl Protobuf<RawTxProof> for Proof {}

impl TryFrom<RawTxProof> for Proof {
    type Error = Error;

    fn try_from(message: RawTxProof) -> Result<Self, Self::Error> {
        Ok(Self {
            root_hash: message.root_hash.try_into()?,
            data: message.data,
            proof: message.proof.ok_or_else(Error::missing_data)?.try_into()?,
        })
    }
}

impl From<Proof> for RawTxProof {
    fn from(value: Proof) -> Self {
        Self {
            root_hash: value.root_hash.into(),
            data: value.data,
            proof: Some(value.proof.into()),
        }
    }
}