Skip to content

Commit

Permalink
remove unwraps
Browse files Browse the repository at this point in the history
  • Loading branch information
juan518munoz committed Sep 16, 2024
1 parent f7b3f75 commit d3b9d70
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions core/node/da_clients/src/eigen_da.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::fmt::Debug;
use async_trait::async_trait;
use zksync_config::configs::da_client::eigen_da::EigenDAConfig;
use zksync_da_client::{
types::{self, InclusionData},
types::{self, DAError, InclusionData},
DataAvailabilityClient,
};

Expand Down Expand Up @@ -31,17 +31,20 @@ impl DataAvailabilityClient for EigenDAClient {
_batch_number: u32,
blob_data: Vec<u8>,
) -> Result<types::DispatchResponse, types::DAError> {
tracing::info!("Dispatching blob to Eigen DA");
let response = self
.client
.post(format!("{}/put/", self.config.api_node_url))
.header(http::header::CONTENT_TYPE, "application/octet-stream")
.body(blob_data)
.send()
.await
.unwrap();
.map_err(to_retriable_error)?;

let request_id = response.bytes().await.unwrap().to_vec();
let request_id = response
.bytes()
.await
.map_err(to_non_retriable_da_error)?
.to_vec();
Ok(types::DispatchResponse {
blob_id: hex::encode(request_id),
})
Expand All @@ -55,8 +58,12 @@ impl DataAvailabilityClient for EigenDAClient {
.get(format!("{}/get/0x{}", self.config.api_node_url, blob_id))
.send()
.await
.unwrap();
let data = response.bytes().await.unwrap().to_vec();
.map_err(to_retriable_error)?;
let data = response
.bytes()
.await
.map_err(to_non_retriable_da_error)?
.to_vec();
Ok(Some(InclusionData { data }))
}

Expand All @@ -71,17 +78,16 @@ impl DataAvailabilityClient for EigenDAClient {

// Note: This methods should be uncommented if the `get_inclusion_data` method
// implementation gets uncommented.
//
// fn to_retriable_error(error: anyhow::Error) -> types::DAError {
// types::DAError {
// error,
// is_retriable: true,
// }
// }
fn to_retriable_error(error: impl Into<anyhow::Error>) -> DAError {
DAError {
error: error.into(),
is_retriable: true,
}
}

// fn to_non_retriable_error(error: anyhow::Error) -> types::DAError {
// types::DAError {
// error,
// is_retriable: false,
// }
// }
fn to_non_retriable_da_error(error: impl Into<anyhow::Error>) -> DAError {
DAError {
error: error.into(),
is_retriable: false,
}
}

0 comments on commit d3b9d70

Please sign in to comment.