refactor ethers-abi to be part of ethers-types
This commit is contained in:
parent
a78979a3ac
commit
bc523b6d60
|
@ -229,7 +229,6 @@ name = "ethers"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)",
|
"anyhow 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"ethers-abi 0.1.0",
|
|
||||||
"ethers-contract 0.1.0",
|
"ethers-contract 0.1.0",
|
||||||
"ethers-providers 0.1.0",
|
"ethers-providers 0.1.0",
|
||||||
"ethers-signers 0.1.0",
|
"ethers-signers 0.1.0",
|
||||||
|
@ -241,23 +240,10 @@ dependencies = [
|
||||||
"tokio 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
|
"tokio 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ethers-abi"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"ethabi 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"ethers-types 0.1.0",
|
|
||||||
"ethers-utils 0.1.0",
|
|
||||||
"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)",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ethers-contract"
|
name = "ethers-contract"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ethers-abi 0.1.0",
|
|
||||||
"ethers-contract-abigen 0.1.0",
|
"ethers-contract-abigen 0.1.0",
|
||||||
"ethers-contract-derive 0.1.0",
|
"ethers-contract-derive 0.1.0",
|
||||||
"ethers-providers 0.1.0",
|
"ethers-providers 0.1.0",
|
||||||
|
@ -276,7 +262,6 @@ dependencies = [
|
||||||
"Inflector 0.11.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
"Inflector 0.11.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"anyhow 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)",
|
"anyhow 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"curl 0.4.29 (registry+https://github.com/rust-lang/crates.io-index)",
|
"curl 0.4.29 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"ethers-abi 0.1.0",
|
|
||||||
"ethers-types 0.1.0",
|
"ethers-types 0.1.0",
|
||||||
"once_cell 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"once_cell 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"proc-macro2 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
"proc-macro2 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -291,8 +276,8 @@ dependencies = [
|
||||||
name = "ethers-contract-derive"
|
name = "ethers-contract-derive"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ethers-abi 0.1.0",
|
|
||||||
"ethers-contract-abigen 0.1.0",
|
"ethers-contract-abigen 0.1.0",
|
||||||
|
"ethers-types 0.1.0",
|
||||||
"proc-macro2 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
"proc-macro2 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"quote 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"quote 1.0.6 (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)",
|
||||||
|
@ -304,7 +289,6 @@ name = "ethers-providers"
|
||||||
version = "0.1.0"
|
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-abi 0.1.0",
|
|
||||||
"ethers-types 0.1.0",
|
"ethers-types 0.1.0",
|
||||||
"ethers-utils 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)",
|
||||||
|
@ -329,7 +313,9 @@ dependencies = [
|
||||||
name = "ethers-types"
|
name = "ethers-types"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"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)",
|
||||||
"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",
|
"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)",
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
members = [
|
members = [
|
||||||
"./crates/ethers",
|
"./crates/ethers",
|
||||||
"./crates/ethers-abi",
|
|
||||||
"./crates/ethers-contract",
|
"./crates/ethers-contract",
|
||||||
"./crates/ethers-providers",
|
"./crates/ethers-providers",
|
||||||
"./crates/ethers-signers",
|
"./crates/ethers-signers",
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "ethers-abi"
|
|
||||||
version = "0.1.0"
|
|
||||||
authors = ["Georgios Konstantopoulos <me@gakonst.com>"]
|
|
||||||
edition = "2018"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
ethers-types = { version = "0.1.0", path = "../ethers-types" }
|
|
||||||
ethers-utils = { version = "0.1.0", path = "../ethers-utils" }
|
|
||||||
|
|
||||||
ethabi = "12.0.0"
|
|
||||||
arrayvec = "0.5.1"
|
|
||||||
thiserror = { version = "1.0.19", default-features = false }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
serde_json = { version = "1.0.53", default-features = false }
|
|
|
@ -8,7 +8,6 @@ edition = "2018"
|
||||||
ethers-contract-abigen = { version = "0.1.0", path = "ethers-contract-abigen", optional = true }
|
ethers-contract-abigen = { version = "0.1.0", path = "ethers-contract-abigen", optional = true }
|
||||||
ethers-contract-derive = { version = "0.1.0", path = "ethers-contract-derive", optional = true }
|
ethers-contract-derive = { version = "0.1.0", path = "ethers-contract-derive", optional = true }
|
||||||
|
|
||||||
ethers-abi = { version = "0.1.0", path = "../ethers-abi" }
|
|
||||||
ethers-providers = { version = "0.1.0", path = "../ethers-providers" }
|
ethers-providers = { version = "0.1.0", path = "../ethers-providers" }
|
||||||
ethers-signers = { version = "0.1.0", path = "../ethers-signers" }
|
ethers-signers = { version = "0.1.0", path = "../ethers-signers" }
|
||||||
ethers-types = { version = "0.1.0", path = "../ethers-types" }
|
ethers-types = { version = "0.1.0", path = "../ethers-types" }
|
||||||
|
|
|
@ -7,7 +7,6 @@ license = "MIT OR Apache-2.0"
|
||||||
description = "Code generation for type-safe bindings to Ethereum smart contracts"
|
description = "Code generation for type-safe bindings to Ethereum smart contracts"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ethers-abi = { path = "../../ethers-abi" }
|
|
||||||
ethers-types = { path = "../../ethers-types" }
|
ethers-types = { path = "../../ethers-types" }
|
||||||
|
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
|
|
|
@ -12,8 +12,7 @@ mod types;
|
||||||
use super::util;
|
use super::util;
|
||||||
use super::Args;
|
use super::Args;
|
||||||
use anyhow::{anyhow, Context as _, Result};
|
use anyhow::{anyhow, Context as _, Result};
|
||||||
use ethers_abi::Abi;
|
use ethers_types::{abi::Abi, Address};
|
||||||
use ethers_types::Address;
|
|
||||||
use inflector::Inflector;
|
use inflector::Inflector;
|
||||||
use proc_macro2::{Ident, Literal, TokenStream};
|
use proc_macro2::{Ident, Literal, TokenStream};
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use super::{types, util, Context};
|
use super::{types, util, Context};
|
||||||
use ethers_abi::{Event, EventExt, EventParam, Hash, ParamType};
|
use ethers_types::abi::{Event, EventExt, EventParam, Hash, ParamType};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use inflector::Inflector;
|
use inflector::Inflector;
|
||||||
|
@ -286,7 +286,7 @@ fn expand_hash(hash: Hash) -> TokenStream {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use ethers_abi::{EventParam, ParamType};
|
use ethers_types::abi::{EventParam, ParamType};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn expand_transfer_filter() {
|
fn expand_transfer_filter() {
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
use super::{types, util, Context};
|
use super::{types, util, Context};
|
||||||
|
use ethers_types::{
|
||||||
use ethers_abi::{Function, FunctionExt, Param};
|
abi::{Function, FunctionExt, Param},
|
||||||
use ethers_types::Selector;
|
Selector,
|
||||||
|
};
|
||||||
|
|
||||||
use anyhow::{anyhow, Context as _, Result};
|
use anyhow::{anyhow, Context as _, Result};
|
||||||
use inflector::Inflector;
|
use inflector::Inflector;
|
||||||
|
@ -106,7 +107,7 @@ fn expand_selector(selector: Selector) -> TokenStream {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use ethers_abi::ParamType;
|
use ethers_types::abi::ParamType;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn expand_inputs_empty() {
|
fn expand_inputs_empty() {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use ethers_abi::ParamType;
|
use ethers_types::abi::ParamType;
|
||||||
use proc_macro2::{Literal, TokenStream};
|
use proc_macro2::{Literal, TokenStream};
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ description = "Proc macro for type-safe bindings generation to Ethereum smart co
|
||||||
proc-macro = true
|
proc-macro = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ethers-abi = { path = "../../ethers-abi" }
|
ethers-types = { path = "../../ethers-types" }
|
||||||
ethers-contract-abigen = { path = "../ethers-contract-abigen" }
|
ethers-contract-abigen = { path = "../ethers-contract-abigen" }
|
||||||
|
|
||||||
serde_json = "1.0.53"
|
serde_json = "1.0.53"
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
//! ethereum smart contract.
|
//! ethereum smart contract.
|
||||||
use crate::spanned::{ParseInner, Spanned};
|
use crate::spanned::{ParseInner, Spanned};
|
||||||
|
|
||||||
use ethers_abi::{Function, FunctionExt, Param};
|
|
||||||
use ethers_contract_abigen::Builder;
|
use ethers_contract_abigen::Builder;
|
||||||
|
use ethers_types::abi::{Function, FunctionExt, Param};
|
||||||
|
|
||||||
use proc_macro2::{Span, TokenStream as TokenStream2};
|
use proc_macro2::{Span, TokenStream as TokenStream2};
|
||||||
use quote::{quote, ToTokens as _};
|
use quote::{quote, ToTokens as _};
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
use ethers_abi::{Detokenize, Function};
|
|
||||||
use ethers_providers::{networks::Network, JsonRpcClient};
|
use ethers_providers::{networks::Network, JsonRpcClient};
|
||||||
use ethers_signers::{Client, Signer};
|
use ethers_signers::{Client, Signer};
|
||||||
use ethers_types::{Address, BlockNumber, TransactionRequest, H256, U256};
|
use ethers_types::{
|
||||||
|
abi::{Detokenize, Error as AbiError, Function, InvalidOutputType},
|
||||||
|
Address, BlockNumber, TransactionRequest, H256, U256,
|
||||||
|
};
|
||||||
|
|
||||||
use std::{fmt::Debug, marker::PhantomData};
|
use std::{fmt::Debug, marker::PhantomData};
|
||||||
|
|
||||||
|
@ -48,9 +50,9 @@ where
|
||||||
P::Error: 'static,
|
P::Error: 'static,
|
||||||
{
|
{
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
DecodingError(#[from] ethers_abi::Error),
|
DecodingError(#[from] AbiError),
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
DetokenizationError(#[from] ethers_abi::InvalidOutputType),
|
DetokenizationError(#[from] InvalidOutputType),
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
CallError(P::Error),
|
CallError(P::Error),
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
use crate::{ContractCall, Event};
|
use crate::{ContractCall, Event};
|
||||||
|
|
||||||
use ethers_abi::{Abi, Detokenize, Error, EventExt, Function, FunctionExt, Tokenize};
|
|
||||||
use ethers_providers::{networks::Network, JsonRpcClient};
|
use ethers_providers::{networks::Network, JsonRpcClient};
|
||||||
use ethers_signers::{Client, Signer};
|
use ethers_signers::{Client, Signer};
|
||||||
use ethers_types::{Address, Filter, NameOrAddress, Selector, TransactionRequest};
|
use ethers_types::{
|
||||||
|
abi::{Abi, Detokenize, Error, EventExt, Function, FunctionExt, Tokenize},
|
||||||
|
Address, Filter, NameOrAddress, Selector, TransactionRequest,
|
||||||
|
};
|
||||||
|
|
||||||
use rustc_hex::ToHex;
|
use rustc_hex::ToHex;
|
||||||
use std::{collections::HashMap, fmt::Debug, hash::Hash, marker::PhantomData};
|
use std::{collections::HashMap, fmt::Debug, hash::Hash, marker::PhantomData};
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
use crate::ContractError;
|
use crate::ContractError;
|
||||||
|
|
||||||
use ethers_abi::{Detokenize, Event as AbiEvent, RawLog};
|
|
||||||
use ethers_providers::{networks::Network, JsonRpcClient, Provider};
|
use ethers_providers::{networks::Network, JsonRpcClient, Provider};
|
||||||
|
|
||||||
use ethers_types::{BlockNumber, Filter, ValueOrArray, H256};
|
use ethers_types::{
|
||||||
|
abi::{Detokenize, Event as AbiEvent, RawLog},
|
||||||
|
BlockNumber, Filter, ValueOrArray, H256,
|
||||||
|
};
|
||||||
|
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,8 @@ pub use ethers_contract_abigen::Builder;
|
||||||
pub use ethers_contract_derive::abigen;
|
pub use ethers_contract_derive::abigen;
|
||||||
|
|
||||||
// re-export for convenience
|
// re-export for convenience
|
||||||
pub use ethers_abi as abi;
|
|
||||||
pub use ethers_providers as providers;
|
pub use ethers_providers as providers;
|
||||||
pub use ethers_signers as signers;
|
pub use ethers_signers as signers;
|
||||||
pub use ethers_types as types;
|
pub use ethers_types as types;
|
||||||
|
pub use ethers_types::abi;
|
||||||
pub use once_cell::sync::Lazy;
|
pub use once_cell::sync::Lazy;
|
||||||
|
|
|
@ -7,7 +7,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" }
|
ethers-utils = { version = "0.1.0", path = "../ethers-utils" }
|
||||||
ethers-abi = { version = "0.1.0", path = "../ethers-abi" }
|
|
||||||
|
|
||||||
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"] }
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::{ens, http::Provider as HttpProvider, networks::Network, JsonRpcClient};
|
use crate::{ens, http::Provider as HttpProvider, networks::Network, JsonRpcClient};
|
||||||
|
|
||||||
use ethers_abi::{Detokenize, ParamType};
|
|
||||||
use ethers_types::{
|
use ethers_types::{
|
||||||
|
abi::{self, Detokenize, ParamType},
|
||||||
Address, Block, BlockId, BlockNumber, Bytes, Filter, Log, NameOrAddress, Selector, Transaction,
|
Address, Block, BlockId, BlockNumber, Bytes, Filter, Log, NameOrAddress, Selector, Transaction,
|
||||||
TransactionReceipt, TransactionRequest, TxHash, U256,
|
TransactionReceipt, TransactionRequest, TxHash, U256,
|
||||||
};
|
};
|
||||||
|
@ -256,8 +256,8 @@ impl<P: JsonRpcClient, N: Network> Provider<P, N> {
|
||||||
///
|
///
|
||||||
/// If the provided bytes were not an interpretation of an address
|
/// If the provided bytes were not an interpretation of an address
|
||||||
fn decode_bytes<T: Detokenize>(param: ParamType, bytes: Bytes) -> T {
|
fn decode_bytes<T: Detokenize>(param: ParamType, bytes: Bytes) -> T {
|
||||||
let tokens = ethers_abi::decode(&[param], &bytes.0)
|
let tokens =
|
||||||
.expect("could not abi-decode bytes to address tokens");
|
abi::decode(&[param], &bytes.0).expect("could not abi-decode bytes to address tokens");
|
||||||
T::from_tokens(tokens).expect("could not parse tokens as address")
|
T::from_tokens(tokens).expect("could not parse tokens as address")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,18 +7,27 @@ edition = "2018"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ethers-utils = { version = "0.1.0", path = "../ethers-utils" }
|
ethers-utils = { version = "0.1.0", path = "../ethers-utils" }
|
||||||
|
|
||||||
|
# ethereum related
|
||||||
ethereum-types = { version = "0.9.2", default-features = false, features = ["serialize"] }
|
ethereum-types = { version = "0.9.2", default-features = false, features = ["serialize"] }
|
||||||
serde = { version = "1.0.110", default-features = false, features = ["derive"] }
|
|
||||||
rlp = { version = "0.4.5", default-features = false }
|
rlp = { version = "0.4.5", default-features = false }
|
||||||
rustc-hex = { version = "2.1.0", default-features = false }
|
ethabi = { version = "12.0.0", default-features = false, optional = true }
|
||||||
thiserror = { version = "1.0.19", default-features = false }
|
|
||||||
|
|
||||||
# crypto
|
# crypto
|
||||||
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 }
|
||||||
|
|
||||||
|
# misc
|
||||||
|
serde = { version = "1.0.110", default-features = false, features = ["derive"] }
|
||||||
|
rustc-hex = { version = "2.1.0", default-features = false }
|
||||||
|
thiserror = { version = "1.0.19", default-features = false }
|
||||||
|
arrayvec = { version = "0.5.1", default-features = false, optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde_json = { version = "1.0.53", default-features = false }
|
serde_json = { version = "1.0.53", default-features = false }
|
||||||
rand = { version = "0.5.1" }
|
rand = { version = "0.5.1" }
|
||||||
bincode = "1.2.1"
|
bincode = "1.2.1"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["abi"]
|
||||||
|
abi = ["ethabi", "arrayvec"]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! This module implements extensions to the `ethabi` API.
|
//! This module implements extensions to the `ethabi` API.
|
||||||
//! Taken from: https://github.com/gnosis/ethcontract-rs/blob/master/common/src/abiext.rs
|
//! Taken from: https://github.com/gnosis/ethcontract-rs/blob/master/common/src/abiext.rs
|
||||||
use ethers_types::Selector;
|
use crate::Selector;
|
||||||
use ethers_utils::id;
|
use ethers_utils::id;
|
||||||
|
|
||||||
pub use ethabi::Contract as Abi;
|
pub use ethabi::Contract as Abi;
|
|
@ -1,10 +1,9 @@
|
||||||
//! Contract Functions Output types.
|
//! Contract Functions Output types.
|
||||||
//! Adapted from: https://github.com/tomusdrw/rust-web3/blob/master/src/contract/tokens.rs
|
//! Adapted from: https://github.com/tomusdrw/rust-web3/blob/master/src/contract/tokens.rs
|
||||||
#![allow(clippy::all)]
|
#![allow(clippy::all)]
|
||||||
use crate::Token;
|
use crate::{abi::Token, Address, Bytes, H256, U128, U256};
|
||||||
|
|
||||||
use arrayvec::ArrayVec;
|
use arrayvec::ArrayVec;
|
||||||
use ethers_types::{Address, Bytes, H256, U128, U256};
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Error)]
|
#[derive(Clone, Debug, Error)]
|
||||||
|
@ -470,8 +469,8 @@ impl_fixed_types!(1024);
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{Detokenize, Tokenizable};
|
use super::{Detokenize, Tokenizable};
|
||||||
|
use crate::{Address, U256};
|
||||||
use ethabi::Token;
|
use ethabi::Token;
|
||||||
use ethers_types::{Address, U256};
|
|
||||||
|
|
||||||
fn output<R: Detokenize>() -> R {
|
fn output<R: Detokenize>() -> R {
|
||||||
unimplemented!()
|
unimplemented!()
|
|
@ -1,3 +1,4 @@
|
||||||
|
// Taken from https://github.com/tomusdrw/rust-web3/blob/master/src/types/block.rs
|
||||||
use crate::{Address, Bloom, Bytes, H256, U256, U64};
|
use crate::{Address, Bloom, Bytes, H256, U256, U64};
|
||||||
use serde::{ser::SerializeStruct, Deserialize, Serialize, Serializer};
|
use serde::{ser::SerializeStruct, Deserialize, Serialize, Serializer};
|
||||||
|
|
||||||
|
@ -63,8 +64,13 @@ pub struct Block<TX> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||||
|
/// A Block Hash or Block Number
|
||||||
pub enum BlockId {
|
pub enum BlockId {
|
||||||
|
// TODO: May want to expand this to include the requireCanonical field
|
||||||
|
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1898.md
|
||||||
|
/// A block hash
|
||||||
Hash(H256),
|
Hash(H256),
|
||||||
|
/// A block number
|
||||||
Number(BlockNumber),
|
Number(BlockNumber),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +108,7 @@ impl Serialize for BlockId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Block Number
|
/// A block Number (or tag - "latest", "earliest", "pending")
|
||||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||||
pub enum BlockNumber {
|
pub enum BlockNumber {
|
||||||
/// Latest block
|
/// Latest block
|
|
@ -0,0 +1,27 @@
|
||||||
|
pub type Selector = [u8; 4];
|
||||||
|
|
||||||
|
// Re-export common ethereum datatypes with more specific names
|
||||||
|
pub use ethereum_types::H256 as TxHash;
|
||||||
|
pub use ethereum_types::{Address, Bloom, H160, H256, U128, U256, U64};
|
||||||
|
|
||||||
|
mod transaction;
|
||||||
|
pub use transaction::{Overrides, Transaction, TransactionReceipt, TransactionRequest};
|
||||||
|
|
||||||
|
mod bytes;
|
||||||
|
pub use bytes::Bytes;
|
||||||
|
|
||||||
|
mod block;
|
||||||
|
pub use block::{Block, BlockId, BlockNumber};
|
||||||
|
|
||||||
|
mod log;
|
||||||
|
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;
|
|
@ -74,20 +74,21 @@ impl PrivateKey {
|
||||||
tx: TransactionRequest,
|
tx: TransactionRequest,
|
||||||
chain_id: Option<U64>,
|
chain_id: Option<U64>,
|
||||||
) -> Result<Transaction, TxError> {
|
) -> Result<Transaction, TxError> {
|
||||||
// Calling `
|
// The nonce, gas and gasprice fields must already be populated
|
||||||
let nonce = tx.nonce.ok_or(TxError::NonceMissing)?;
|
let nonce = tx.nonce.ok_or(TxError::NonceMissing)?;
|
||||||
let gas_price = tx.gas_price.ok_or(TxError::NonceMissing)?;
|
let gas_price = tx.gas_price.ok_or(TxError::GasPriceMissing)?;
|
||||||
let gas = tx.gas.ok_or(TxError::NonceMissing)?;
|
let gas = tx.gas.ok_or(TxError::GasMissing)?;
|
||||||
|
|
||||||
// Hash the transaction's RLP encoding
|
// Hash the transaction's RLP encoding
|
||||||
let hash = tx.hash(chain_id);
|
let hash = tx.hash(chain_id);
|
||||||
let message = Message::from_slice(hash.as_bytes()).expect("hash is non-zero 32-bytes; qed");
|
let message = Message::from_slice(hash.as_bytes()).expect("hash is non-zero 32-bytes; qed");
|
||||||
|
|
||||||
|
// Sign it (with replay protection if applicable)
|
||||||
let signature = self.sign_with_eip155(&message, chain_id);
|
let signature = self.sign_with_eip155(&message, chain_id);
|
||||||
|
|
||||||
let rlp = tx.rlp_signed(&signature);
|
let rlp = tx.rlp_signed(&signature);
|
||||||
let hash = keccak256(&rlp.0);
|
let hash = keccak256(&rlp.0);
|
||||||
|
|
||||||
|
// This function should not be called with ENS names
|
||||||
let to = tx.to.map(|to| match to {
|
let to = tx.to.map(|to| match to {
|
||||||
NameOrAddress::Address(inner) => inner,
|
NameOrAddress::Address(inner) => inner,
|
||||||
NameOrAddress::Name(_) => {
|
NameOrAddress::Name(_) => {
|
||||||
|
@ -129,6 +130,7 @@ impl PrivateKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Applies [EIP155](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md)
|
||||||
fn to_eip155_v(recovery_id: RecoveryId, chain_id: Option<U64>) -> u64 {
|
fn to_eip155_v(recovery_id: RecoveryId, chain_id: Option<U64>) -> u64 {
|
||||||
let standard_v = recovery_id.to_i32() as u64;
|
let standard_v = recovery_id.to_i32() as u64;
|
||||||
if let Some(chain_id) = chain_id {
|
if let Some(chain_id) = chain_id {
|
||||||
|
@ -156,7 +158,7 @@ impl Deref for PrivateKey {
|
||||||
|
|
||||||
impl DefaultIsZeroes for PrivateKey {}
|
impl DefaultIsZeroes for PrivateKey {}
|
||||||
|
|
||||||
/// A public key
|
/// A secp256k1 Public Key
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct PublicKey(pub(super) PubKey);
|
pub struct PublicKey(pub(super) PubKey);
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
mod keys;
|
||||||
|
pub use keys::{PrivateKey, PublicKey, TxError};
|
||||||
|
|
||||||
|
mod signature;
|
||||||
|
pub use signature::Signature;
|
|
@ -1,35 +1,10 @@
|
||||||
//! Various Ethereum Related Datatypes
|
//! Various Ethereum Related Datatypes
|
||||||
|
|
||||||
pub type Selector = [u8; 4];
|
mod crypto;
|
||||||
|
pub use crypto::*;
|
||||||
|
|
||||||
// Re-export common ethereum datatypes with more specific names
|
mod chainstate;
|
||||||
pub use ethereum_types::H256 as TxHash;
|
pub use chainstate::*;
|
||||||
pub use ethereum_types::{Address, Bloom, H160, H256, U128, U256, U64};
|
|
||||||
|
|
||||||
mod transaction;
|
#[cfg(feature = "abi")]
|
||||||
pub use transaction::{Overrides, Transaction, TransactionReceipt, TransactionRequest};
|
pub mod abi;
|
||||||
|
|
||||||
mod keys;
|
|
||||||
pub use keys::{PrivateKey, PublicKey, TxError};
|
|
||||||
|
|
||||||
mod signature;
|
|
||||||
pub use signature::Signature;
|
|
||||||
|
|
||||||
mod bytes;
|
|
||||||
pub use bytes::Bytes;
|
|
||||||
|
|
||||||
mod block;
|
|
||||||
pub use block::{Block, BlockId, BlockNumber};
|
|
||||||
|
|
||||||
mod log;
|
|
||||||
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;
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ edition = "2018"
|
||||||
[features]
|
[features]
|
||||||
default = ["full"]
|
default = ["full"]
|
||||||
full = [
|
full = [
|
||||||
"abi",
|
|
||||||
"contract",
|
"contract",
|
||||||
"providers",
|
"providers",
|
||||||
"signers",
|
"signers",
|
||||||
|
@ -15,7 +14,6 @@ full = [
|
||||||
"utils",
|
"utils",
|
||||||
]
|
]
|
||||||
|
|
||||||
abi = ["ethers-abi"]
|
|
||||||
contract = ["ethers-contract"]
|
contract = ["ethers-contract"]
|
||||||
providers = ["ethers-providers"]
|
providers = ["ethers-providers"]
|
||||||
signers = ["ethers-signers"]
|
signers = ["ethers-signers"]
|
||||||
|
@ -23,7 +21,6 @@ types = ["ethers-types"]
|
||||||
utils = ["ethers-utils"]
|
utils = ["ethers-utils"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ethers-abi = { version = "0.1.0", path = "../ethers-abi", optional = true }
|
|
||||||
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 }
|
||||||
|
|
|
@ -15,11 +15,6 @@
|
||||||
//! More examples can be found in the [`examples` directory of the
|
//! More examples can be found in the [`examples` directory of the
|
||||||
//! repositry](https://github.com/gakonst/ethers-rs)
|
//! repositry](https://github.com/gakonst/ethers-rs)
|
||||||
|
|
||||||
#[cfg(feature = "abi")]
|
|
||||||
pub mod abi {
|
|
||||||
pub use ethers_abi::*;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "contract")]
|
#[cfg(feature = "contract")]
|
||||||
pub mod contract {
|
pub mod contract {
|
||||||
pub use ethers_contract::*;
|
pub use ethers_contract::*;
|
||||||
|
|
Loading…
Reference in New Issue