feat: make reqwest optional but enabled by default (#580)
* feat: make reqwest optional but enabled by default * update changelog
This commit is contained in:
parent
0f22afeb49
commit
d53ca0ea56
|
@ -4,6 +4,7 @@
|
|||
|
||||
### 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)
|
||||
- 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)
|
||||
|
|
|
@ -72,6 +72,8 @@ ledger = ["ethers-signers/ledger"]
|
|||
yubi = ["ethers-signers/yubi"]
|
||||
## contracts
|
||||
abigen = ["ethers-contract/abigen"]
|
||||
### abigen without reqwest
|
||||
abigen-offline = ["ethers-contract/abigen-offline"]
|
||||
## solc
|
||||
solc-async = ["ethers-solc/async"]
|
||||
solc-full = ["ethers-solc/full"]
|
||||
|
|
|
@ -12,7 +12,7 @@ keywords = ["ethereum", "web3", "celo", "ethers"]
|
|||
[dependencies]
|
||||
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-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-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]
|
||||
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"]
|
||||
legacy = []
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ url = "2.1"
|
|||
serde_json = "1.0.61"
|
||||
serde = { version = "1.0.124", features = ["derive"] }
|
||||
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"
|
||||
cfg-if = "1.0.0"
|
||||
|
||||
|
@ -29,6 +29,9 @@ cfg-if = "1.0.0"
|
|||
# NOTE: this enables wasm compatibility for getrandom indirectly
|
||||
getrandom = { version = "0.2", features = ["js"] }
|
||||
|
||||
[features]
|
||||
default = ["reqwest"]
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use ethers_core::types::Address;
|
||||
|
||||
use anyhow::{anyhow, Result};
|
||||
use cfg_if::cfg_if;
|
||||
use inflector::Inflector;
|
||||
use proc_macro2::{Ident, Literal, Span, TokenStream};
|
||||
use quote::quote;
|
||||
|
@ -69,10 +70,15 @@ where
|
|||
Ok(address_str[2..].parse()?)
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
/// Perform an HTTP GET request and return the contents of the response.
|
||||
pub fn http_get(url: &str) -> Result<String> {
|
||||
Ok(reqwest::blocking::get(url)?.text()?)
|
||||
pub fn http_get(_url: &str) -> Result<String> {
|
||||
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)]
|
||||
|
|
Loading…
Reference in New Issue