diff --git a/ethers-core/src/utils/geth.rs b/ethers-core/src/utils/geth.rs index 8657c888..8c13d175 100644 --- a/ethers-core/src/utils/geth.rs +++ b/ethers-core/src/utils/geth.rs @@ -164,6 +164,7 @@ impl Default for PrivateNetOptions { /// ``` #[derive(Clone, Default)] pub struct Geth { + program: Option, port: Option, authrpc_port: Option, ipc_path: Option, @@ -180,6 +181,32 @@ impl Geth { Self::default() } + /// Creates a Geth builder which will execute `geth` at the given path. + /// + /// # Example + /// + /// ``` + /// use ethers_core::utils::Geth; + /// # fn a() { + /// let geth = Geth::at("../go-ethereum/build/bin/geth").spawn(); + /// + /// println!("Geth running at `{}`", geth.endpoint()); + /// # } + /// ``` + pub fn at(path: impl Into) -> Self { + Self::new().path(path) + } + + /// Sets the `path` to the `geth` executable + /// + /// By default, it's expected that `geth` is in `$PATH`, see also + /// [`std::process::Command::new()`] + #[must_use] + pub fn path>(mut self, path: T) -> Self { + self.program = Some(path.into()); + self + } + /// Sets the port which will be used when the `geth-cli` instance is launched. #[must_use] pub fn port>(mut self, port: T) -> Self { @@ -274,9 +301,10 @@ impl Geth { /// Consumes the builder and spawns `geth` with stdout redirected /// to /dev/null. pub fn spawn(self) -> GethInstance { - let mut cmd = Command::new(GETH); + let mut cmd = + if let Some(ref prg) = self.program { Command::new(prg) } else { Command::new(GETH) }; // geth uses stderr for its logs - cmd.stderr(std::process::Stdio::piped()); + cmd.stderr(Stdio::piped()); let port = if let Some(port) = self.port { port } else { unused_port() }; let authrpc_port = if let Some(port) = self.authrpc_port { port } else { unused_port() };