refactor ethers-utils to be part of ethers-types

This commit is contained in:
Georgios Konstantopoulos 2020-05-31 18:31:13 +03:00
parent d4bc43ee5b
commit 0013edf0e1
No known key found for this signature in database
GPG Key ID: FA607837CD26EDBC
23 changed files with 38 additions and 79 deletions

16
Cargo.lock generated
View File

@ -233,7 +233,6 @@ dependencies = [
"ethers-providers 0.1.0", "ethers-providers 0.1.0",
"ethers-signers 0.1.0", "ethers-signers 0.1.0",
"ethers-types 0.1.0", "ethers-types 0.1.0",
"ethers-utils 0.1.0",
"rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.53 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.53 (registry+https://github.com/rust-lang/crates.io-index)",
@ -291,7 +290,6 @@ version = "0.1.0"
dependencies = [ dependencies = [
"async-trait 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", "async-trait 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)",
"ethers-types 0.1.0", "ethers-types 0.1.0",
"ethers-utils 0.1.0",
"reqwest 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-hex 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)",
@ -307,7 +305,6 @@ version = "0.1.0"
dependencies = [ dependencies = [
"ethers-providers 0.1.0", "ethers-providers 0.1.0",
"ethers-types 0.1.0", "ethers-types 0.1.0",
"ethers-utils 0.1.0",
] ]
[[package]] [[package]]
@ -318,7 +315,6 @@ dependencies = [
"bincode 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "bincode 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"ethabi 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethabi 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ethereum-types 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", "ethereum-types 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
"ethers-utils 0.1.0",
"glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
"rlp 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
@ -327,18 +323,8 @@ dependencies = [
"serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.53 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.53 (registry+https://github.com/rust-lang/crates.io-index)",
"thiserror 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)", "thiserror 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)",
"zeroize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "ethers-utils"
version = "0.1.0"
dependencies = [
"ethereum-types 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-hex 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.53 (registry+https://github.com/rust-lang/crates.io-index)",
"tiny-keccak 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "tiny-keccak 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"zeroize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]

View File

@ -6,5 +6,4 @@ members = [
"./crates/ethers-providers", "./crates/ethers-providers",
"./crates/ethers-signers", "./crates/ethers-signers",
"./crates/ethers-types", "./crates/ethers-types",
"./crates/ethers-utils",
] ]

View File

@ -6,7 +6,6 @@ edition = "2018"
[dependencies] [dependencies]
ethers-types = { version = "0.1.0", path = "../ethers-types" } ethers-types = { version = "0.1.0", path = "../ethers-types" }
ethers-utils = { version = "0.1.0", path = "../ethers-utils" }
async-trait = { version = "0.1.31", default-features = false } async-trait = { version = "0.1.31", default-features = false }
reqwest = { version = "0.10.4", default-features = false, features = ["json", "rustls-tls"] } reqwest = { version = "0.10.4", default-features = false, features = ["json", "rustls-tls"] }

View File

@ -1,10 +1,8 @@
/// [Ethereum Name Service](https://docs.ens.domains/) support /// [Ethereum Name Service](https://docs.ens.domains/) support
// Adapted from https://github.com/hhatto/rust-ens/blob/master/src/lib.rs // Adapted from https://github.com/hhatto/rust-ens/blob/master/src/lib.rs
use ethers_types::{Address, NameOrAddress, Selector, TransactionRequest, H256}; use ethers_types::{utils::keccak256, Address, NameOrAddress, Selector, TransactionRequest, H256};
use ethers_utils::keccak256;
// Selectors // Selectors
const ENS_REVERSE_REGISTRAR_DOMAIN: &str = "addr.reverse"; const ENS_REVERSE_REGISTRAR_DOMAIN: &str = "addr.reverse";
/// resolver(bytes32) /// resolver(bytes32)

View File

@ -2,10 +2,9 @@ use crate::{ens, http::Provider as HttpProvider, networks::Network, JsonRpcClien
use ethers_types::{ use ethers_types::{
abi::{self, Detokenize, ParamType}, abi::{self, Detokenize, ParamType},
Address, Block, BlockId, BlockNumber, Bytes, Filter, Log, NameOrAddress, Selector, Transaction, utils, Address, Block, BlockId, BlockNumber, Bytes, Filter, Log, NameOrAddress, Selector,
TransactionReceipt, TransactionRequest, TxHash, U256, Transaction, TransactionReceipt, TransactionRequest, TxHash, U256,
}; };
use ethers_utils as utils;
use serde::Deserialize; use serde::Deserialize;
use url::{ParseError, Url}; use url::{ParseError, Url};

View File

@ -7,4 +7,3 @@ edition = "2018"
[dependencies] [dependencies]
ethers-types = { version = "0.1.0", path = "../ethers-types" } ethers-types = { version = "0.1.0", path = "../ethers-types" }
ethers-providers = { version = "0.1.0", path = "../ethers-providers" } ethers-providers = { version = "0.1.0", path = "../ethers-providers" }
ethers-utils = { version = "0.1.0", path = "../ethers-utils" }

View File

@ -5,8 +5,6 @@ authors = ["Georgios Konstantopoulos <me@gakonst.com>"]
edition = "2018" edition = "2018"
[dependencies] [dependencies]
ethers-utils = { version = "0.1.0", path = "../ethers-utils" }
# ethereum related # ethereum related
ethereum-types = { version = "0.9.2", default-features = false, features = ["serialize"] } ethereum-types = { version = "0.9.2", default-features = false, features = ["serialize"] }
rlp = { version = "0.4.5", default-features = false } rlp = { version = "0.4.5", default-features = false }
@ -16,6 +14,8 @@ ethabi = { version = "12.0.0", default-features = false, optional = true }
secp256k1 = { version = "0.17.2", default-features = false, features = ["std", "recovery", "rand"] } secp256k1 = { version = "0.17.2", default-features = false, features = ["std", "recovery", "rand"] }
rand = { version = "0.5.1", default-features = false } # this should be the same rand crate version as the one in secp rand = { version = "0.5.1", default-features = false } # this should be the same rand crate version as the one in secp
zeroize = { version = "1.1.0", default-features = false } zeroize = { version = "1.1.0", default-features = false }
tiny-keccak = { version = "2.0.2", default-features = false }
# misc # misc
serde = { version = "1.0.110", default-features = false, features = ["derive"] } serde = { version = "1.0.110", default-features = false, features = ["derive"] }

View File

@ -1,7 +1,6 @@
//! This module implements extensions to the `ethabi` API. //! This module implements extensions to the `ethabi` API.
// Adapted from [Gnosis' ethcontract](https://github.com/gnosis/ethcontract-rs/blob/master/common/src/abiext.rs) // Adapted from [Gnosis' ethcontract](https://github.com/gnosis/ethcontract-rs/blob/master/common/src/abiext.rs)
use crate::Selector; use crate::{utils::id, Selector};
use ethers_utils::id;
pub use ethabi::Contract as Abi; pub use ethabi::Contract as Abi;
pub use ethabi::*; pub use ethabi::*;

View File

@ -1,6 +1,5 @@
// Adapted from https://github.com/tomusdrw/rust-web3/blob/master/src/types/log.rs // Adapted from https://github.com/tomusdrw/rust-web3/blob/master/src/types/log.rs
use crate::{Address, BlockNumber, Bytes, H256, U256, U64}; use crate::{utils::keccak256, Address, BlockNumber, Bytes, H256, U256, U64};
use ethers_utils::keccak256;
use serde::{ser::SerializeSeq, Deserialize, Serialize, Serializer}; use serde::{ser::SerializeSeq, Deserialize, Serialize, Serializer};
use std::str::FromStr; use std::str::FromStr;
@ -221,7 +220,7 @@ where
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use ethers_utils::serialize; use crate::utils::serialize;
#[test] #[test]
fn filter_serialization_test() { fn filter_serialization_test() {

View File

@ -1,6 +1,7 @@
//! Transaction types //! Transaction types
use crate::{Address, Bloom, Bytes, Log, NameOrAddress, Signature, H256, U256, U64}; use crate::{
use ethers_utils::keccak256; utils::keccak256, Address, Bloom, Bytes, Log, NameOrAddress, Signature, H256, U256, U64,
};
use rlp::RlpStream; use rlp::RlpStream;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View File

@ -1,5 +1,7 @@
use crate::{Address, NameOrAddress, Signature, Transaction, TransactionRequest, H256, U256, U64}; use crate::{
use ethers_utils::{hash_message, keccak256}; utils::{hash_message, keccak256},
Address, NameOrAddress, Signature, Transaction, TransactionRequest, H256, U256, U64,
};
use rand::Rng; use rand::Rng;
use secp256k1::{ use secp256k1::{

View File

@ -1,6 +1,5 @@
// Code adapted from: https://github.com/tomusdrw/rust-web3/blob/master/src/api/accounts.rs // Code adapted from: https://github.com/tomusdrw/rust-web3/blob/master/src/api/accounts.rs
use crate::{Address, PublicKey, H256}; use crate::{utils::hash_message, Address, PublicKey, H256};
use ethers_utils::hash_message;
use rustc_hex::ToHex; use rustc_hex::ToHex;
use secp256k1::{ use secp256k1::{

View File

@ -44,8 +44,4 @@ pub use chainstate::*;
#[cfg(feature = "abi")] #[cfg(feature = "abi")]
pub mod abi; pub mod abi;
// Convenience re-export pub mod utils;
pub use ethers_utils as utils;
mod solc;
pub use solc::Solc;

View File

@ -18,7 +18,8 @@ impl Drop for Ganache {
/// # Example /// # Example
/// ///
/// ```rust,ignore /// ```rust,ignore
/// use ethers_utils::ganache::GanacheBuilder; /// use ethers_types::utils::ganache::GanacheBuilder;
///
/// let port = 8545u64; /// let port = 8545u64;
/// let url = format!("http://localhost:{}", port).to_string(); /// let url = format!("http://localhost:{}", port).to_string();
/// ///

View File

@ -2,9 +2,6 @@
use ethereum_types::H256; use ethereum_types::H256;
use tiny_keccak::{Hasher, Keccak}; use tiny_keccak::{Hasher, Keccak};
/// Utilities for launching a ganache-cli testnet instance
pub mod ganache;
const PREFIX: &str = "\x19Ethereum Signed Message:\n"; const PREFIX: &str = "\x19Ethereum Signed Message:\n";
/// Hash a message according to EIP-191. /// Hash a message according to EIP-191.

View File

@ -0,0 +1,10 @@
/// Utilities for launching a ganache-cli testnet instance
mod ganache;
pub use ganache::{Ganache, GanacheBuilder};
/// Solidity compiler bindings
mod solc;
pub use solc::{CompiledContract, Solc};
mod hash;
pub use hash::{hash_message, id, keccak256, serialize};

View File

@ -116,7 +116,7 @@ impl Solc {
.into(); .into();
let name = name let name = name
.rsplit(":") .rsplit(':')
.next() .next()
.expect("could not strip fname") .expect("could not strip fname")
.to_owned(); .to_owned();
@ -136,7 +136,7 @@ impl Solc {
let command_output = Command::new(SOLC) let command_output = Command::new(SOLC)
.arg("--version") .arg("--version")
.output() .output()
.expect(&format!("`{}` not in user's $PATH", SOLC)); .unwrap_or_else(|_| panic!("`{}` not in user's $PATH", SOLC));
let version = command_output let version = command_output
.stdout .stdout

View File

@ -1,14 +0,0 @@
[package]
name = "ethers-utils"
version = "0.1.0"
authors = ["Georgios Konstantopoulos <me@gakonst.com>"]
edition = "2018"
[dependencies]
ethereum-types = { version = "0.9.2", default-features = false, features = ["serialize"] }
tiny-keccak = { version = "2.0.2", default-features = false }
serde = { version = "1.0.110", default-features = false }
serde_json = { version = "1.0.53", default-features = false, features = ["alloc"] }
[dev-dependencies]
rustc-hex = "2.1.0"

View File

@ -11,25 +11,20 @@ full = [
"providers", "providers",
"signers", "signers",
"types", "types",
"utils",
] ]
contract = ["ethers-contract"] contract = ["ethers-contract"]
providers = ["ethers-providers"] providers = ["ethers-providers"]
signers = ["ethers-signers"] signers = ["ethers-signers"]
types = ["ethers-types"] types = ["ethers-types"]
utils = ["ethers-utils"]
[dependencies] [dependencies]
ethers-contract = { version = "0.1.0", path = "../ethers-contract", features = ["abigen"], optional = true } ethers-contract = { version = "0.1.0", path = "../ethers-contract", features = ["abigen"], optional = true }
ethers-providers = { version = "0.1.0", path = "../ethers-providers", optional = true } ethers-providers = { version = "0.1.0", path = "../ethers-providers", optional = true }
ethers-signers = { version = "0.1.0", path = "../ethers-signers", optional = true } ethers-signers = { version = "0.1.0", path = "../ethers-signers", optional = true }
ethers-types = { version = "0.1.0", path = "../ethers-types", optional = true } ethers-types = { version = "0.1.0", path = "../ethers-types", optional = true }
ethers-utils = { version = "0.1.0", path = "../ethers-utils", optional = true }
[dev-dependencies] [dev-dependencies]
ethers-contract = { version = "0.1.0", path = "../ethers-contract", features = ["abigen"] }
anyhow = "1.0.31" anyhow = "1.0.31"
tokio = { version = "0.2.21", features = ["macros"] } tokio = { version = "0.2.21", features = ["macros"] }
serde_json = "1.0.53" serde_json = "1.0.53"

View File

@ -3,8 +3,7 @@ use ethers::{
contract::{abigen, ContractFactory}, contract::{abigen, ContractFactory},
providers::HttpProvider, providers::HttpProvider,
signers::MainnetWallet, signers::MainnetWallet,
types::Solc, types::utils::{GanacheBuilder, Solc},
utils::ganache::GanacheBuilder,
}; };
use std::convert::TryFrom; use std::convert::TryFrom;
@ -50,7 +49,7 @@ async fn main() -> Result<()> {
let addr = contract.address(); let addr = contract.address();
// 9. instantiate the contract // 9. instantiate the contract
let contract = SimpleContract::new(addr.clone(), &client); let contract = SimpleContract::new(*addr, &client);
// 10. call the `setValue` method // 10. call the `setValue` method
let _tx_hash = contract.set_value("hi".to_owned()).send().await?; let _tx_hash = contract.set_value("hi".to_owned()).send().await?;

View File

@ -1,7 +1,8 @@
use anyhow::Result; use anyhow::Result;
use ethers::{ use ethers::{
providers::HttpProvider, signers::MainnetWallet, types::TransactionRequest, providers::HttpProvider,
utils::ganache::GanacheBuilder, signers::MainnetWallet,
types::{utils::GanacheBuilder, TransactionRequest},
}; };
use std::convert::TryFrom; use std::convert::TryFrom;

View File

@ -1,8 +1,7 @@
use anyhow::Result; use anyhow::Result;
use ethers::{ use ethers::{
providers::{networks::Any, HttpProvider}, providers::{networks::Any, HttpProvider},
types::{BlockNumber, TransactionRequest}, types::{utils::GanacheBuilder, BlockNumber, TransactionRequest},
utils::ganache::GanacheBuilder,
}; };
use std::convert::TryFrom; use std::convert::TryFrom;

View File

@ -34,8 +34,3 @@ pub mod signers {
pub mod types { pub mod types {
pub use ethers_types::*; pub use ethers_types::*;
} }
#[cfg(feature = "utils")]
pub mod utils {
pub use ethers_utils::*;
}