celestia-client 0.3.0

Celestia client combining RPC and gRPC functionality.
Documentation
use std::sync::Arc;

use celestia_rpc::blobstream::BlobstreamClient;

use crate::Result;
use crate::client::ClientInner;
use crate::types::MerkleProof;
use crate::types::hash::Hash;

/// Blobstream API for quering bridge nodes.
pub struct BlobstreamApi {
    inner: Arc<ClientInner>,
}

impl BlobstreamApi {
    pub(crate) fn new(inner: Arc<ClientInner>) -> BlobstreamApi {
        BlobstreamApi { inner }
    }

    /// Collects the data roots over a provided ordered range of blocks, and then
    /// creates a new Merkle root of those data roots.
    ///
    /// The range is end exclusive.
    pub async fn get_data_root_tuple_root(&self, start: u64, end: u64) -> Result<Hash> {
        Ok(self
            .inner
            .rpc
            .blobstream_get_data_root_tuple_root(start, end)
            .await?)
    }

    /// Creates an inclusion proof, for the data root tuple of block height `height`,
    /// in the set of blocks defined by `start` and `end`.
    ///
    /// The range is end exclusive.
    pub async fn get_data_root_tuple_inclusion_proof(
        &self,
        height: u64,
        start: u64,
        end: u64,
    ) -> Result<MerkleProof> {
        Ok(self
            .inner
            .rpc
            .blobstream_get_data_root_tuple_inclusion_proof(height, start, end)
            .await?)
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    use crate::test_utils::ensure_serializable_deserializable;

    #[allow(dead_code)]
    #[allow(unused_variables)]
    #[allow(unreachable_code)]
    #[allow(clippy::diverging_sub_expression)]
    async fn enforce_serde_bounds() {
        // intentionally no run, compile only test
        let api = BlobstreamApi::new(unimplemented!());

        ensure_serializable_deserializable(api.get_data_root_tuple_root(0, 0).await.unwrap());

        ensure_serializable_deserializable(
            api.get_data_root_tuple_inclusion_proof(0, 0, 0)
                .await
                .unwrap(),
        );
    }
}