feat(core): add dev as a chain (#1093)
adds a new error message to etherscan if the user tries to create an etherscan client with a 1337/ganache/dev chain
This commit is contained in:
parent
3a653472cf
commit
842f4d260f
|
@ -22,6 +22,7 @@ pub enum Chain {
|
|||
XDai = 100,
|
||||
Polygon = 137,
|
||||
Fantom = 250,
|
||||
Dev = 1337,
|
||||
FantomTestnet = 4002,
|
||||
PolygonMumbai = 80001,
|
||||
Avalanche = 43114,
|
||||
|
@ -60,6 +61,7 @@ impl fmt::Display for Chain {
|
|||
Chain::Optimism => "optimism",
|
||||
Chain::OptimismKovan => "optimism-kovan",
|
||||
Chain::Fantom => "fantom",
|
||||
Chain::Dev => "dev",
|
||||
Chain::FantomTestnet => "fantom-testnet",
|
||||
Chain::BinanceSmartChain => "bsc",
|
||||
Chain::BinanceSmartChainTestnet => "bsc-testnet",
|
||||
|
@ -103,6 +105,7 @@ impl TryFrom<u64> for Chain {
|
|||
42 => Chain::Kovan,
|
||||
100 => Chain::XDai,
|
||||
137 => Chain::Polygon,
|
||||
1337 => Chain::Dev,
|
||||
250 => Chain::Fantom,
|
||||
4002 => Chain::FantomTestnet,
|
||||
80001 => Chain::PolygonMumbai,
|
||||
|
@ -147,6 +150,7 @@ impl FromStr for Chain {
|
|||
"optimism-kovan" => Chain::OptimismKovan,
|
||||
"fantom" => Chain::Fantom,
|
||||
"fantom-testnet" => Chain::FantomTestnet,
|
||||
"dev" => Chain::Dev,
|
||||
"bsc" => Chain::BinanceSmartChain,
|
||||
"bsc-testnet" => Chain::BinanceSmartChainTestnet,
|
||||
"arbitrum" => Chain::Arbitrum,
|
||||
|
|
|
@ -25,4 +25,6 @@ pub enum EtherscanError {
|
|||
ContractCodeNotVerified(Address),
|
||||
#[error(transparent)]
|
||||
IO(#[from] std::io::Error),
|
||||
#[error("Local networks (e.g. ganache, geth --dev) cannot be indexed by etherscan")]
|
||||
LocalNetworksNotSupported,
|
||||
}
|
||||
|
|
|
@ -92,6 +92,7 @@ impl Client {
|
|||
Chain::Cronos => {
|
||||
(Url::parse("https://api.cronoscan.com/api"), Url::parse("https://cronoscan.com"))
|
||||
}
|
||||
Chain::Dev => return Err(EtherscanError::LocalNetworksNotSupported),
|
||||
chain => return Err(EtherscanError::ChainNotSupported(chain)),
|
||||
};
|
||||
|
||||
|
@ -128,6 +129,7 @@ impl Client {
|
|||
Chain::Moonbeam | Chain::MoonbeamDev | Chain::Moonriver => {
|
||||
std::env::var("MOONSCAN_API_KEY")?
|
||||
}
|
||||
Chain::Dev => return Err(errors::EtherscanError::LocalNetworksNotSupported),
|
||||
};
|
||||
Self::new(chain, api_key)
|
||||
}
|
||||
|
@ -241,6 +243,12 @@ mod tests {
|
|||
assert_eq!(err.to_string(), "chain xdai not supported");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn local_networks_not_supported() {
|
||||
let err = Client::new_from_env(Chain::Dev).unwrap_err();
|
||||
assert!(matches!(err, EtherscanError::LocalNetworksNotSupported));
|
||||
}
|
||||
|
||||
pub async fn run_at_least_duration(duration: Duration, block: impl Future) {
|
||||
let start = SystemTime::now();
|
||||
block.await;
|
||||
|
|
|
@ -117,10 +117,6 @@ impl<D: Sync + Send + DigestSigner<Sha256Proxy, RecoverableSignature>> Signer fo
|
|||
}
|
||||
|
||||
/// Gets the wallet's chain id
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// If the chain id has not already been set.
|
||||
fn chain_id(&self) -> u64 {
|
||||
self.chain_id
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue