Skip to content

Commit 0543e1c

Browse files
authoredNov 8, 2023
chore: make ethers-ethercan optional in ethers-middleware (gakonst#2672)
* chore: make ethers-ethercan optional in ethers-middleware * fmt * chore: clippy * feats
1 parent 1840aee commit 0543e1c

File tree

7 files changed

+37
-24
lines changed

7 files changed

+37
-24
lines changed
 

‎ethers-core/src/types/serde_helpers.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ impl TryFrom<StringifiedNumeric> for U64 {
7676
let value = U256::try_from(value)?;
7777
let mut be_bytes = [0u8; 32];
7878
value.to_big_endian(&mut be_bytes);
79-
U64::try_from(&be_bytes[value.leading_zeros() as usize / 8..])
80-
.map_err(|err| err.to_string())
79+
Ok(U64::from(&be_bytes[value.leading_zeros() as usize / 8..]))
8180
}
8281
}
8382

‎ethers-middleware/Cargo.toml

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ all-features = true
2525
[dependencies]
2626
ethers-contract = { workspace = true, features = ["abigen", "providers"] }
2727
ethers-core.workspace = true
28-
ethers-etherscan.workspace = true
2928
ethers-providers.workspace = true
3029
ethers-signers.workspace = true
3130

@@ -46,6 +45,8 @@ url.workspace = true
4645

4746
serde_json.workspace = true
4847

48+
ethers-etherscan = { workspace = true, optional = true }
49+
4950
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
5051
tokio.workspace = true
5152

@@ -62,8 +63,9 @@ reqwest = { workspace = true, features = ["json", "rustls"] }
6263
tokio = { workspace = true, features = ["rt-multi-thread", "macros", "time"] }
6364

6465
[features]
65-
default = ["rustls"]
66+
default = ["rustls", "etherscan"]
6667
celo = ["ethers-core/celo", "ethers-providers/celo", "ethers-signers/celo", "ethers-contract/celo"]
68+
etherscan = ["dep:ethers-etherscan"]
6769
optimism = ["ethers-core/optimism", "ethers-providers/optimism", "ethers-contract/optimism"]
6870
rustls = ["reqwest/rustls-tls"]
6971
openssl = ["reqwest/native-tls"]

‎ethers-middleware/src/gas_oracle/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ pub use eth_gas_station::EthGasStation;
88
pub mod etherchain;
99
pub use etherchain::Etherchain;
1010

11+
#[cfg(feature = "etherscan")]
1112
pub mod etherscan;
13+
#[cfg(feature = "etherscan")]
1214
pub use etherscan::Etherscan;
1315

1416
pub mod middleware;
@@ -70,6 +72,7 @@ pub enum GasOracleError {
7072
/// An internal error in the Etherscan client request made from the underlying
7173
/// gas oracle
7274
#[error(transparent)]
75+
#[cfg(feature = "etherscan")]
7376
EtherscanError(#[from] ethers_etherscan::errors::EtherscanError),
7477

7578
/// An internal error thrown when the required gas category is not

‎ethers-middleware/tests/it/gas_oracle.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
use async_trait::async_trait;
2-
use ethers_core::{
3-
types::*,
4-
utils::{parse_ether, Anvil},
5-
};
6-
use ethers_etherscan::Client;
2+
use ethers_core::{types::*, utils::Anvil};
73
use ethers_middleware::gas_oracle::{
8-
BlockNative, Etherchain, Etherscan, GasCategory, GasNow, GasOracle, GasOracleError,
9-
GasOracleMiddleware, Polygon, ProviderOracle, Result,
4+
BlockNative, Etherchain, GasNow, GasOracle, GasOracleError, GasOracleMiddleware, Polygon,
5+
ProviderOracle, Result,
106
};
117
use ethers_providers::{Http, Middleware, Provider};
128

@@ -89,8 +85,13 @@ async fn etherchain() {
8985
assert!(gas_price > U256::zero());
9086
}
9187

88+
#[cfg(feature = "etherscan")]
9289
#[tokio::test]
9390
async fn etherscan() {
91+
use ethers_core::utils::parse_ether;
92+
use ethers_etherscan::Client;
93+
use ethers_middleware::gas_oracle::{Etherscan, GasCategory};
94+
9495
let chain = Chain::Mainnet;
9596
let etherscan_client = Client::new_from_opt_env(chain).unwrap();
9697

‎ethers/Cargo.toml

+9-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ rustdoc-args = ["--cfg", "docsrs"]
2323
all-features = true
2424

2525
[features]
26-
default = ["abigen", "rustls"]
26+
default = ["abigen", "rustls", "etherscan"]
2727

2828
# workspace-wide features
2929
legacy = ["ethers-core/legacy", "ethers-contract/legacy"]
@@ -46,14 +46,14 @@ optimism = [
4646

4747
rustls = [
4848
"ethers-contract/rustls",
49-
"ethers-etherscan/rustls",
49+
"ethers-etherscan?/rustls",
5050
"ethers-middleware/rustls",
5151
"ethers-providers/rustls",
5252
"ethers-solc?/rustls",
5353
]
5454
openssl = [
5555
"ethers-contract/openssl",
56-
"ethers-etherscan/openssl",
56+
"ethers-etherscan?/openssl",
5757
"ethers-middleware/openssl",
5858
"ethers-providers/openssl",
5959
"ethers-solc?/openssl",
@@ -75,23 +75,27 @@ yubi = ["ethers-signers/yubi"]
7575
abigen = ["ethers-contract/abigen"]
7676
abigen-online = ["ethers-contract/abigen-online"]
7777

78+
# ethers-etherscan
79+
etherscan = ["dep:ethers-etherscan", "ethers-middleware/etherscan"]
80+
7881
# ethers-solc
79-
ethers-solc = ["dep:ethers-solc", "ethers-etherscan/ethers-solc"]
82+
solc = ["dep:ethers-solc", "ethers-etherscan?/ethers-solc"]
8083
solc-full = ["ethers-solc?/full"]
8184
solc-tests = ["ethers-solc?/tests"]
8285

8386
# Deprecated
8487
abigen-offline = ["abigen"]
8588
eip712 = []
89+
ethers-solc = ["solc"]
8690
solc-sha2-asm = []
8791

8892
[dependencies]
8993
ethers-addressbook.workspace = true
9094
ethers-contract = { workspace = true, features = ["providers"] }
9195
ethers-core.workspace = true
92-
ethers-etherscan.workspace = true
9396
ethers-middleware.workspace = true
9497
ethers-providers.workspace = true
9598
ethers-signers.workspace = true
9699

100+
ethers-etherscan = { workspace = true, optional = true }
97101
ethers-solc = { workspace = true, optional = true }

‎ethers/src/lib.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! # ethers-rs
22
//!
33
//! A complete Ethereum and Celo Rust library.
4-
//!
4+
//!
55
//! <div class="warning">
66
//! This crate is in the process of being deprecated.
77
//! See <a href="https://github.com/gakonst/ethers-rs/issues/2667">#2667</a> for more information.
@@ -96,14 +96,17 @@ pub use ethers_contract as contract;
9696
#[doc(inline)]
9797
pub use ethers_core as core;
9898
#[doc(inline)]
99-
pub use ethers_etherscan as etherscan;
100-
#[doc(inline)]
10199
pub use ethers_middleware as middleware;
102100
#[doc(inline)]
103101
pub use ethers_providers as providers;
104102
#[doc(inline)]
105103
pub use ethers_signers as signers;
106-
#[cfg(feature = "ethers-solc")]
104+
105+
#[cfg(feature = "etherscan")]
106+
#[doc(inline)]
107+
pub use ethers_etherscan as etherscan;
108+
109+
#[cfg(feature = "solc")]
107110
#[doc(inline)]
108111
pub use ethers_solc as solc;
109112

@@ -120,15 +123,16 @@ pub mod prelude {
120123

121124
pub use super::core::{types::*, *};
122125

123-
pub use super::etherscan::*;
124-
125126
pub use super::middleware::*;
126127

127128
pub use super::providers::*;
128129

129130
pub use super::signers::*;
130131

131-
#[cfg(feature = "ethers-solc")]
132+
#[cfg(feature = "etherscan")]
133+
pub use super::etherscan::*;
134+
135+
#[cfg(feature = "solc")]
132136
pub use super::solc::*;
133137
}
134138

‎examples/middleware/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ rust-version.workspace = true
99
edition.workspace = true
1010

1111
[dev-dependencies]
12-
ethers = { workspace = true, features = ["rustls"] }
12+
ethers = { workspace = true, features = ["rustls", "etherscan"] }
1313
serde.workspace = true
1414
serde_json.workspace = true
1515
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }

0 commit comments

Comments
 (0)
Please sign in to comment.