Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
100 changes: 100 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ alloy-sol-types = "1.5.6"
bytes = "1.10.1"
clap = { version = "4.5.40", features = ["derive"] }
derive_more = "2.0.1"
dirs = "6.0.0"
eyre = "0.6.12"
libc = "0.2.177"
rustyline = "17.0.2"
sha2 = "0.10"

# rpc
jsonrpsee = "0.26.0"
jsonrpsee = { version = "0.26.0", features = ["http-client", "ws-client"] }
jsonrpsee-core = { version = "0.26.0", features = ["server"] }
jsonrpsee-proc-macros = "0.26.0"

Expand All @@ -36,6 +39,7 @@ reth-basic-payload-builder = { git = "https://github.com/paradigmxyz/reth", tag
reth-chainspec = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.3" }
reth-cli = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.3" }
reth-cli-commands = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.3" }
reth-cli-runner = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.3" }
reth-cli-util = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.3" }
reth-codecs = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.3" }
reth-consensus-common = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.3" }
Expand Down Expand Up @@ -63,23 +67,26 @@ reth-rpc-convert = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.3
reth-rpc-engine-api = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.3" }
reth-rpc-eth-api = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.3" }
reth-rpc-eth-types = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.3" }
reth-rpc-server-types = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.3" }
reth-storage-api = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.3" }
reth-transaction-pool = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.3" }
serde = { version = "1.0", features = ["derive"], default-features = false }
serde_json = "1.0"
thiserror = "2.0"
tokio = "1.46.0"
tokio = { version = "1.46.0", features = ["macros", "rt-multi-thread", "net", "io-util"] }
tracing = "0.1.41"

[dev-dependencies]
alloy-provider = "1.6.3"
alloy-rpc-client = "1.6.3"
alloy-rpc-types-trace = "1.6.3"
eyre = "0.6.12"
jsonrpsee = { version = "0.26.0", features = ["server"] }
reth-e2e-test-utils = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.3" }
reth-rpc-builder = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.3" }
reth-trie-common = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.3" }
revm-inspectors = "0.34.2"
tempfile = "3.15.0"
test-fuzz = "7"

[build-dependencies]
Expand Down
58 changes: 58 additions & 0 deletions src/berachain_cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//! Berachain-specific CLI subcommands (extension to reth Ethereum CLI).

use clap::Subcommand;
use reth_cli_runner::CliRunner;
use reth_ethereum_cli::app::ExtendedCommand;

#[derive(Debug, Subcommand)]
pub enum BerachainSubcommands {
/// JSON-RPC console over IPC, HTTP, or WebSocket.
Console(crate::console::ConsoleCommand),
}

impl ExtendedCommand for BerachainSubcommands {
fn execute(self, runner: CliRunner) -> eyre::Result<()> {
match self {
Self::Console(cmd) => cmd.run(runner),
}
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::chainspec::BerachainChainSpecParser;
use clap::Parser;
use reth_cli_commands::node::NoArgs;
use reth_ethereum_cli::interface::{Cli, Commands};
use reth_rpc_server_types::DefaultRpcModuleValidator;

#[test]
fn parses_console_subcommand() {
let err = Cli::<
BerachainChainSpecParser,
NoArgs,
DefaultRpcModuleValidator,
BerachainSubcommands,
>::try_parse_from(["bera-reth", "console", "--help"])
.unwrap_err();
assert_eq!(err.kind(), clap::error::ErrorKind::DisplayHelp);
}

#[test]
fn ext_console_variant_reachable() {
let cli = Cli::<
BerachainChainSpecParser,
NoArgs,
DefaultRpcModuleValidator,
BerachainSubcommands,
>::try_parse_from(["bera-reth", "console", "--exec", "eth_blockNumber"])
.unwrap();
match cli.command {
Commands::Ext(BerachainSubcommands::Console(ref c)) => {
assert_eq!(c.exec.as_deref(), Some("eth_blockNumber"));
}
_ => panic!("expected console ext"),
}
}
}
61 changes: 61 additions & 0 deletions src/console/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
use clap::Args;
use reth_cli_runner::CliRunner;

/// JSON-RPC console (IPC, HTTP, or WebSocket).
#[derive(Debug, Clone, Args)]
pub struct ConsoleCommand {
/// IPC path, or `http(s)://…`, or `ws(s)://…`. If omitted, uses the platform default
/// datadir with `reth.ipc`.
#[arg(value_name = "ENDPOINT")]
pub endpoint: Option<String>,

/// Run a single command and print raw JSON (implies raw output; no prompts).
#[arg(long = "exec")]
pub exec: Option<String>,

/// In REPL mode, print raw JSON instead of tables and annotations.
#[arg(long)]
pub raw: bool,
}

impl ConsoleCommand {
pub fn run(self, runner: CliRunner) -> eyre::Result<()> {
runner.block_on(super::run::run_console(self))
}
}

#[cfg(test)]
mod tests {
use super::*;
use clap::Parser;

#[derive(clap::Parser)]
#[command(name = "bera-reth")]
struct Top {
#[command(subcommand)]
sub: Sub,
}

#[derive(clap::Subcommand)]
enum Sub {
Console(ConsoleCommand),
}

#[test]
fn parses_exec_and_raw() {
let Top { sub: Sub::Console(c) } =
Top::try_parse_from(["bera-reth", "console", "--exec", "eth.blockNumber", "--raw"])
.unwrap();
assert_eq!(c.exec.as_deref(), Some("eth.blockNumber"));
assert!(c.raw);
assert!(c.endpoint.is_none());
}

#[test]
fn parses_positional_endpoint() {
let Top { sub: Sub::Console(c) } =
Top::try_parse_from(["bera-reth", "console", "/tmp/reth.ipc"]).unwrap();
assert_eq!(c.endpoint.as_deref(), Some("/tmp/reth.ipc"));
assert!(!c.raw);
}
}
Loading
Loading