Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

feat: add anvil hardhat chain id #1356

Merged
merged 2 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions ethers-core/src/types/chain.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use serde::Deserialize;
use thiserror::Error;

use core::convert::TryFrom;
use std::{convert::TryInto, default, fmt, str::FromStr};

use crate::types::U256;
use serde::Deserialize;
use std::{
convert::{TryFrom, TryInto},
fmt,
str::FromStr,
};
use strum::EnumVariantNames;
use thiserror::Error;

#[derive(Debug, Clone, Error)]
#[error("Failed to parse chain: {0}")]
Expand All @@ -26,6 +27,7 @@ pub enum Chain {
Polygon = 137,
Fantom = 250,
Dev = 1337,
AnvilHardhat = 31337,
FantomTestnet = 4002,
PolygonMumbai = 80001,
Avalanche = 43114,
Expand Down Expand Up @@ -86,6 +88,7 @@ impl fmt::Display for Chain {
Chain::Oasis => "oasis",
Chain::Emerald => "emerald",
Chain::EmeraldTestnet => "emerald-testnet",
Chain::AnvilHardhat => "anvil-hardhat",
};

write!(formatter, "{}", chain)
Expand Down Expand Up @@ -123,6 +126,7 @@ impl TryFrom<u64> for Chain {
100 => Chain::XDai,
137 => Chain::Polygon,
1337 => Chain::Dev,
31337 => Chain::Dev,
250 => Chain::Fantom,
4002 => Chain::FantomTestnet,
80001 => Chain::PolygonMumbai,
Expand Down Expand Up @@ -185,6 +189,7 @@ impl FromStr for Chain {
"fantom" => Chain::Fantom,
"fantom-testnet" => Chain::FantomTestnet,
"dev" => Chain::Dev,
"anvil" | "hardhat" | "anvil-hardhat" => Chain::AnvilHardhat,
"bsc" => Chain::BinanceSmartChain,
"bsc-testnet" => Chain::BinanceSmartChainTestnet,
"arbitrum" => Chain::Arbitrum,
Expand Down Expand Up @@ -225,7 +230,7 @@ impl Chain {
}
}

impl default::Default for Chain {
impl Default for Chain {
fn default() -> Self {
Chain::Mainnet
}
Expand Down
27 changes: 14 additions & 13 deletions ethers-etherscan/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
//! Bindings for [etherscan.io web api](https://docs.etherscan.io/)

use contract::ContractMetadata;
use errors::EtherscanError;
use ethers_core::{
abi::{Abi, Address},
types::{Chain, H256},
};
use reqwest::{header, IntoUrl, Url};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use std::{
borrow::Cow,
io::Write,
path::PathBuf,
time::{Duration, SystemTime, UNIX_EPOCH},
};

use contract::ContractMetadata;
use reqwest::{header, IntoUrl, Url};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use tracing::trace;

use errors::EtherscanError;
use ethers_core::{
abi::{Abi, Address},
types::{Chain, H256},
};

pub mod account;
pub mod contract;
pub mod errors;
Expand Down Expand Up @@ -108,7 +105,9 @@ impl Client {
Chain::Moonbeam | Chain::MoonbeamDev | Chain::Moonriver => {
std::env::var("MOONSCAN_API_KEY")?
}
Chain::Dev => return Err(EtherscanError::LocalNetworksNotSupported),
Chain::AnvilHardhat | Chain::Dev => {
return Err(EtherscanError::LocalNetworksNotSupported)
}
};
Self::new(chain, api_key)
}
Expand Down Expand Up @@ -297,7 +296,9 @@ impl ClientBuilder {
"https://testnet.explorer.emerald.oasis.dev/api",
"https://testnet.explorer.emerald.oasis.dev/",
),
Chain::Dev => return Err(EtherscanError::LocalNetworksNotSupported),
Chain::AnvilHardhat | Chain::Dev => {
return Err(EtherscanError::LocalNetworksNotSupported)
}
chain => return Err(EtherscanError::ChainNotSupported(chain)),
};
self.with_api_url(etherscan_api_url?)?.with_url(etherscan_url?)
Expand Down