-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change anyhow for thiserror #1
Changes from all commits
25ada9c
a44decf
6a439ae
c925859
402ec48
4974c95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,3 @@ async-trait = "0.1" | |
hex = "0.4" | ||
secrecy = "0.8.0" | ||
byteorder = "1.5.0" | ||
|
||
|
||
|
||
anyhow = "1" #TODO: Remove |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
use crate::errors::{CommunicationError, ConfigError, EigenClientError}; | ||
|
||
use super::{ | ||
blob_info::BlobInfo, | ||
config::{EigenConfig, EigenSecrets}, | ||
|
@@ -14,36 +16,37 @@ pub struct EigenClient { | |
} | ||
|
||
impl EigenClient { | ||
pub async fn new(config: EigenConfig, secrets: EigenSecrets) -> anyhow::Result<Self> { | ||
pub async fn new(config: EigenConfig, secrets: EigenSecrets) -> Result<Self, EigenClientError> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is using a single huge crate-level error enum like It feels a bit weird to me. Wouldn't it be better to have a specific error enum per method? For eg, one guy says:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having a single error type that encapsulates the possible errors from a library makes it easier to use (specially if you use several modules from the same library together). We did a small refactor of the error types since your last review. So feel free to take a look again. |
||
let private_key = SecretKey::from_str(secrets.private_key.0.expose_secret().as_str()) | ||
.map_err(|e| anyhow::anyhow!("Failed to parse private key: {}", e))?; | ||
.map_err(ConfigError::Secp)?; | ||
|
||
let client = RawEigenClient::new(private_key, config).await?; | ||
Ok(Self { | ||
client: Arc::new(client), | ||
}) | ||
} | ||
|
||
pub async fn get_commitment(&self, blob_id: &str) -> anyhow::Result<String> { | ||
pub async fn get_commitment(&self, blob_id: &str) -> Result<String, EigenClientError> { | ||
let blob_info = self.client.get_inclusion_data(blob_id).await?; | ||
Ok(blob_info) | ||
} | ||
|
||
async fn dispatch_blob(&self, data: Vec<u8>) -> anyhow::Result<String> { | ||
pub async fn dispatch_blob(&self, data: Vec<u8>) -> Result<String, EigenClientError> { | ||
let blob_id = self.client.dispatch_blob(data).await?; | ||
|
||
Ok(blob_id) | ||
} | ||
|
||
async fn get_inclusion_data(&self, blob_id: &str) -> anyhow::Result<Vec<u8>> { | ||
pub async fn get_inclusion_data(&self, blob_id: &str) -> Result<Vec<u8>, EigenClientError> { | ||
let blob_info = self.get_commitment(blob_id).await?; | ||
let rlp_encoded_bytes = hex::decode(blob_info)?; | ||
let blob_info: BlobInfo = rlp::decode(&rlp_encoded_bytes)?; | ||
let rlp_encoded_bytes = hex::decode(blob_info).map_err(CommunicationError::Hex)?; | ||
let blob_info: BlobInfo = | ||
rlp::decode(&rlp_encoded_bytes).map_err(CommunicationError::Rlp)?; | ||
let inclusion_data = blob_info.blob_verification_proof.inclusion_proof; | ||
Ok(inclusion_data) | ||
} | ||
|
||
fn blob_size_limit(&self) -> Option<usize> { | ||
pub fn blob_size_limit(&self) -> Option<usize> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it necessary to expose this? |
||
Some(RawEigenClient::blob_size_limit()) | ||
} | ||
} | ||
|
@@ -61,7 +64,10 @@ mod tests { | |
use crate::blob_info::BlobInfo; | ||
|
||
impl EigenClient { | ||
pub async fn get_blob_data(&self, blob_id: &str) -> anyhow::Result<Option<Vec<u8>>> { | ||
pub async fn get_blob_data( | ||
&self, | ||
blob_id: &str, | ||
) -> Result<Option<Vec<u8>>, EigenClientError> { | ||
self.client.get_blob_data(blob_id).await | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are you deleting all these to_bytes? Were they used for something before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they were not needed.