From 37d37a6bec3aad5e3ac6d94ea97198bc2a8a9a16 Mon Sep 17 00:00:00 2001 From: Georgios Konstantopoulos Date: Sun, 31 May 2020 19:20:08 +0300 Subject: [PATCH] add a prelude to make importing stuff easier --- crates/ethers/examples/contract.rs | 6 ++---- crates/ethers/examples/ens.rs | 2 +- crates/ethers/examples/get_logs.rs | 5 +---- crates/ethers/examples/local_signer.rs | 8 ++------ crates/ethers/examples/sign.rs | 4 ++-- crates/ethers/examples/transfer_eth.rs | 8 +------- crates/ethers/src/lib.rs | 23 +++++++++++++++++++++++ 7 files changed, 32 insertions(+), 24 deletions(-) diff --git a/crates/ethers/examples/contract.rs b/crates/ethers/examples/contract.rs index 9abd4c83..bb9ea960 100644 --- a/crates/ethers/examples/contract.rs +++ b/crates/ethers/examples/contract.rs @@ -1,9 +1,7 @@ use anyhow::Result; use ethers::{ - contract::{abigen, ContractFactory}, - core::utils::{GanacheBuilder, Solc}, - providers::HttpProvider, - signers::MainnetWallet, + prelude::*, + utils::{GanacheBuilder, Solc}, }; use std::convert::TryFrom; diff --git a/crates/ethers/examples/ens.rs b/crates/ethers/examples/ens.rs index 7326387c..6aa24886 100644 --- a/crates/ethers/examples/ens.rs +++ b/crates/ethers/examples/ens.rs @@ -1,5 +1,5 @@ use anyhow::Result; -use ethers::{core::types::TransactionRequest, providers::HttpProvider, signers::MainnetWallet}; +use ethers::prelude::*; use std::convert::TryFrom; #[tokio::main] diff --git a/crates/ethers/examples/get_logs.rs b/crates/ethers/examples/get_logs.rs index 053dd2ef..142ef659 100644 --- a/crates/ethers/examples/get_logs.rs +++ b/crates/ethers/examples/get_logs.rs @@ -1,8 +1,5 @@ use anyhow::Result; -use ethers::{ - core::types::{Address, Filter}, - providers::{networks::Any, HttpProvider}, -}; +use ethers::{networks::Any, prelude::*}; use std::convert::TryFrom; #[tokio::main] diff --git a/crates/ethers/examples/local_signer.rs b/crates/ethers/examples/local_signer.rs index d4fe5059..09a8bb26 100644 --- a/crates/ethers/examples/local_signer.rs +++ b/crates/ethers/examples/local_signer.rs @@ -1,9 +1,5 @@ use anyhow::Result; -use ethers::{ - core::{types::TransactionRequest, utils::GanacheBuilder}, - providers::HttpProvider, - signers::MainnetWallet, -}; +use ethers::{prelude::*, utils::GanacheBuilder}; use std::convert::TryFrom; #[tokio::main] @@ -37,7 +33,7 @@ async fn main() -> Result<()> { let receipt = client.get_transaction_receipt(tx.hash).await?; - println!("Send tx: {}", serde_json::to_string(&tx)?); + println!("Sent tx: {}\n", serde_json::to_string(&tx)?); println!("Tx receipt: {}", serde_json::to_string(&receipt)?); Ok(()) diff --git a/crates/ethers/examples/sign.rs b/crates/ethers/examples/sign.rs index 35103636..3df2d55f 100644 --- a/crates/ethers/examples/sign.rs +++ b/crates/ethers/examples/sign.rs @@ -1,8 +1,8 @@ -use ethers::signers::{MainnetWallet as Wallet, Signer}; +use ethers::prelude::*; fn main() { let message = "Some data"; - let wallet = Wallet::new(&mut rand::thread_rng()); + let wallet = MainnetWallet::new(&mut rand::thread_rng()); // sign a message let signature = wallet.sign_message(message); diff --git a/crates/ethers/examples/transfer_eth.rs b/crates/ethers/examples/transfer_eth.rs index 2dcaf0a3..eac06309 100644 --- a/crates/ethers/examples/transfer_eth.rs +++ b/crates/ethers/examples/transfer_eth.rs @@ -1,11 +1,5 @@ use anyhow::Result; -use ethers::{ - core::{ - types::{BlockNumber, TransactionRequest}, - utils::GanacheBuilder, - }, - providers::{networks::Any, HttpProvider}, -}; +use ethers::{networks::Any, prelude::*, utils::GanacheBuilder}; use std::convert::TryFrom; #[tokio::main] diff --git a/crates/ethers/src/lib.rs b/crates/ethers/src/lib.rs index 2287d0b1..9d5bc8af 100644 --- a/crates/ethers/src/lib.rs +++ b/crates/ethers/src/lib.rs @@ -34,3 +34,26 @@ pub mod signers { pub mod core { pub use ethers_core::*; } + +// Re-export ethers_core::utils +#[cfg(feature = "core")] +pub use ethers_core::utils; + +// Re-export ethers_providers::networks +#[cfg(feature = "providers")] +pub use ethers_providers::networks; + +/// Brings all types, contract, providers and signer imports into scope +pub mod prelude { + #[cfg(feature = "contract")] + pub use ethers_contract::*; + + #[cfg(feature = "providers")] + pub use ethers_providers::*; + + #[cfg(feature = "signers")] + pub use ethers_signers::*; + + #[cfg(feature = "core")] + pub use ethers_core::types::*; +}