rust_eigenda_client/
client.rs1use crate::errors::{ConfigError, EigenClientError};
2
3use super::{
4 config::{EigenConfig, EigenSecrets},
5 sdk::RawEigenClient,
6};
7use async_trait::async_trait;
8use secp256k1::SecretKey;
9use secrecy::ExposeSecret;
10use std::error::Error;
11use std::{str::FromStr, sync::Arc};
12
13#[async_trait]
17pub trait BlobProvider: std::fmt::Debug + Send + Sync {
18 async fn get_blob(
21 &self,
22 blob_id: &str,
23 ) -> Result<Option<Vec<u8>>, Box<dyn Error + Send + Sync>>;
24}
25
26#[derive(Debug, Clone)]
28pub struct EigenClient {
29 pub(crate) client: Arc<RawEigenClient>,
30}
31
32impl EigenClient {
33 pub async fn new(
35 config: EigenConfig,
36 secrets: EigenSecrets,
37 blob_provider: Arc<dyn BlobProvider>,
38 ) -> Result<Self, EigenClientError> {
39 let private_key = SecretKey::from_str(secrets.private_key.0.expose_secret().as_str())
40 .map_err(ConfigError::Secp)?;
41
42 let client = RawEigenClient::new(private_key, config, blob_provider).await?;
43 Ok(Self {
44 client: Arc::new(client),
45 })
46 }
47
48 pub async fn dispatch_blob(&self, data: Vec<u8>) -> Result<String, EigenClientError> {
50 let blob_id = self.client.dispatch_blob(data).await?;
51
52 Ok(blob_id)
53 }
54
55 pub async fn get_inclusion_data(
57 &self,
58 blob_id: &str,
59 ) -> Result<Option<Vec<u8>>, EigenClientError> {
60 let inclusion_data = self.client.get_inclusion_data(blob_id).await?;
61 Ok(inclusion_data)
62 }
63
64 pub fn blob_size_limit(&self) -> Option<usize> {
66 Some(RawEigenClient::blob_size_limit())
67 }
68}