Skip to content

Commit

Permalink
remove unwraps
Browse files Browse the repository at this point in the history
  • Loading branch information
juan518munoz committed Oct 22, 2024
1 parent cdec06c commit aff1048
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
4 changes: 3 additions & 1 deletion core/node/eigenda_proxy/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ pub enum EigenDAError {
GetError,
}

pub(crate) enum RequestProcessorError {}
pub(crate) enum RequestProcessorError {
EigenDA(EigenDAError),
}

impl IntoResponse for RequestProcessorError {
fn into_response(self) -> Response {
Expand Down
7 changes: 4 additions & 3 deletions core/node/eigenda_proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ pub async fn run_server(
mut stop_receiver: watch::Receiver<bool>,
) -> anyhow::Result<()> {
// TODO: Replace port for config

let bind_address = SocketAddr::from(([0, 0, 0, 0], 4242));
tracing::debug!("Starting eigenda proxy on {bind_address}");

let eigenda_client = match config {
EigenDAConfig::Disperser(disperser_config) => {
EigenDAClient::new(disperser_config).await.unwrap()
}
EigenDAConfig::Disperser(disperser_config) => EigenDAClient::new(disperser_config)
.await
.map_err(|e| anyhow::anyhow!("Failed to create EigenDA client: {:?}", e))?,
_ => panic!("memstore unimplemented"),
};
let app = create_eigenda_proxy_router(eigenda_client);
Expand Down
25 changes: 18 additions & 7 deletions core/node/eigenda_proxy/src/request_processor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use axum::{extract::Path, http::Response};

use crate::eigenda_client::EigenDAClient;
use crate::{eigenda_client::EigenDAClient, errors::RequestProcessorError};

#[derive(Clone)]
pub(crate) struct RequestProcessor {
Expand All @@ -15,15 +15,26 @@ impl RequestProcessor {
pub(crate) async fn get_blob_id(
&self,
Path(blob_id): Path<String>,
) -> axum::response::Response {
) -> Result<axum::response::Response, RequestProcessorError> {
let blob_id_bytes = hex::decode(blob_id).unwrap();
let response = self.eigenda_client.get_blob(blob_id_bytes).await.unwrap();
Response::new(response.into())
let response = self
.eigenda_client
.get_blob(blob_id_bytes)
.await
.map_err(|e| RequestProcessorError::EigenDA(e))?;
Ok(Response::new(response.into()))
}

pub(crate) async fn put_blob_id(&self, Path(data): Path<String>) -> axum::response::Response {
pub(crate) async fn put_blob_id(
&self,
Path(data): Path<String>,
) -> Result<axum::response::Response, RequestProcessorError> {
let data_bytes = hex::decode(data).unwrap();
let response = self.eigenda_client.put_blob(data_bytes).await.unwrap();
Response::new(response.into())
let response = self
.eigenda_client
.put_blob(data_bytes)
.await
.map_err(|e| RequestProcessorError::EigenDA(e))?;
Ok(Response::new(response.into()))
}
}

0 comments on commit aff1048

Please sign in to comment.