diff --git a/ethers-core/src/utils/ganache.rs b/ethers-core/src/utils/ganache.rs index b3870862..19a67ef9 100644 --- a/ethers-core/src/utils/ganache.rs +++ b/ethers-core/src/utils/ganache.rs @@ -1,9 +1,11 @@ use std::process::{Child, Command}; /// A ganache CLI instance. Will close the instance when dropped. -pub struct Ganache(Child); +/// +/// Construct this using [`Ganache`](./struct.Ganache.html) +pub struct GanacheInstance(Child); -impl Drop for Ganache { +impl Drop for GanacheInstance { fn drop(&mut self) { self.0.kill().expect("could not kill ganache"); } @@ -17,13 +19,13 @@ impl Drop for Ganache { /// /// # Example /// -/// ```rust,ignore -/// use ethers_types::utils::ganache::GanacheBuilder; +/// ```no_run +/// use ethers_core::utils::Ganache; /// /// let port = 8545u64; /// let url = format!("http://localhost:{}", port).to_string(); /// -/// let ganache = GanacheBuilder::new() +/// let ganache = Ganache::new() /// .port(port) /// .mnemonic("abstract vacuum mammal awkward pudding scene penalty purchase dinner depart evoke puzzle") /// .spawn(); @@ -31,12 +33,12 @@ impl Drop for Ganache { /// drop(ganache); // this will kill the instance /// ``` #[derive(Clone, Default)] -pub struct GanacheBuilder { +pub struct Ganache { port: Option, mnemonic: Option, } -impl GanacheBuilder { +impl Ganache { /// Creates an empty Ganache builder. /// The default port is 8545. The mnemonic is chosen randomly. pub fn new() -> Self { @@ -58,7 +60,7 @@ impl GanacheBuilder { /// Consumes the builder and spawns `ganache-cli` with stdout redirected /// to /dev/null. This takes ~2 seconds to execute as it blocks while /// waiting for `ganache-cli` to launch. - pub fn spawn(self) -> Ganache { + pub fn spawn(self) -> GanacheInstance { let mut cmd = Command::new("ganache-cli"); cmd.stdout(std::process::Stdio::null()); if let Some(port) = self.port { @@ -75,6 +77,6 @@ impl GanacheBuilder { // TODO: Change this to poll for `port` let sleep_time = std::time::Duration::from_secs(2); std::thread::sleep(sleep_time); - Ganache(ganache_pid) + GanacheInstance(ganache_pid) } } diff --git a/ethers-core/src/utils/hash.rs b/ethers-core/src/utils/hash.rs index 6c804eb7..89594c62 100644 --- a/ethers-core/src/utils/hash.rs +++ b/ethers-core/src/utils/hash.rs @@ -44,7 +44,11 @@ pub fn id>(signature: S) -> [u8; 4] { output } -/// Serialize a type. Panics if the type is returns error during serialization. +/// Serialize a type. +/// +/// # Panics +/// +/// If the type returns an error during serialization. pub fn serialize(t: &T) -> serde_json::Value { serde_json::to_value(t).expect("Types never fail to serialize.") } diff --git a/ethers-core/src/utils/mod.rs b/ethers-core/src/utils/mod.rs index 7d6d70fc..13069f5b 100644 --- a/ethers-core/src/utils/mod.rs +++ b/ethers-core/src/utils/mod.rs @@ -1,6 +1,6 @@ /// Utilities for launching a ganache-cli testnet instance mod ganache; -pub use ganache::{Ganache, GanacheBuilder}; +pub use ganache::Ganache; /// Solidity compiler bindings mod solc; diff --git a/ethers-core/src/utils/solc.rs b/ethers-core/src/utils/solc.rs index 2d98ba5a..3944a582 100644 --- a/ethers-core/src/utils/solc.rs +++ b/ethers-core/src/utils/solc.rs @@ -1,17 +1,3 @@ -//! Solidity Compiler Bindings -//! -//! Assumes that `solc` is installed and available in the caller's $PATH. Any calls -//! will fail otherwise. -//! -//! # Examples -//! -//! ```rust,ignore -//! // Give it a glob -//! let contracts = Solc::new("./contracts/*") -//! .optimizer(200) -//! .build(); -//! let contract = contracts.get("SimpleStorage").unwrap(); -//! ``` use crate::{abi::Abi, types::Bytes}; use glob::glob; use rustc_hex::FromHex; @@ -43,7 +29,30 @@ pub struct CompiledContract { pub bytecode: Bytes, } -/// Solc builder +/// Solidity Compiler Bindings +/// +/// Assumes that `solc` is installed and available in the caller's $PATH. Any calls +/// will **panic** otherwise. +/// +/// By default, it uses 200 optimizer runs and Istanbul as the EVM version +/// +/// # Examples +/// +/// ```no_run +/// use ethers_core::utils::Solc; +/// +/// # fn main() -> Result<(), Box> { +/// // Give it a glob +/// let contracts = Solc::new("./contracts/*") +/// .optimizer(200) +/// .build()?; +/// +/// // this will return None if the specified contract did not exist in the compiled +/// // files +/// let contract = contracts.get("SimpleStorage").expect("contract not found"); +/// # Ok(()) +/// # } +/// ``` pub struct Solc { /// The path where contracts will be read from pub paths: Vec, @@ -156,7 +165,7 @@ impl Solc { } /// Sets the optimizer runs (default = 200) - pub fn optimizer_runs(mut self, runs: usize) -> Self { + pub fn optimizer(mut self, runs: usize) -> Self { self.optimizer = runs; self }