diff --git a/ethers-core/src/types/chain.rs b/ethers-core/src/types/chain.rs index 01da44d4..5397e78f 100644 --- a/ethers-core/src/types/chain.rs +++ b/ethers-core/src/types/chain.rs @@ -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 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, diff --git a/ethers-etherscan/src/errors.rs b/ethers-etherscan/src/errors.rs index fcd59263..cad7a808 100644 --- a/ethers-etherscan/src/errors.rs +++ b/ethers-etherscan/src/errors.rs @@ -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, } diff --git a/ethers-etherscan/src/lib.rs b/ethers-etherscan/src/lib.rs index 4bf20b35..2a0ad068 100644 --- a/ethers-etherscan/src/lib.rs +++ b/ethers-etherscan/src/lib.rs @@ -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; diff --git a/ethers-signers/src/wallet/mod.rs b/ethers-signers/src/wallet/mod.rs index 65e8e7d1..efde9cf2 100644 --- a/ethers-signers/src/wallet/mod.rs +++ b/ethers-signers/src/wallet/mod.rs @@ -117,10 +117,6 @@ impl> 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 }