docs(core): improve struct level docs
This commit is contained in:
parent
f93b8b6919
commit
6f5bc95543
|
@ -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<u64>,
|
||||
mnemonic: Option<String>,
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,11 @@ pub fn id<S: AsRef<str>>(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: serde::Serialize>(t: &T) -> serde_json::Value {
|
||||
serde_json::to_value(t).expect("Types never fail to serialize.")
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<dyn std::error::Error>> {
|
||||
/// // 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<String>,
|
||||
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue