feat: add anvil hardhat chain id (#1356)
* feat: add anvil hardhat chain id * chore: cover anvil hh
This commit is contained in:
parent
d6d76c6024
commit
0abc3ca39a
|
@ -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}")]
|
||||
|
@ -26,6 +27,7 @@ pub enum Chain {
|
|||
Polygon = 137,
|
||||
Fantom = 250,
|
||||
Dev = 1337,
|
||||
AnvilHardhat = 31337,
|
||||
FantomTestnet = 4002,
|
||||
PolygonMumbai = 80001,
|
||||
Avalanche = 43114,
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -225,7 +230,7 @@ impl Chain {
|
|||
}
|
||||
}
|
||||
|
||||
impl default::Default for Chain {
|
||||
impl Default for Chain {
|
||||
fn default() -> Self {
|
||||
Chain::Mainnet
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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?)
|
||||
|
|
Loading…
Reference in New Issue