diff --git a/ethers-core/src/types/serde_helpers.rs b/ethers-core/src/types/serde_helpers.rs index ea0015aea..80676388b 100644 --- a/ethers-core/src/types/serde_helpers.rs +++ b/ethers-core/src/types/serde_helpers.rs @@ -76,8 +76,7 @@ impl TryFrom for U64 { let value = U256::try_from(value)?; let mut be_bytes = [0u8; 32]; value.to_big_endian(&mut be_bytes); - U64::try_from(&be_bytes[value.leading_zeros() as usize / 8..]) - .map_err(|err| err.to_string()) + Ok(U64::from(&be_bytes[value.leading_zeros() as usize / 8..])) } } diff --git a/ethers-middleware/Cargo.toml b/ethers-middleware/Cargo.toml index baae44d85..022f91dba 100644 --- a/ethers-middleware/Cargo.toml +++ b/ethers-middleware/Cargo.toml @@ -25,7 +25,6 @@ all-features = true [dependencies] ethers-contract = { workspace = true, features = ["abigen", "providers"] } ethers-core.workspace = true -ethers-etherscan.workspace = true ethers-providers.workspace = true ethers-signers.workspace = true @@ -46,6 +45,8 @@ url.workspace = true serde_json.workspace = true +ethers-etherscan = { workspace = true, optional = true } + [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio.workspace = true @@ -62,8 +63,9 @@ reqwest = { workspace = true, features = ["json", "rustls"] } tokio = { workspace = true, features = ["rt-multi-thread", "macros", "time"] } [features] -default = ["rustls"] +default = ["rustls", "etherscan"] celo = ["ethers-core/celo", "ethers-providers/celo", "ethers-signers/celo", "ethers-contract/celo"] +etherscan = ["dep:ethers-etherscan"] optimism = ["ethers-core/optimism", "ethers-providers/optimism", "ethers-contract/optimism"] rustls = ["reqwest/rustls-tls"] openssl = ["reqwest/native-tls"] diff --git a/ethers-middleware/src/gas_oracle/mod.rs b/ethers-middleware/src/gas_oracle/mod.rs index 419c3306a..24362f3dc 100644 --- a/ethers-middleware/src/gas_oracle/mod.rs +++ b/ethers-middleware/src/gas_oracle/mod.rs @@ -8,7 +8,9 @@ pub use eth_gas_station::EthGasStation; pub mod etherchain; pub use etherchain::Etherchain; +#[cfg(feature = "etherscan")] pub mod etherscan; +#[cfg(feature = "etherscan")] pub use etherscan::Etherscan; pub mod middleware; @@ -70,6 +72,7 @@ pub enum GasOracleError { /// An internal error in the Etherscan client request made from the underlying /// gas oracle #[error(transparent)] + #[cfg(feature = "etherscan")] EtherscanError(#[from] ethers_etherscan::errors::EtherscanError), /// An internal error thrown when the required gas category is not diff --git a/ethers-middleware/tests/it/gas_oracle.rs b/ethers-middleware/tests/it/gas_oracle.rs index 5abb5ca9c..b810d1f40 100644 --- a/ethers-middleware/tests/it/gas_oracle.rs +++ b/ethers-middleware/tests/it/gas_oracle.rs @@ -1,12 +1,8 @@ use async_trait::async_trait; -use ethers_core::{ - types::*, - utils::{parse_ether, Anvil}, -}; -use ethers_etherscan::Client; +use ethers_core::{types::*, utils::Anvil}; use ethers_middleware::gas_oracle::{ - BlockNative, Etherchain, Etherscan, GasCategory, GasNow, GasOracle, GasOracleError, - GasOracleMiddleware, Polygon, ProviderOracle, Result, + BlockNative, Etherchain, GasNow, GasOracle, GasOracleError, GasOracleMiddleware, Polygon, + ProviderOracle, Result, }; use ethers_providers::{Http, Middleware, Provider}; @@ -89,8 +85,13 @@ async fn etherchain() { assert!(gas_price > U256::zero()); } +#[cfg(feature = "etherscan")] #[tokio::test] async fn etherscan() { + use ethers_core::utils::parse_ether; + use ethers_etherscan::Client; + use ethers_middleware::gas_oracle::{Etherscan, GasCategory}; + let chain = Chain::Mainnet; let etherscan_client = Client::new_from_opt_env(chain).unwrap(); diff --git a/ethers/Cargo.toml b/ethers/Cargo.toml index 54e23980d..2281330c5 100644 --- a/ethers/Cargo.toml +++ b/ethers/Cargo.toml @@ -23,7 +23,7 @@ rustdoc-args = ["--cfg", "docsrs"] all-features = true [features] -default = ["abigen", "rustls"] +default = ["abigen", "rustls", "etherscan"] # workspace-wide features legacy = ["ethers-core/legacy", "ethers-contract/legacy"] @@ -46,14 +46,14 @@ optimism = [ rustls = [ "ethers-contract/rustls", - "ethers-etherscan/rustls", + "ethers-etherscan?/rustls", "ethers-middleware/rustls", "ethers-providers/rustls", "ethers-solc?/rustls", ] openssl = [ "ethers-contract/openssl", - "ethers-etherscan/openssl", + "ethers-etherscan?/openssl", "ethers-middleware/openssl", "ethers-providers/openssl", "ethers-solc?/openssl", @@ -75,23 +75,27 @@ yubi = ["ethers-signers/yubi"] abigen = ["ethers-contract/abigen"] abigen-online = ["ethers-contract/abigen-online"] +# ethers-etherscan +etherscan = ["dep:ethers-etherscan", "ethers-middleware/etherscan"] + # ethers-solc -ethers-solc = ["dep:ethers-solc", "ethers-etherscan/ethers-solc"] +solc = ["dep:ethers-solc", "ethers-etherscan?/ethers-solc"] solc-full = ["ethers-solc?/full"] solc-tests = ["ethers-solc?/tests"] # Deprecated abigen-offline = ["abigen"] eip712 = [] +ethers-solc = ["solc"] solc-sha2-asm = [] [dependencies] ethers-addressbook.workspace = true ethers-contract = { workspace = true, features = ["providers"] } ethers-core.workspace = true -ethers-etherscan.workspace = true ethers-middleware.workspace = true ethers-providers.workspace = true ethers-signers.workspace = true +ethers-etherscan = { workspace = true, optional = true } ethers-solc = { workspace = true, optional = true } diff --git a/ethers/src/lib.rs b/ethers/src/lib.rs index 6cd73ae3f..9d14f714c 100644 --- a/ethers/src/lib.rs +++ b/ethers/src/lib.rs @@ -1,7 +1,7 @@ //! # ethers-rs //! //! A complete Ethereum and Celo Rust library. -//! +//! //!
//! This crate is in the process of being deprecated. //! See #2667 for more information. @@ -96,14 +96,17 @@ pub use ethers_contract as contract; #[doc(inline)] pub use ethers_core as core; #[doc(inline)] -pub use ethers_etherscan as etherscan; -#[doc(inline)] pub use ethers_middleware as middleware; #[doc(inline)] pub use ethers_providers as providers; #[doc(inline)] pub use ethers_signers as signers; -#[cfg(feature = "ethers-solc")] + +#[cfg(feature = "etherscan")] +#[doc(inline)] +pub use ethers_etherscan as etherscan; + +#[cfg(feature = "solc")] #[doc(inline)] pub use ethers_solc as solc; @@ -120,15 +123,16 @@ pub mod prelude { pub use super::core::{types::*, *}; - pub use super::etherscan::*; - pub use super::middleware::*; pub use super::providers::*; pub use super::signers::*; - #[cfg(feature = "ethers-solc")] + #[cfg(feature = "etherscan")] + pub use super::etherscan::*; + + #[cfg(feature = "solc")] pub use super::solc::*; } diff --git a/examples/middleware/Cargo.toml b/examples/middleware/Cargo.toml index 6ca79c644..5faeb2391 100644 --- a/examples/middleware/Cargo.toml +++ b/examples/middleware/Cargo.toml @@ -9,7 +9,7 @@ rust-version.workspace = true edition.workspace = true [dev-dependencies] -ethers = { workspace = true, features = ["rustls"] } +ethers = { workspace = true, features = ["rustls", "etherscan"] } serde.workspace = true serde_json.workspace = true tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }