-
Notifications
You must be signed in to change notification settings - Fork 795
fix(verify
): make verification result an option to handle blockscout's format
#2426
fix(verify
): make verification result an option to handle blockscout's format
#2426
Conversation
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.
nice find!
ethers-etherscan/src/contract.rs
Outdated
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()); |
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.
null will now always be a serde error,
I'd rather have a new error variant for EmptyResult or something
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.
done in 94ad922 — we now bubble up the error with an EmptyResult
variant
ethers-etherscan/src/errors.rs
Outdated
#[error("Response result is unexpectedly empty")] | ||
EmptyResult { status: String, message: 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.
Should the error message include status
or message
?
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.
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
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.
done on fa5c243
Motivation
I've been investigating verification issues due to foundry-rs/foundry#4909 — and it turns out that blockscout, unlike etherscan, likes to return
null
on theresult
field sometimes, instead of an empty string onmessage
and the actual message on theresult
field, like etherscan. This in turn introduced a bug when detecting if a contract was already verified as it expects that the blockscout format is identical to etherscan's.To be a bit more specifc, this format is returned by blockscout when a contract is not verified, and this is not what etherscan returns (see the
null
in result):While making a blockscout verification client might be the "best" fix, this is a slight difference in formats and I opted for this solution instead. We can handle separating blockscout & etherscan verification later.
Solution
Parses the
result
field from the API response as an Option instead of just a string, to handle cases where result isnull
.