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

chore: make ethers-ethercan optional in ethers-middleware #2672

Merged
merged 4 commits into from
Nov 8, 2023
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
3 changes: 1 addition & 2 deletions ethers-core/src/types/serde_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ impl TryFrom<StringifiedNumeric> 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..]))
}
}

Expand Down
6 changes: 4 additions & 2 deletions ethers-middleware/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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"]
3 changes: 3 additions & 0 deletions ethers-middleware/src/gas_oracle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions ethers-middleware/tests/it/gas_oracle.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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();

Expand Down
14 changes: 9 additions & 5 deletions ethers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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",
Expand All @@ -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 }
18 changes: 11 additions & 7 deletions ethers/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! # ethers-rs
//!
//! A complete Ethereum and Celo Rust library.
//!
//!
//! <div class="warning">
//! This crate is in the process of being deprecated.
//! See <a href="https://github.com/gakonst/ethers-rs/issues/2667">#2667</a> for more information.
Expand Down Expand Up @@ -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;

Expand All @@ -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::*;
}

Expand Down
2 changes: 1 addition & 1 deletion examples/middleware/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
Loading