2022-02-24 12:07:34 +00:00
use ethers_core ::types ::{ Address , Chain } ;
2021-10-17 10:01:20 +00:00
use std ::env ::VarError ;
#[ derive(Debug, thiserror::Error) ]
pub enum EtherscanError {
2022-04-06 02:01:44 +00:00
#[ error( " Chain {0} not supported " ) ]
2021-10-24 18:41:50 +00:00
ChainNotSupported ( Chain ) ,
2022-04-06 02:01:44 +00:00
#[ error( " Contract execution call failed: {0} " ) ]
2021-10-17 10:01:20 +00:00
ExecutionFailed ( String ) ,
2022-04-06 02:01:44 +00:00
#[ error( " Balance failed " ) ]
2022-02-26 14:35:43 +00:00
BalanceFailed ,
2022-04-06 02:01:44 +00:00
#[ error( " Transaction receipt failed " ) ]
2021-10-17 10:01:20 +00:00
TransactionReceiptFailed ,
2022-04-06 02:01:44 +00:00
#[ error( " Gas estimation failed " ) ]
2021-11-27 07:54:20 +00:00
GasEstimationFailed ,
2022-04-06 02:01:44 +00:00
#[ error( " Bad status code: {0} " ) ]
2021-10-17 10:01:20 +00:00
BadStatusCode ( String ) ,
#[ error(transparent) ]
EnvVarNotFound ( #[ from ] VarError ) ,
#[ error(transparent) ]
Reqwest ( #[ from ] reqwest ::Error ) ,
#[ error(transparent) ]
Serde ( #[ from ] serde_json ::Error ) ,
2022-02-24 12:07:34 +00:00
#[ error( " Contract source code not verified: {0} " ) ]
ContractCodeNotVerified ( Address ) ,
2022-04-06 02:01:44 +00:00
#[ error( " Rate limit exceeded " ) ]
RateLimitExceeded ,
2022-03-06 15:21:19 +00:00
#[ error(transparent) ]
IO ( #[ from ] std ::io ::Error ) ,
2022-06-01 15:22:39 +00:00
#[ error( " Local networks (e.g. anvil, ganache, geth --dev) cannot be indexed by etherscan " ) ]
2022-03-30 18:20:23 +00:00
LocalNetworksNotSupported ,
2022-04-06 02:01:44 +00:00
#[ error( " Unknown error: {0} " ) ]
Unknown ( String ) ,
2022-04-29 11:25:52 +00:00
#[ error( " Missing field: {0} " ) ]
Builder ( String ) ,
2022-05-09 17:44:32 +00:00
#[ error( " Missing solc version: {0} " ) ]
MissingSolcVersion ( String ) ,
2022-08-15 17:30:30 +00:00
#[ error( " Invalid API Key " ) ]
InvalidApiKey ,
2022-09-15 19:44:52 +00:00
#[ error( " Sorry, you have been blocked by Cloudflare, See also https://community.cloudflare.com/t/sorry-you-have-been-blocked/110790 " ) ]
BlockedByCloudflare ,
}
/// etherscan/polyscan is protected by cloudflare, which can lead to html responses like `Sorry, you have been blocked` See also <https://community.cloudflare.com/t/sorry-you-have-been-blocked/110790>
///
/// This returns true if the `txt` is a cloudflare error response
pub ( crate ) fn is_blocked_by_cloudflare_response ( txt : & str ) -> bool {
txt . to_lowercase ( ) . contains ( " sorry, you have been blocked " )
2021-10-17 10:01:20 +00:00
}