Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

fix(verify): make verification result an option to handle blockscout's format #2426

Merged
merged 5 commits into from
May 23, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions ethers-etherscan/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,17 +331,23 @@ impl Client {
}

let query = self.create_query("contract", "getabi", HashMap::from([("address", address)]));
let resp: Response<String> = self.get_json(&query).await?;
if resp.result.starts_with("Max rate limit reached") {
let resp: Response<Option<String>> = self.get_json(&query).await?;

let result = resp.result.unwrap_or("".to_string());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null will now always be a serde error,

I'd rather have a new error variant for EmptyResult or something

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 94ad922 — we now bubble up the error with an EmptyResult variant


if result.starts_with("Max rate limit reached") {
return Err(EtherscanError::RateLimitExceeded)
}
if resp.result.starts_with("Contract source code not verified") {

if result.starts_with("Contract source code not verified") ||
resp.message.starts_with("Contract source code not verified")
{
if let Some(ref cache) = self.cache {
cache.set_abi(address, None);
}
return Err(EtherscanError::ContractCodeNotVerified(address))
}
let abi = serde_json::from_str(&resp.result)?;
let abi = serde_json::from_str(&result)?;

if let Some(ref cache) = self.cache {
cache.set_abi(address, Some(&abi));
Expand Down