refactor ethers-types -> ethers-core

This commit is contained in:
Georgios Konstantopoulos 2020-05-31 19:01:34 +03:00
parent 0013edf0e1
commit a9643fc9f6
No known key found for this signature in database
GPG Key ID: FA607837CD26EDBC
52 changed files with 707 additions and 736 deletions

1249
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -5,5 +5,5 @@ members = [
"./crates/ethers-contract",
"./crates/ethers-providers",
"./crates/ethers-signers",
"./crates/ethers-types",
"./crates/ethers-core",
]

View File

@ -10,7 +10,7 @@ ethers-contract-derive = { version = "0.1.0", path = "ethers-contract-derive", o
ethers-providers = { version = "0.1.0", path = "../ethers-providers" }
ethers-signers = { version = "0.1.0", path = "../ethers-signers" }
ethers-types = { version = "0.1.0", path = "../ethers-types" }
ethers-core = { version = "0.1.0", path = "../ethers-core" }
serde = { version = "1.0.110", default-features = false }
rustc-hex = { version = "2.1.0", default-features = false }

View File

@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
description = "Code generation for type-safe bindings to Ethereum smart contracts"
[dependencies]
ethers-types = { path = "../../ethers-types" }
ethers-core = { path = "../../ethers-core" }
anyhow = "1.0"
curl = "0.4"

View File

@ -12,7 +12,7 @@ mod types;
use super::util;
use super::Args;
use anyhow::{anyhow, Context as _, Result};
use ethers_types::{abi::Abi, Address};
use ethers_core::{abi::Abi, types::Address};
use inflector::Inflector;
use proc_macro2::{Ident, Literal, TokenStream};
use quote::quote;

View File

@ -1,6 +1,6 @@
use super::Context;
use ethers_types::Address;
use ethers_core::types::Address;
use proc_macro2::{Literal, TokenStream};
use quote::quote;

View File

@ -1,5 +1,5 @@
use super::{types, util, Context};
use ethers_types::abi::{Event, EventExt, EventParam, Hash, ParamType};
use ethers_core::abi::{Event, EventExt, EventParam, Hash, ParamType};
use anyhow::Result;
use inflector::Inflector;
@ -286,7 +286,7 @@ fn expand_hash(hash: Hash) -> TokenStream {
#[cfg(test)]
mod tests {
use super::*;
use ethers_types::abi::{EventParam, ParamType};
use ethers_core::abi::{EventParam, ParamType};
#[test]
fn expand_transfer_filter() {

View File

@ -1,7 +1,7 @@
use super::{types, util, Context};
use ethers_types::{
use ethers_core::{
abi::{Function, FunctionExt, Param},
Selector,
types::Selector,
};
use anyhow::{anyhow, Context as _, Result};
@ -107,7 +107,7 @@ fn expand_selector(selector: Selector) -> TokenStream {
#[cfg(test)]
mod tests {
use super::*;
use ethers_types::abi::ParamType;
use ethers_core::abi::ParamType;
#[test]
fn expand_inputs_empty() {

View File

@ -1,5 +1,5 @@
use anyhow::{anyhow, Result};
use ethers_types::abi::ParamType;
use ethers_core::abi::ParamType;
use proc_macro2::{Literal, TokenStream};
use quote::quote;

View File

@ -19,7 +19,7 @@ mod rustfmt;
mod source;
mod util;
pub use ethers_types::Address;
pub use ethers_core::types::Address;
pub use source::Source;
pub use util::parse_address;

View File

@ -1,6 +1,6 @@
//! Module implements reading of contract artifacts from various sources.
use super::util;
use ethers_types::Address;
use ethers_core::types::Address;
use anyhow::{anyhow, Context, Error, Result};
use std::{

View File

@ -1,4 +1,4 @@
use ethers_types::Address;
use ethers_core::types::Address;
use anyhow::{anyhow, Result};
use curl::easy::Easy;

View File

@ -10,7 +10,7 @@ description = "Proc macro for type-safe bindings generation to Ethereum smart co
proc-macro = true
[dependencies]
ethers-types = { path = "../../ethers-types" }
ethers-core = { path = "../../ethers-core" }
ethers-contract-abigen = { path = "../ethers-contract-abigen" }
serde_json = "1.0.53"

View File

@ -3,7 +3,7 @@
use crate::spanned::{ParseInner, Spanned};
use ethers_contract_abigen::Builder;
use ethers_types::abi::{Function, FunctionExt, Param};
use ethers_core::abi::{Function, FunctionExt, Param};
use proc_macro2::{Span, TokenStream as TokenStream2};
use quote::{quote, ToTokens as _};

View File

@ -1,9 +1,9 @@
use ethers_core::{
abi::{Detokenize, Error as AbiError, Function, InvalidOutputType},
types::{Address, BlockNumber, TransactionRequest, H256, U256},
};
use ethers_providers::{networks::Network, JsonRpcClient};
use ethers_signers::{Client, Signer};
use ethers_types::{
abi::{Detokenize, Error as AbiError, Function, InvalidOutputType},
Address, BlockNumber, TransactionRequest, H256, U256,
};
use std::{fmt::Debug, marker::PhantomData};

View File

@ -1,11 +1,11 @@
use crate::{ContractCall, Event};
use ethers_core::{
abi::{Abi, Detokenize, Error, EventExt, Function, FunctionExt, Tokenize},
types::{Address, Filter, NameOrAddress, Selector, TransactionRequest},
};
use ethers_providers::{networks::Network, JsonRpcClient};
use ethers_signers::{Client, Signer};
use ethers_types::{
abi::{Abi, Detokenize, Error, EventExt, Function, FunctionExt, Tokenize},
Address, Filter, NameOrAddress, Selector, TransactionRequest,
};
use rustc_hex::ToHex;
use std::{collections::HashMap, fmt::Debug, hash::Hash, marker::PhantomData};

View File

@ -2,9 +2,9 @@ use crate::ContractError;
use ethers_providers::{networks::Network, JsonRpcClient, Provider};
use ethers_types::{
use ethers_core::{
abi::{Detokenize, Event as AbiEvent, RawLog},
BlockNumber, Filter, ValueOrArray, H256,
types::{BlockNumber, Filter, ValueOrArray, H256},
};
use std::marker::PhantomData;

View File

@ -1,11 +1,11 @@
use crate::{Contract, ContractError};
use ethers_core::{
abi::{Abi, Tokenize},
types::{Bytes, TransactionRequest},
};
use ethers_providers::{networks::Network, JsonRpcClient};
use ethers_signers::{Client, Signer};
use ethers_types::{
abi::{Abi, Tokenize},
Bytes, TransactionRequest,
};
use std::time::Duration;
use tokio::time;

View File

@ -17,8 +17,8 @@ pub use ethers_contract_abigen::Builder;
pub use ethers_contract_derive::abigen;
// re-export for convenience
pub use ethers_core::abi;
pub use ethers_core::types;
pub use ethers_providers as providers;
pub use ethers_signers as signers;
pub use ethers_types as types;
pub use ethers_types::abi;
pub use once_cell::sync::Lazy;

View File

@ -1,5 +1,5 @@
[package]
name = "ethers-types"
name = "ethers-core"
version = "0.1.0"
authors = ["Georgios Konstantopoulos <me@gakonst.com>"]
edition = "2018"

View File

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

View File

@ -1,7 +1,10 @@
//! Contract Functions Output types.
// Adapted from: [rust-web3](https://github.com/tomusdrw/rust-web3/blob/master/src/contract/tokens.rs)
#![allow(clippy::all)]
use crate::{abi::Token, Address, Bytes, H256, U128, U256};
use crate::{
abi::Token,
types::{Address, Bytes, H256, U128, U256},
};
use arrayvec::ArrayVec;
use thiserror::Error;
@ -469,7 +472,7 @@ impl_fixed_types!(1024);
#[cfg(test)]
mod tests {
use super::{Detokenize, Tokenizable};
use crate::{Address, U256};
use crate::types::{Address, U256};
use ethabi::Token;
fn output<R: Detokenize>() -> R {

View File

@ -9,7 +9,7 @@
//! signing the hash of the result.
//!
//! ```rust
//! use ethers_types::{PrivateKey, Address};
//! use ethers_core::types::{PrivateKey, Address};
//!
//! let message = "Some data";
//! let key = PrivateKey::new(&mut rand::thread_rng());
@ -24,6 +24,12 @@
//! assert_eq!(recovered, address);
//! ```
//!
//! # Utilities
//!
//! The crate provides utilities for launching local Ethereum testnets by using `ganache-cli`
//! via the `GanacheBuilder` struct. In addition, you're able to compile contracts on the
//! filesystem by providing a glob to their path, using the `Solc` struct.
//!
//! # ABI Encoding and Decoding
//!
//! This crate re-exports the [`ethabi`](http://docs.rs/ethabi) crate's functions
@ -34,14 +40,20 @@
//! The version of `rand` used in the `secp256k1` crate is not compatible with the
//! latest one in crates at the time of writing (rand version 0.5.1, secp256k1 version 0.17.1)
//! As a result, the RNGs used for generating private keys must use a compatible rand crate
//! version. For convenience, we re-export it so that consumers can use it as `ethers_types::rand`.
mod crypto;
pub use crypto::*;
//! version. For convenience, we re-export it so that consumers can use it as `ethers_core::rand`.
mod chainstate;
pub use chainstate::*;
/// Ethereum related datatypes
pub mod types;
#[cfg(feature = "abi")]
pub mod abi;
/// Various utilities
pub mod utils;
// re-export the non-standard rand version so that other crates don't use the
// wrong one by accident
pub use rand;
// re-export libsecp
pub use secp256k1;

View File

@ -1,5 +1,5 @@
// Taken from https://github.com/tomusdrw/rust-web3/blob/master/src/types/block.rs
use crate::{Address, Bloom, Bytes, H256, U256, U64};
use crate::types::{Address, Bloom, Bytes, H256, U256, U64};
use serde::{ser::SerializeStruct, Deserialize, Serialize, Serializer};
/// The block type returned from RPC calls.
@ -150,7 +150,7 @@ impl Serialize for BlockNumber {
#[cfg(test)]
mod tests {
use super::*;
use crate::{Transaction, TxHash};
use crate::types::{Transaction, TxHash};
#[test]
fn deserialize_blk_no_txs() {

View File

@ -1,4 +1,4 @@
use crate::Address;
use crate::types::Address;
use rlp::{Encodable, RlpStream};
use serde::{ser::Error as SerializationError, Deserialize, Deserializer, Serialize, Serializer};

View File

@ -1,5 +1,8 @@
// Adapted from https://github.com/tomusdrw/rust-web3/blob/master/src/types/log.rs
use crate::{utils::keccak256, Address, BlockNumber, Bytes, H256, U256, U64};
use crate::{
types::{Address, BlockNumber, Bytes, H256, U256, U64},
utils::keccak256,
};
use serde::{ser::SerializeSeq, Deserialize, Serialize, Serializer};
use std::str::FromStr;

View File

@ -21,10 +21,3 @@ pub use log::{Filter, Log, ValueOrArray};
mod ens;
pub use ens::NameOrAddress;
// re-export the non-standard rand version so that other crates don't use the
// wrong one by accident
pub use rand;
// re-export libsecp
pub use secp256k1;

View File

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

View File

@ -1,6 +1,6 @@
use crate::{
types::{Address, NameOrAddress, Signature, Transaction, TransactionRequest, H256, U256, U64},
utils::{hash_message, keccak256},
Address, NameOrAddress, Signature, Transaction, TransactionRequest, H256, U256, U64,
};
use rand::Rng;
@ -234,7 +234,7 @@ impl From<PrivateKey> for Address {
#[cfg(test)]
mod tests {
use super::*;
use crate::Bytes;
use crate::types::Bytes;
use rustc_hex::FromHex;
#[test]

View File

@ -1,5 +1,8 @@
// Code adapted from: https://github.com/tomusdrw/rust-web3/blob/master/src/api/accounts.rs
use crate::{utils::hash_message, Address, PublicKey, H256};
use crate::{
types::{Address, PublicKey, H256},
utils::hash_message,
};
use rustc_hex::ToHex;
use secp256k1::{
@ -191,7 +194,7 @@ impl From<H256> for RecoveryMessage {
#[cfg(test)]
mod tests {
use super::*;
use crate::PrivateKey;
use crate::types::PrivateKey;
#[test]
fn recover_signature_from_message() {

View File

@ -0,0 +1,5 @@
mod crypto;
pub use crypto::*;
mod chainstate;
pub use chainstate::*;

View File

@ -12,7 +12,7 @@
//! .build();
//! let contract = contracts.get("SimpleStorage").unwrap();
//! ```
use crate::{abi::Abi, Bytes};
use crate::{abi::Abi, types::Bytes};
use glob::glob;
use rustc_hex::FromHex;
use serde::{Deserialize, Serialize};

View File

@ -5,7 +5,7 @@ authors = ["Georgios Konstantopoulos <me@gakonst.com>"]
edition = "2018"
[dependencies]
ethers-types = { version = "0.1.0", path = "../ethers-types" }
ethers-core = { version = "0.1.0", path = "../ethers-core" }
async-trait = { version = "0.1.31", default-features = false }
reqwest = { version = "0.10.4", default-features = false, features = ["json", "rustls-tls"] }

View File

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

View File

@ -1,6 +1,6 @@
//! Networks are used inside wallets and providers to ensure replay protection across networks,
//! as well as to allow functions to be called with ENS names instead of Addresses.
use ethers_types::{Address, H160, U64};
use ethers_core::types::{Address, H160, U64};
/// Trait for specifying network specific metadata, such as the Chain Id or the ENS
/// address.

View File

@ -1,9 +1,12 @@
use crate::{ens, http::Provider as HttpProvider, networks::Network, JsonRpcClient};
use ethers_types::{
use ethers_core::{
abi::{self, Detokenize, ParamType},
utils, Address, Block, BlockId, BlockNumber, Bytes, Filter, Log, NameOrAddress, Selector,
types::{
Address, Block, BlockId, BlockNumber, Bytes, Filter, Log, NameOrAddress, Selector,
Transaction, TransactionReceipt, TransactionRequest, TxHash, U256,
},
utils,
};
use serde::Deserialize;

View File

@ -5,5 +5,5 @@ authors = ["Georgios Konstantopoulos <me@gakonst.com>"]
edition = "2018"
[dependencies]
ethers-types = { version = "0.1.0", path = "../ethers-types" }
ethers-core = { version = "0.1.0", path = "../ethers-core" }
ethers-providers = { version = "0.1.0", path = "../ethers-providers" }

View File

@ -1,7 +1,7 @@
use crate::Signer;
use ethers_core::types::{Address, BlockNumber, NameOrAddress, TransactionRequest, TxHash};
use ethers_providers::{networks::Network, JsonRpcClient, Provider};
use ethers_types::{Address, BlockNumber, NameOrAddress, TransactionRequest, TxHash};
use std::ops::Deref;

View File

@ -44,7 +44,7 @@ pub use wallet::Wallet;
mod client;
pub use client::Client;
use ethers_types::{Address, Signature, Transaction, TransactionRequest};
use ethers_core::types::{Address, Signature, Transaction, TransactionRequest};
use std::error::Error;
/// Trait for signing transactions and messages

View File

@ -2,9 +2,10 @@ use crate::{Client, Signer};
use ethers_providers::{networks::Network, JsonRpcClient, Provider};
use ethers_types::{
rand::Rng, secp256k1, Address, PrivateKey, PublicKey, Signature, Transaction,
TransactionRequest, TxError,
use ethers_core::{
rand::Rng,
secp256k1,
types::{Address, PrivateKey, PublicKey, Signature, Transaction, TransactionRequest, TxError},
};
use std::{marker::PhantomData, str::FromStr};

View File

@ -10,19 +10,19 @@ full = [
"contract",
"providers",
"signers",
"types",
"core",
]
contract = ["ethers-contract"]
providers = ["ethers-providers"]
signers = ["ethers-signers"]
types = ["ethers-types"]
core = ["ethers-core"]
[dependencies]
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-signers = { version = "0.1.0", path = "../ethers-signers", optional = true }
ethers-types = { version = "0.1.0", path = "../ethers-types", optional = true }
ethers-core = { version = "0.1.0", path = "../ethers-core", optional = true }
[dev-dependencies]
anyhow = "1.0.31"

View File

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

View File

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

View File

@ -1,7 +1,7 @@
use anyhow::Result;
use ethers::{
core::types::{Address, Filter},
providers::{networks::Any, HttpProvider},
types::{Address, Filter},
};
use std::convert::TryFrom;

View File

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

View File

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

View File

@ -30,7 +30,7 @@ pub mod signers {
pub use ethers_signers::*;
}
#[cfg(feature = "types")]
pub mod types {
pub use ethers_types::*;
#[cfg(feature = "core")]
pub mod core {
pub use ethers_core::*;
}