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
Show file tree
Hide file tree
Changes from 4 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
22 changes: 18 additions & 4 deletions ethers-etherscan/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,17 +331,31 @@ 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 = match resp.result {
Some(result) => result,
None => {
return Err(EtherscanError::EmptyResult {
message: resp.message,
status: resp.status,
})
}
};

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
2 changes: 2 additions & 0 deletions ethers-etherscan/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub enum EtherscanError {
Serde(#[from] serde_json::Error),
#[error("Contract source code not verified: {0}")]
ContractCodeNotVerified(Address),
#[error("Response result is unexpectedly empty")]
EmptyResult { status: String, message: String },
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should the error message include status or message?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yeah, let's include both! the status should only be a number so it's short. The message is what actually has the error

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 on fa5c243

#[error("Rate limit exceeded")]
RateLimitExceeded,
#[error(transparent)]
Expand Down