feat: add contract code not verified check (#962)
This commit is contained in:
parent
184cffaca3
commit
f1eaee52ef
|
@ -259,7 +259,6 @@ fn get_etherscan_contract(address: Address, domain: &str) -> Result<String> {
|
||||||
// NOTE: We do not retrieve the bytecode since deploying contracts with the
|
// NOTE: We do not retrieve the bytecode since deploying contracts with the
|
||||||
// same bytecode is unreliable as the libraries have already linked and
|
// same bytecode is unreliable as the libraries have already linked and
|
||||||
// probably don't reference anything when deploying on other networks.
|
// probably don't reference anything when deploying on other networks.
|
||||||
|
|
||||||
let api_key = {
|
let api_key = {
|
||||||
let key_res = match domain {
|
let key_res = match domain {
|
||||||
"etherscan.io" => env::var("ETHERSCAN_API_KEY").ok(),
|
"etherscan.io" => env::var("ETHERSCAN_API_KEY").ok(),
|
||||||
|
@ -276,6 +275,11 @@ fn get_etherscan_contract(address: Address, domain: &str) -> Result<String> {
|
||||||
);
|
);
|
||||||
let abi =
|
let abi =
|
||||||
util::http_get(&abi_url).context(format!("failed to retrieve ABI from {}", domain))?;
|
util::http_get(&abi_url).context(format!("failed to retrieve ABI from {}", domain))?;
|
||||||
|
|
||||||
|
if abi.starts_with("Contract source code not verified") {
|
||||||
|
eyre::bail!("Contract source code not verified: {:?}", address);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(abi)
|
Ok(abi)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use ethers_core::abi::{Abi, Address};
|
use ethers_core::abi::{Abi, Address};
|
||||||
|
|
||||||
use crate::{Client, Response, Result};
|
use crate::{Client, EtherscanError, Response, Result};
|
||||||
|
|
||||||
/// Arguments for verifying contracts
|
/// Arguments for verifying contracts
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
@ -236,6 +236,9 @@ impl Client {
|
||||||
pub async fn contract_abi(&self, address: Address) -> Result<Abi> {
|
pub async fn contract_abi(&self, address: Address) -> Result<Abi> {
|
||||||
let query = self.create_query("contract", "getabi", HashMap::from([("address", address)]));
|
let query = self.create_query("contract", "getabi", HashMap::from([("address", address)]));
|
||||||
let resp: Response<String> = self.get_json(&query).await?;
|
let resp: Response<String> = self.get_json(&query).await?;
|
||||||
|
if resp.result.starts_with("Contract source code not verified") {
|
||||||
|
return Err(EtherscanError::ContractCodeNotVerified(address))
|
||||||
|
}
|
||||||
Ok(serde_json::from_str(&resp.result)?)
|
Ok(serde_json::from_str(&resp.result)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,7 +271,7 @@ mod tests {
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
|
|
||||||
use ethers_core::types::Chain;
|
use ethers_core::types::Chain;
|
||||||
use ethers_solc::{MinimalCombinedArtifacts, Project, ProjectPathsConfig};
|
use ethers_solc::{Project, ProjectPathsConfig};
|
||||||
|
|
||||||
use crate::{contract::VerifyContract, tests::run_at_least_duration, Client};
|
use crate::{contract::VerifyContract, tests::run_at_least_duration, Client};
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use ethers_core::types::Chain;
|
use ethers_core::types::{Address, Chain};
|
||||||
use std::env::VarError;
|
use std::env::VarError;
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
|
@ -19,4 +19,6 @@ pub enum EtherscanError {
|
||||||
Reqwest(#[from] reqwest::Error),
|
Reqwest(#[from] reqwest::Error),
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Serde(#[from] serde_json::Error),
|
Serde(#[from] serde_json::Error),
|
||||||
|
#[error("Contract source code not verified: {0}")]
|
||||||
|
ContractCodeNotVerified(Address),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue