add a prelude to make importing stuff easier

This commit is contained in:
Georgios Konstantopoulos 2020-05-31 19:20:08 +03:00
parent a9643fc9f6
commit 37d37a6bec
No known key found for this signature in database
GPG Key ID: FA607837CD26EDBC
7 changed files with 32 additions and 24 deletions

View File

@ -1,9 +1,7 @@
use anyhow::Result; use anyhow::Result;
use ethers::{ use ethers::{
contract::{abigen, ContractFactory}, prelude::*,
core::utils::{GanacheBuilder, Solc}, utils::{GanacheBuilder, Solc},
providers::HttpProvider,
signers::MainnetWallet,
}; };
use std::convert::TryFrom; use std::convert::TryFrom;

View File

@ -1,5 +1,5 @@
use anyhow::Result; use anyhow::Result;
use ethers::{core::types::TransactionRequest, providers::HttpProvider, signers::MainnetWallet}; use ethers::prelude::*;
use std::convert::TryFrom; use std::convert::TryFrom;
#[tokio::main] #[tokio::main]

View File

@ -1,8 +1,5 @@
use anyhow::Result; use anyhow::Result;
use ethers::{ use ethers::{networks::Any, prelude::*};
core::types::{Address, Filter},
providers::{networks::Any, HttpProvider},
};
use std::convert::TryFrom; use std::convert::TryFrom;
#[tokio::main] #[tokio::main]

View File

@ -1,9 +1,5 @@
use anyhow::Result; use anyhow::Result;
use ethers::{ use ethers::{prelude::*, utils::GanacheBuilder};
core::{types::TransactionRequest, utils::GanacheBuilder},
providers::HttpProvider,
signers::MainnetWallet,
};
use std::convert::TryFrom; use std::convert::TryFrom;
#[tokio::main] #[tokio::main]
@ -37,7 +33,7 @@ async fn main() -> Result<()> {
let receipt = client.get_transaction_receipt(tx.hash).await?; 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)?); println!("Tx receipt: {}", serde_json::to_string(&receipt)?);
Ok(()) Ok(())

View File

@ -1,8 +1,8 @@
use ethers::signers::{MainnetWallet as Wallet, Signer}; use ethers::prelude::*;
fn main() { fn main() {
let message = "Some data"; let message = "Some data";
let wallet = Wallet::new(&mut rand::thread_rng()); let wallet = MainnetWallet::new(&mut rand::thread_rng());
// sign a message // sign a message
let signature = wallet.sign_message(message); let signature = wallet.sign_message(message);

View File

@ -1,11 +1,5 @@
use anyhow::Result; use anyhow::Result;
use ethers::{ use ethers::{networks::Any, prelude::*, utils::GanacheBuilder};
core::{
types::{BlockNumber, TransactionRequest},
utils::GanacheBuilder,
},
providers::{networks::Any, HttpProvider},
};
use std::convert::TryFrom; use std::convert::TryFrom;
#[tokio::main] #[tokio::main]

View File

@ -34,3 +34,26 @@ pub mod signers {
pub mod core { pub mod core {
pub use ethers_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::*;
}