Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(node-bindings): support appending extra args #1299

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions crates/node-bindings/src/nodes/geth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ pub struct Geth {
genesis: Option<Genesis>,
mode: NodeMode,
clique_private_key: Option<SigningKey>,
args: Vec<String>,
}

impl Geth {
Expand Down Expand Up @@ -367,6 +368,28 @@ impl Geth {
self
}

/// Adds an argument to pass to `geth`.
///
/// Pass any arg that is not supported by the builder.
pub fn arg<T: Into<String>>(mut self, arg: T) -> Self {
self.args.push(arg.into());
self
}

/// Adds multiple arguments to pass to `geth`.
///
/// Pass any args that is not supported by the builder.
pub fn args<I, S>(mut self, args: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
yash-atreya marked this conversation as resolved.
Show resolved Hide resolved
{
for arg in args {
self = self.arg(arg);
}
self
}

/// Consumes the builder and spawns `geth`.
///
/// # Panics
Expand Down Expand Up @@ -543,6 +566,8 @@ impl Geth {
cmd.arg("--ipcpath").arg(ipc);
}

cmd.args(self.args);

let mut child = cmd.spawn().map_err(NodeError::SpawnError)?;

let stderr = child.stderr.take().ok_or(NodeError::NoStderr)?;
Expand Down
27 changes: 27 additions & 0 deletions crates/node-bindings/src/nodes/reth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ pub struct Reth {
data_dir: Option<PathBuf>,
chain_or_path: Option<String>,
genesis: Option<Genesis>,
args: Vec<String>,
}

impl Reth {
Expand All @@ -184,6 +185,7 @@ impl Reth {
data_dir: None,
chain_or_path: None,
genesis: None,
args: Vec::new(),
}
}

Expand Down Expand Up @@ -306,6 +308,28 @@ impl Reth {
self
}

/// Adds an argument to pass to `reth`.
///
/// Pass any arg that is not supported by the builder.
pub fn arg<T: Into<String>>(mut self, arg: T) -> Self {
self.args.push(arg.into());
self
}

/// Adds multiple arguments to pass to `reth`.
///
/// Pass any args that is not supported by the builder.
pub fn args<I, S>(mut self, args: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
for arg in args {
self = self.arg(arg);
}
self
}

/// Consumes the builder and spawns `reth`.
///
/// # Panics
Expand Down Expand Up @@ -413,6 +437,9 @@ impl Reth {
// Disable color output to make parsing logs easier.
cmd.arg("--color").arg("never");

// Add any additional arguments.
cmd.args(self.args);

let mut child = cmd.spawn().map_err(NodeError::SpawnError)?;

let stdout = child.stdout.take().ok_or(NodeError::NoStdout)?;
Expand Down