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

Commit

Permalink
feat: make reqwest optional but enabled by default (#580)
Browse files Browse the repository at this point in the history
* feat: make reqwest optional but enabled by default

* update changelog
  • Loading branch information
mattsse authored Nov 14, 2021
1 parent 0f22afe commit d53ca0e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
5 changes: 3 additions & 2 deletions ethers-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand All @@ -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 = []

Expand Down
5 changes: 4 additions & 1 deletion ethers-contract/ethers-contract-abigen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ 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"

[target.'cfg(target_arch = "wasm32")'.dependencies]
# 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"]
12 changes: 9 additions & 3 deletions ethers-contract/ethers-contract-abigen/src/util.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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)]
Expand Down

0 comments on commit d53ca0e

Please sign in to comment.