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

feat: generalize wallet/private key #75

Merged
merged 3 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
499 changes: 454 additions & 45 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions ethers-contract/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use ethers_contract::{Contract, ContractFactory};
use ethers_core::utils::{GanacheInstance, Solc};
use ethers_middleware::Client;
use ethers_providers::{Http, Middleware, Provider};
use ethers_signers::Wallet;
use ethers_signers::LocalWallet;
use std::{convert::TryFrom, sync::Arc, time::Duration};

// Note: We also provide the `abigen` macro for generating these bindings automatically
Expand Down Expand Up @@ -44,14 +44,14 @@ pub fn compile_contract(name: &str, filename: &str) -> (Abi, Bytes) {
(contract.abi.clone(), contract.bytecode.clone())
}

type HttpWallet = Client<Provider<Http>, Wallet>;
type HttpWallet = Client<Provider<Http>, LocalWallet>;

/// connects the private key to http://localhost:8545
pub fn connect(ganache: &GanacheInstance, idx: usize) -> Arc<HttpWallet> {
let provider = Provider::<Http>::try_from(ganache.endpoint())
.unwrap()
.interval(Duration::from_millis(10u64));
let wallet: Wallet = ganache.keys()[idx].clone().into();
let wallet: LocalWallet = ganache.keys()[idx].clone().into();
Arc::new(Client::new(provider, wallet))
}

Expand Down
11 changes: 6 additions & 5 deletions ethers-contract/tests/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,15 @@ mod eth_tests {
assert_eq!(return_data.2, multicall_contract.address());
assert_eq!(return_data.3, multicall_contract.address());

let addrs = ganache.addresses();
// query ETH balances of multiple addresses
// these keys haven't been used to do any tx
// so should have 100 ETH
multicall
.clear_calls()
.eth_balance_of(Address::from(&ganache.keys()[4]))
.eth_balance_of(Address::from(&ganache.keys()[5]))
.eth_balance_of(Address::from(&ganache.keys()[6]));
.eth_balance_of(addrs[4])
.eth_balance_of(addrs[5])
.eth_balance_of(addrs[6]);
let balances: (U256, U256, U256) = multicall.call().await.unwrap();
assert_eq!(balances.0, U256::from(100000000000000000000u128));
assert_eq!(balances.1, U256::from(100000000000000000000u128));
Expand All @@ -343,7 +344,7 @@ mod celo_tests {
use ethers::{
middleware::Client,
providers::{Http, Provider},
signers::Wallet,
signers::LocalWallet,
types::BlockNumber,
};
use std::{convert::TryFrom, sync::Arc, time::Duration};
Expand All @@ -359,7 +360,7 @@ mod celo_tests {

// Funded with https://celo.org/developers/faucet
let wallet = "d652abb81e8c686edba621a895531b1f291289b63b5ef09a94f686a5ecdd5db1"
.parse::<Wallet>()
.parse::<LocalWallet>()
.unwrap();

let client = Client::new(provider, wallet);
Expand Down
3 changes: 1 addition & 2 deletions ethers-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ arrayvec = { version = "0.5.1", default-features = false }
ecdsa = { version = "0.8.0", features = ["std"] }
elliptic-curve = { version = "0.6.1", features = ["arithmetic"] }
generic-array = "0.14.4"
k256 = { git = "https://github.com/RustCrypto/elliptic-curves", version = "0.5.2", features = ["keccak256", "ecdsa"] }
k256 = { version = "0.5.2", features = ["keccak256", "ecdsa"] }
rand = "0.7.2"
tiny-keccak = { version = "2.0.2", default-features = false }
sha2 = { version = "0.9.1" }

# misc
serde = { version = "1.0.110", default-features = false, features = ["derive"] }
Expand Down
14 changes: 8 additions & 6 deletions ethers-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@
//! signing the hash of the result.
//!
//! ```rust
//! use ethers::core::types::{PrivateKey, Address};
//! # async fn foo() -> Result<(), Box<dyn std::error::Error>> {
//! use ethers::signers::{Signer, LocalWallet};
//!
//! let message = "Some data";
//! let key = PrivateKey::new(&mut rand::thread_rng());
//! let address = Address::from(&key);
//! let wallet = LocalWallet::new(&mut rand::thread_rng());
//!
//! // Sign the message
//! let signature = key.sign(message);
//! let signature = wallet.sign_message(message).await?;
//!
//! // Recover the signer from the message
//! let recovered = signature.recover(message).unwrap();
//! let recovered = signature.recover(message)?;
//!
//! assert_eq!(recovered, address);
//! assert_eq!(recovered, wallet.address());
//! # Ok(())
//! # }
//! ```
//!
//! ## Utilities
Expand Down
26 changes: 0 additions & 26 deletions ethers-core/src/types/chainstate/mod.rs

This file was deleted.

Loading