feat: make reqwest optional but enabled by default (#580)

* feat: make reqwest optional but enabled by default

* update changelog
This commit is contained in:
Matthias Seitz 2021-11-14 13:27:05 +01:00 committed by GitHub
parent 0f22afeb49
commit d53ca0ea56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 6 deletions

View File

@ -4,6 +4,7 @@
### Unreleased ### Unreleased
- Provide a way to opt out of networking support in abigen proc macro with `abigen-offline` feature [#580](https://github.com/gakonst/ethers-rs/pull/580)
- Add `.call()` method to `Deployer` for performing dry runs of contract deployments. [#554](https://github.com/gakonst/ethers-rs/pull/554) - Add `.call()` method to `Deployer` for performing dry runs of contract deployments. [#554](https://github.com/gakonst/ethers-rs/pull/554)
- Improve error message from failure in `ethers_contract_abigen::Source::parse` [#552](https://github.com/gakonst/ethers-rs/pull/552) - Improve error message from failure in `ethers_contract_abigen::Source::parse` [#552](https://github.com/gakonst/ethers-rs/pull/552)
- use enumerated aliases for overloaded functions [#545](https://github.com/gakonst/ethers-rs/pull/545) - use enumerated aliases for overloaded functions [#545](https://github.com/gakonst/ethers-rs/pull/545)

View File

@ -72,6 +72,8 @@ ledger = ["ethers-signers/ledger"]
yubi = ["ethers-signers/yubi"] yubi = ["ethers-signers/yubi"]
## contracts ## contracts
abigen = ["ethers-contract/abigen"] abigen = ["ethers-contract/abigen"]
### abigen without reqwest
abigen-offline = ["ethers-contract/abigen-offline"]
## solc ## solc
solc-async = ["ethers-solc/async"] solc-async = ["ethers-solc/async"]
solc-full = ["ethers-solc/full"] solc-full = ["ethers-solc/full"]

View File

@ -12,7 +12,7 @@ keywords = ["ethereum", "web3", "celo", "ethers"]
[dependencies] [dependencies]
ethers-providers = { version = "^0.5.0", path = "../ethers-providers", default-features = false } ethers-providers = { version = "^0.5.0", path = "../ethers-providers", default-features = false }
ethers-core = { version = "^0.5.0", path = "../ethers-core", default-features = false } ethers-core = { version = "^0.5.0", path = "../ethers-core", default-features = false }
ethers-contract-abigen = { version = "^0.5.0", path = "ethers-contract-abigen", optional = true } ethers-contract-abigen = { version = "^0.5.0", path = "ethers-contract-abigen", default-features = false, optional = true }
ethers-contract-derive = { version = "^0.5.0", path = "ethers-contract-derive", optional = true } ethers-contract-derive = { version = "^0.5.0", path = "ethers-contract-derive", optional = true }
ethers-derive-eip712 = { version = "0.1.0", path = "../ethers-core/ethers-derive-eip712", optional = true } ethers-derive-eip712 = { version = "0.1.0", path = "../ethers-core/ethers-derive-eip712", optional = true }
@ -39,7 +39,8 @@ tokio = { version = "1.5", default-features = false, features = ["macros"] }
[features] [features]
eip712 = ["ethers-derive-eip712", "ethers-core/eip712"] eip712 = ["ethers-derive-eip712", "ethers-core/eip712"]
abigen = ["ethers-contract-abigen", "ethers-contract-derive"] abigen = ["ethers-contract-abigen/reqwest", "ethers-contract-derive"]
abigen-offline = ["ethers-contract-abigen", "ethers-contract-derive"]
celo = ["legacy", "ethers-core/celo", "ethers-core/celo", "ethers-providers/celo"] celo = ["legacy", "ethers-core/celo", "ethers-core/celo", "ethers-providers/celo"]
legacy = [] legacy = []

View File

@ -21,7 +21,7 @@ url = "2.1"
serde_json = "1.0.61" serde_json = "1.0.61"
serde = { version = "1.0.124", features = ["derive"] } serde = { version = "1.0.124", features = ["derive"] }
hex = { version = "0.4.2", default-features = false, features = ["std"] } hex = { version = "0.4.2", default-features = false, features = ["std"] }
reqwest = { version = "0.11.3", features = ["blocking"] } reqwest = { version = "0.11.3", features = ["blocking"] , optional = true }
once_cell = "1.8.0" once_cell = "1.8.0"
cfg-if = "1.0.0" cfg-if = "1.0.0"
@ -29,6 +29,9 @@ cfg-if = "1.0.0"
# NOTE: this enables wasm compatibility for getrandom indirectly # NOTE: this enables wasm compatibility for getrandom indirectly
getrandom = { version = "0.2", features = ["js"] } getrandom = { version = "0.2", features = ["js"] }
[features]
default = ["reqwest"]
[package.metadata.docs.rs] [package.metadata.docs.rs]
all-features = true all-features = true
rustdoc-args = ["--cfg", "docsrs"] rustdoc-args = ["--cfg", "docsrs"]

View File

@ -1,6 +1,7 @@
use ethers_core::types::Address; use ethers_core::types::Address;
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use cfg_if::cfg_if;
use inflector::Inflector; use inflector::Inflector;
use proc_macro2::{Ident, Literal, Span, TokenStream}; use proc_macro2::{Ident, Literal, Span, TokenStream};
use quote::quote; use quote::quote;
@ -69,10 +70,15 @@ where
Ok(address_str[2..].parse()?) Ok(address_str[2..].parse()?)
} }
#[cfg(not(target_arch = "wasm32"))]
/// Perform an HTTP GET request and return the contents of the response. /// Perform an HTTP GET request and return the contents of the response.
pub fn http_get(url: &str) -> Result<String> { pub fn http_get(_url: &str) -> Result<String> {
Ok(reqwest::blocking::get(url)?.text()?) cfg_if! {
if #[cfg(any(not(target_arch = "wasm32"), not(features = "reqwest")))]{
Err(anyhow!("HTTP is unsupported"))
} else {
Ok(reqwest::blocking::get(_url)?.text()?)
}
}
} }
#[cfg(test)] #[cfg(test)]