Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
juan518munoz committed Dec 9, 2024
1 parent f75e703 commit f2aa6f2
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 11 deletions.
42 changes: 37 additions & 5 deletions get_all_blobs/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use tonic::transport::{Channel, ClientTlsConfig, Endpoint};

use crate::{
blob_info::BlobInfo,
generated::{disperser, disperser::disperser_client::DisperserClient},
generated::disperser::{self, disperser_client::DisperserClient},
};

#[derive(Debug, Clone)]
Expand All @@ -22,10 +22,7 @@ impl EigenClientRetriever {
Ok(EigenClientRetriever { client })
}

pub async fn get_blob_data(&self, blob_id: &str) -> anyhow::Result<Option<Vec<u8>>> {
let commit = hex::decode(blob_id)?;

let blob_info: BlobInfo = rlp::decode(&commit)?;
pub async fn get_blob_data(&self, blob_info: BlobInfo) -> anyhow::Result<Option<Vec<u8>>> {
let blob_index = blob_info.blob_verification_proof.blob_index;
let batch_header_hash = blob_info
.blob_verification_proof
Expand All @@ -49,4 +46,39 @@ impl EigenClientRetriever {
let data = kzgpad_rs::remove_empty_byte_from_padded_bytes(&get_response.data);
Ok(Some(data))
}

pub async fn get_blob_status(&self, blob_id: &str) -> anyhow::Result<Option<BlobInfo>> {
let polling_request = disperser::BlobStatusRequest {
request_id: hex::decode(blob_id)?,
};

let resp = self
.client
.clone()
.get_blob_status(polling_request.clone())
.await?
.into_inner();

match disperser::BlobStatus::try_from(resp.status)? {
disperser::BlobStatus::Processing | disperser::BlobStatus::Dispersing => Ok(None),
disperser::BlobStatus::Failed => Err(anyhow::anyhow!("Blob dispatch failed")),
disperser::BlobStatus::InsufficientSignatures => {
Err(anyhow::anyhow!("Insufficient signatures"))
}
disperser::BlobStatus::Confirmed => {
let blob_info = resp
.info
.ok_or_else(|| anyhow::anyhow!("No blob header in response"))?;
Ok(Some(blob_info.try_into().unwrap()))
}
disperser::BlobStatus::Finalized => {
let blob_info = resp
.info
.ok_or_else(|| anyhow::anyhow!("No blob header in response"))?;
Ok(Some(blob_info.try_into().unwrap()))
}

_ => Err(anyhow::anyhow!("Received unknown blob status")),
}
}
}
18 changes: 12 additions & 6 deletions get_all_blobs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mod generated;

#[derive(Debug, Serialize, Deserialize)]
struct BlobData {
pub commitment: String,
pub blob_id: String,
pub blob: String,
}

Expand All @@ -27,10 +27,16 @@ const COMMIT_BATCHES_SELECTOR: &str = "6edd4f12";

async fn get_blob(commitment: &str) -> anyhow::Result<Vec<u8>> {
let client = EigenClientRetriever::new(EIGENDA_API_URL).await?;
let blob_id = commitment;
let blob_info = client
.get_blob_status(blob_id)
.await?
.ok_or_else(|| anyhow::anyhow!("Blob not found"))?;
let data = client
.get_blob_data(commitment)
.get_blob_data(blob_info)
.await?
.ok_or_else(|| anyhow::anyhow!("Blob not found"))?;

Ok(data)
}

Expand Down Expand Up @@ -128,11 +134,11 @@ async fn get_blob_from_pubdata_commitment(
));
}
let pubdata_commitments_bytes = pubdata_commitments_bytes.unwrap();
let commitment = hex::decode(&pubdata_commitments_bytes[1..])?;
let commitment = hex::encode(&commitment);
let blob = get_blob(&commitment).await?;
let blob_id = hex::decode(&pubdata_commitments_bytes[1..])?;
let blob_id = hex::encode(&blob_id);
let blob = get_blob(&blob_id).await?;
Ok(BlobData {
commitment,
blob_id,
blob: hex::encode(blob),
})
}
Expand Down

0 comments on commit f2aa6f2

Please sign in to comment.