-
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
base: client-implementation
Are you sure you want to change the base?
Changes from 4 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::EigenClientError; | ||
|
||
use super::{ | ||
blob_info::BlobInfo, | ||
config::{EigenConfig, EigenSecrets}, | ||
|
@@ -14,36 +16,35 @@ pub struct EigenClient { | |
} | ||
|
||
impl EigenClient { | ||
pub async fn new(config: EigenConfig, secrets: EigenSecrets) -> anyhow::Result<Self> { | ||
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))?; | ||
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())?; | ||
|
||
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 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 +62,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 | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
use tonic::{transport::Error as TonicError, Status}; | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
pub enum EigenClientError { | ||
#[error(transparent)] | ||
EthClient(#[from] EthClientError), | ||
#[error(transparent)] | ||
Verification(#[from] VerificationError), | ||
#[error("Private Key Error")] | ||
PrivateKey, | ||
#[error(transparent)] | ||
Secp(#[from] secp256k1::Error), | ||
#[error(transparent)] | ||
Hex(#[from] hex::FromHexError), | ||
#[error(transparent)] | ||
Rlp(#[from] rlp::DecoderError), | ||
#[error(transparent)] | ||
Tonic(#[from] TonicError), | ||
#[error(transparent)] | ||
Status(#[from] Status), | ||
#[error("No response from server")] | ||
NoResponseFromServer, | ||
#[error("No payload in response")] | ||
NoPayloadInResponse, | ||
#[error("Unexpected response from server")] | ||
UnexpectedResponseFromServer, | ||
#[error("Failed to get blob data")] | ||
FailedToGetBlobData, | ||
#[error("Failed to send DisperseBlobRequest: {0}")] | ||
DisperseBlob(String), | ||
#[error("Failed to send AuthenticationData: {0}")] | ||
AuthenticationData(String), | ||
#[error("Error from server: {0}")] | ||
ErrorFromServer(String), | ||
#[error("Blob still processing")] | ||
BlobStillProcessing, | ||
#[error("Blob dispatched failed")] | ||
BlobDispatchedFailed, | ||
#[error("Insufficient signatures")] | ||
InsufficientSignatures, | ||
#[error("No blob header in response")] | ||
NoBlobHeaderInResponse, | ||
#[error("Received unknown blob status")] | ||
ReceivedUnknownBlobStatus, | ||
#[error(transparent)] | ||
Conversion(#[from] ConversionError), | ||
#[error(transparent)] | ||
Prost(#[from] prost::DecodeError), | ||
} | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
pub enum ConversionError { | ||
#[error("Failed to convert {0}")] | ||
NotPresent(String), | ||
} | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
pub enum EthClientError { | ||
#[error("Failed to serialize request body: {0}")] | ||
FailedToSerializeRequestBody(String), | ||
juanbono marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#[error(transparent)] | ||
gianbelinche marked this conversation as resolved.
Show resolved
Hide resolved
|
||
HTTPClient(#[from] reqwest::Error), | ||
#[error(transparent)] | ||
SerdeJSON(#[from] serde_json::Error), | ||
#[error("RPC: {0}")] | ||
RPC(String), | ||
} | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
pub enum VerificationError { | ||
#[error("Service Manager Error: {0}")] | ||
ServiceManager(String), | ||
#[error("Kzg Error: {0}")] | ||
Kzg(String), | ||
#[error("Wrong proof")] | ||
WrongProof, | ||
#[error("Different commitments")] | ||
DifferentCommitments, | ||
#[error("Different roots")] | ||
DifferentRoots, | ||
#[error("Empty hashes")] | ||
EmptyHash, | ||
#[error("Different hashes")] | ||
DifferentHashes, | ||
#[error("Wrong quorum params")] | ||
WrongQuorumParams, | ||
#[error("Quorum not confirmed")] | ||
QuorumNotConfirmed, | ||
#[error("Commitment not on curve")] | ||
CommitmentNotOnCurve, | ||
#[error("Commitment not on correct subgroup")] | ||
CommitmentNotOnCorrectSubgroup, | ||
#[error("Link Error: {0}")] | ||
Link(String), | ||
} |
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.