rust_eigenda_client/
client.rs1use crate::blob_info::BlobInfo;
2use crate::errors::EigenClientError;
3
4use super::{config::EigenConfig, sdk::RawEigenClient};
5use crate::rust_eigenda_signers::{signers::private_key::Signer as PrivateKeySigner, Sign};
6use async_trait::async_trait;
7use std::error::Error;
8use std::sync::Arc;
9
10#[async_trait]
14pub trait BlobProvider: std::fmt::Debug + Send + Sync {
15 async fn get_blob(
18 &self,
19 blob_id: &str,
20 ) -> Result<Option<Vec<u8>>, Box<dyn Error + Send + Sync>>;
21}
22
23#[derive(Debug, Clone)]
25pub struct EigenClient<S = PrivateKeySigner> {
26 pub(crate) client: Arc<RawEigenClient<S>>,
27}
28
29impl<S> EigenClient<S> {
30 pub async fn new(
32 config: EigenConfig,
33 signer: S,
34 blob_provider: Arc<dyn BlobProvider>,
35 ) -> Result<Self, EigenClientError> {
36 let client = RawEigenClient::new(signer, config, blob_provider).await?;
37 Ok(Self {
38 client: Arc::new(client),
39 })
40 }
41
42 pub async fn dispatch_blob(&self, data: Vec<u8>) -> Result<String, EigenClientError>
44 where
45 S: Sign,
46 {
47 let blob_id = self.client.dispatch_blob(data).await?;
48
49 Ok(blob_id)
50 }
51
52 pub async fn get_inclusion_data(
54 &self,
55 blob_id: &str,
56 ) -> Result<Option<Vec<u8>>, EigenClientError> {
57 let inclusion_data = self.client.get_inclusion_data(blob_id).await?;
58 Ok(inclusion_data)
59 }
60
61 pub async fn get_blob_info(&self, blob_id: &str) -> Result<Option<BlobInfo>, EigenClientError> {
63 self.client.get_blob_info(blob_id).await
64 }
65
66 pub async fn check_finality(&self, blob_id: &str) -> Result<bool, EigenClientError> {
68 let blob_info = self
69 .client
70 .try_get_inclusion_data(blob_id.to_string())
71 .await?;
72 Ok(blob_info.is_some())
73 }
74
75 pub fn blob_size_limit(&self) -> Option<usize> {
77 Some(RawEigenClient::<S>::blob_size_limit())
78 }
79
80 pub async fn get_blob(
82 &self,
83 blob_index: u32,
84 batch_header_hash: Vec<u8>,
85 ) -> Result<Option<Vec<u8>>, EigenClientError> {
86 self.client.get_blob(blob_index, batch_header_hash).await
87 }
88}