parent
69eb21da67
commit
86a9e7c3af
|
@ -1,4 +1,4 @@
|
||||||
# ethers-core
|
# ethers-contract
|
||||||
|
|
||||||
Type-safe abstractions for interacting with Ethereum smart contracts.
|
Type-safe abstractions for interacting with Ethereum smart contracts.
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
use crate::contract::ContractInstance;
|
use crate::ContractInstance;
|
||||||
|
|
||||||
pub use ethers_core::abi::AbiError;
|
pub use ethers_core::abi::AbiError;
|
||||||
use ethers_core::{
|
use ethers_core::{
|
||||||
abi::{Abi, Detokenize, Error, Event, Function, FunctionExt, RawLog, Token, Tokenize},
|
abi::{Abi, Detokenize, Error, Event, Function, FunctionExt, RawLog, Token, Tokenize},
|
||||||
types::{Address, Bytes, Selector, H256},
|
types::{Address, Bytes, Selector, H256},
|
||||||
};
|
};
|
||||||
use ethers_providers::Middleware;
|
use ethers_providers::Middleware;
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
borrow::Borrow,
|
borrow::Borrow,
|
||||||
collections::{BTreeMap, HashMap},
|
collections::{BTreeMap, HashMap},
|
||||||
|
|
|
@ -3,8 +3,9 @@
|
||||||
#![deny(unsafe_code)]
|
#![deny(unsafe_code)]
|
||||||
#![warn(missing_docs)]
|
#![warn(missing_docs)]
|
||||||
|
|
||||||
mod contract;
|
#[path = "contract.rs"]
|
||||||
pub use contract::{Contract, ContractInstance};
|
mod _contract;
|
||||||
|
pub use _contract::{Contract, ContractInstance};
|
||||||
|
|
||||||
mod base;
|
mod base;
|
||||||
pub use base::{decode_function_data, encode_function_data, AbiError, BaseContract};
|
pub use base::{decode_function_data, encode_function_data, AbiError, BaseContract};
|
||||||
|
@ -67,3 +68,32 @@ pub use once_cell::sync::Lazy;
|
||||||
|
|
||||||
#[cfg(feature = "eip712")]
|
#[cfg(feature = "eip712")]
|
||||||
pub use ethers_derive_eip712::*;
|
pub use ethers_derive_eip712::*;
|
||||||
|
|
||||||
|
// For Abigen expansions in docs.rs builds.
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
#[allow(unused_extern_crates)]
|
||||||
|
extern crate self as ethers_contract;
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
#[allow(unused_extern_crates)]
|
||||||
|
#[cfg(docsrs)]
|
||||||
|
extern crate self as ethers;
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
#[cfg(docsrs)]
|
||||||
|
pub mod core {
|
||||||
|
pub use ethers_core::*;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
#[cfg(docsrs)]
|
||||||
|
pub mod contract {
|
||||||
|
pub use crate::*;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
#[cfg(docsrs)]
|
||||||
|
pub mod providers {
|
||||||
|
pub use ethers_providers::*;
|
||||||
|
}
|
||||||
|
|
|
@ -56,10 +56,13 @@ pub struct ProjectEnvironment {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProjectEnvironment {
|
impl ProjectEnvironment {
|
||||||
|
/// Creates a new instance using the given manifest dir and crate name.
|
||||||
pub fn new<T: Into<PathBuf>, U: Into<String>>(manifest_dir: T, crate_name: U) -> Self {
|
pub fn new<T: Into<PathBuf>, U: Into<String>>(manifest_dir: T, crate_name: U) -> Self {
|
||||||
Self { manifest_dir: manifest_dir.into(), crate_name: Some(crate_name.into()) }
|
Self { manifest_dir: manifest_dir.into(), crate_name: Some(crate_name.into()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates a new instance using the the `CARGO_MANIFEST_DIR` and `CARGO_CRATE_NAME` environment
|
||||||
|
/// variables.
|
||||||
pub fn new_from_env() -> Option<Self> {
|
pub fn new_from_env() -> Option<Self> {
|
||||||
Some(Self {
|
Some(Self {
|
||||||
manifest_dir: env::var_os("CARGO_MANIFEST_DIR")?.into(),
|
manifest_dir: env::var_os("CARGO_MANIFEST_DIR")?.into(),
|
||||||
|
@ -90,29 +93,15 @@ impl ProjectEnvironment {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn crate_names_from_metadata(&self) -> Option<CrateNames> {
|
fn crate_names_from_metadata(&self) -> Option<CrateNames> {
|
||||||
let metadata = MetadataCommand::new().current_dir(&self.manifest_dir).exec().ok()?;
|
let metadata = MetadataCommand::new().current_dir(&self.manifest_dir).exec().ok()?;
|
||||||
let pkg = metadata.root_package()?;
|
let pkg = metadata.root_package()?;
|
||||||
|
|
||||||
// return ethers_* if the root package is an internal ethers crate since `ethers` is not
|
// return ethers_* if the root package is an internal ethers crate since `ethers` is not
|
||||||
// available
|
// available
|
||||||
let crate_is_root = self.is_crate_root();
|
if pkg.name.parse::<EthersCrate>().is_ok() || pkg.name == "ethers" {
|
||||||
if let Ok(current_pkg) = pkg.name.parse::<EthersCrate>() {
|
return Some(EthersCrate::path_names().collect())
|
||||||
// replace `current_pkg`'s name with "crate"
|
}
|
||||||
let names =
|
|
||||||
EthersCrate::path_names()
|
|
||||||
.map(|(pkg, name)| {
|
|
||||||
if crate_is_root && pkg == current_pkg {
|
|
||||||
(pkg, "crate")
|
|
||||||
} else {
|
|
||||||
(pkg, name)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
return Some(names)
|
|
||||||
} /* else if pkg.name == "ethers" {
|
|
||||||
// should not happen (the root package the `ethers` workspace package itself)
|
|
||||||
} */
|
|
||||||
|
|
||||||
let mut names: CrateNames = EthersCrate::ethers_path_names().collect();
|
let mut names: CrateNames = EthersCrate::ethers_path_names().collect();
|
||||||
for dep in pkg.dependencies.iter() {
|
for dep in pkg.dependencies.iter() {
|
||||||
|
@ -293,7 +282,7 @@ impl EthersCrate {
|
||||||
pub const fn ethers_path_name(self) -> &'static str {
|
pub const fn ethers_path_name(self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
// re-exported in ethers::contract
|
// re-exported in ethers::contract
|
||||||
Self::EthersContractAbigen => "::ethers::contract", // partly
|
Self::EthersContractAbigen => "::ethers::contract", // partially
|
||||||
Self::EthersContractDerive => "::ethers::contract",
|
Self::EthersContractDerive => "::ethers::contract",
|
||||||
Self::EthersDeriveEip712 => "::ethers::contract",
|
Self::EthersDeriveEip712 => "::ethers::contract",
|
||||||
|
|
||||||
|
@ -386,7 +375,7 @@ mod tests {
|
||||||
|
|
||||||
let krate = s.crate_name.as_ref().and_then(|x| x.parse::<EthersCrate>().ok());
|
let krate = s.crate_name.as_ref().and_then(|x| x.parse::<EthersCrate>().ok());
|
||||||
let is_internal = krate.is_some();
|
let is_internal = krate.is_some();
|
||||||
let mut expected: CrateNames = match (is_internal, ethers) {
|
let expected: CrateNames = match (is_internal, ethers) {
|
||||||
// internal
|
// internal
|
||||||
(true, _) => EthersCrate::path_names().collect(),
|
(true, _) => EthersCrate::path_names().collect(),
|
||||||
|
|
||||||
|
@ -403,10 +392,6 @@ mod tests {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if is_internal {
|
|
||||||
expected.insert(krate.unwrap(), "crate");
|
|
||||||
}
|
|
||||||
|
|
||||||
// don't use assert for a better custom message
|
// don't use assert for a better custom message
|
||||||
if names != expected {
|
if names != expected {
|
||||||
// BTreeMap sorts the keys
|
// BTreeMap sorts the keys
|
||||||
|
|
|
@ -83,6 +83,11 @@
|
||||||
#![deny(rustdoc::broken_intra_doc_links)]
|
#![deny(rustdoc::broken_intra_doc_links)]
|
||||||
#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms), allow(dead_code, unused_variables))))]
|
#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms), allow(dead_code, unused_variables))))]
|
||||||
|
|
||||||
|
// For macro expansion
|
||||||
|
#[doc(hidden)]
|
||||||
|
#[allow(unused_extern_crates)]
|
||||||
|
extern crate self as ethers;
|
||||||
|
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use ethers_addressbook as addressbook;
|
pub use ethers_addressbook as addressbook;
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
|
|
Loading…
Reference in New Issue