Skip to content

Commit

Permalink
Update 'search_sourcify_sources' handler to support newest sourcify l…
Browse files Browse the repository at this point in the history
…ib (#576)
  • Loading branch information
rimrakhimov authored Aug 14, 2023
1 parent e61bd59 commit b041cd8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion eth-bytecode-db/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion eth-bytecode-db/eth-bytecode-db-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ sea-orm = "0.11"
serde = "1.0"
serde_json = "1.0.96"
serde_with = "2.1"
sourcify = { git = "https://github.com/blockscout/blockscout-rs", branch = "rimrakhimov/libs/sourcify" }
sourcify = { git = "https://github.com/blockscout/blockscout-rs", rev = "e61bd59" }
tokio = { version = "1.23", features = [ "rt-multi-thread", "macros" ] }
tonic = "0.8"
tracing = "0.1"
Expand Down
11 changes: 7 additions & 4 deletions eth-bytecode-db/eth-bytecode-db-server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,13 @@ pub async fn run(settings: Settings) -> Result<(), anyhow::Error> {
.sourcify
.enabled
.then(|| {
sourcify::ClientBuilder::default()
.base_url(&settings.database.sourcify.base_url)
.total_duration(settings.database.sourcify.total_request_duration)
.build()
Ok::<_, anyhow::Error>(
sourcify::ClientBuilder::default()
.try_base_url(&settings.database.sourcify.base_url)
.map_err(|err| anyhow::anyhow!(err))?
.total_duration(settings.database.sourcify.total_request_duration)
.build(),
)
})
.transpose()?;
let database = Arc::new(DatabaseService::new_arc(db_connection, sourcify_client));
Expand Down
16 changes: 8 additions & 8 deletions eth-bytecode-db/eth-bytecode-db-server/src/services/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,16 @@ impl Database for DatabaseService {
}
}

fn process_sourcify_error(error: sourcify::Error) -> Option<tonic::Status> {
fn process_sourcify_error(
error: sourcify::Error<sourcify::EmptyCustomError>,
) -> Option<tonic::Status> {
match error {
sourcify::Error::InvalidArgument { .. }
| sourcify::Error::Reqwest(_)
| sourcify::Error::ReqwestMiddleware(_) => {
sourcify::Error::Reqwest(_) | sourcify::Error::ReqwestMiddleware(_) => {
tracing::error!(target: "sourcify", "{error}");
Some(tonic::Status::internal(
"sending request to sourcify failed",
))
}
sourcify::Error::Sourcify(sourcify::SourcifyError::TooManyRequests(_)) => {
tracing::error!(target: "sourcify", "{error}");
Some(tonic::Status::resource_exhausted(error.to_string()))
}
sourcify::Error::Sourcify(sourcify::SourcifyError::InternalServerError(_)) => {
tracing::error!(target: "sourcify", "{error}");
Some(tonic::Status::internal("sourcify responded with error"))
Expand All @@ -132,5 +128,9 @@ fn process_sourcify_error(error: sourcify::Error) -> Option<tonic::Status> {
tracing::error!(target: "sourcify", "{error}");
Some(tonic::Status::internal("sourcify responded with error"))
}
sourcify::Error::Sourcify(sourcify::SourcifyError::Custom(_)) => {
// `EmptyCustomError` enum has no variants and cannot be initialized
unreachable!()
}
}
}

0 comments on commit b041cd8

Please sign in to comment.