Skip to content

Commit ba9d925

Browse files
committed
refactor: change rpc from string to url
1 parent 8cd2978 commit ba9d925

File tree

5 files changed

+24
-14
lines changed

5 files changed

+24
-14
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ clap = { version = "4.5.4", features = ["derive", "env"] }
1919
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
2020
dirs = "5.0.1"
2121
ctrlc = "3.2.3"
22+
url = "2.5.0"
2223

2324
helios-core = { path = "../core" }
2425
helios-ethereum = { path = "../ethereum" }

cli/src/main.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use helios_opstack::{config::Config as OpStackConfig, OpStackClient, OpStackClie
2525
use tracing::{error, info};
2626
use tracing_subscriber::filter::{EnvFilter, LevelFilter};
2727
use tracing_subscriber::FmtSubscriber;
28+
use url::Url;
2829

2930
#[tokio::main]
3031
async fn main() -> Result<()> {
@@ -129,10 +130,10 @@ struct EthereumArgs {
129130
rpc_port: Option<u16>,
130131
#[clap(short = 'w', long, env)]
131132
checkpoint: Option<B256>,
132-
#[clap(short, long, env)]
133-
execution_rpc: Option<String>,
134-
#[clap(short, long, env)]
135-
consensus_rpc: Option<String>,
133+
#[clap(short, long, env, value_parser = parse_url)]
134+
execution_rpc: Option<Url>,
135+
#[clap(short, long, env, value_parser = parse_url)]
136+
consensus_rpc: Option<Url>,
136137
#[clap(short, long, env)]
137138
data_dir: Option<String>,
138139
#[clap(short = 'f', long, env)]
@@ -187,10 +188,10 @@ struct OpStackArgs {
187188
rpc_bind_ip: Option<IpAddr>,
188189
#[clap(short = 'p', long, env, default_value = "8545")]
189190
rpc_port: Option<u16>,
190-
#[clap(short, long, env)]
191-
execution_rpc: Option<String>,
192-
#[clap(short, long, env)]
193-
consensus_rpc: Option<String>,
191+
#[clap(short, long, env, value_parser = parse_url)]
192+
execution_rpc: Option<Url>,
193+
#[clap(short, long, env, value_parser = parse_url)]
194+
consensus_rpc: Option<Url>,
194195
#[clap(
195196
short = 'w',
196197
long = "ethereum-checkpoint",
@@ -226,11 +227,11 @@ impl OpStackArgs {
226227
let mut user_dict = HashMap::new();
227228

228229
if let Some(rpc) = &self.execution_rpc {
229-
user_dict.insert("execution_rpc", Value::from(rpc.clone()));
230+
user_dict.insert("execution_rpc", Value::from(rpc.to_string()));
230231
}
231232

232233
if let Some(rpc) = &self.consensus_rpc {
233-
user_dict.insert("consensus_rpc", Value::from(rpc.clone()));
234+
user_dict.insert("consensus_rpc", Value::from(rpc.to_string()));
234235
}
235236

236237
if self.rpc_bind_ip.is_some() && self.rpc_port.is_some() {
@@ -265,3 +266,7 @@ fn true_or_none(b: bool) -> Option<bool> {
265266
None
266267
}
267268
}
269+
270+
fn parse_url(s: &str) -> Result<Url, url::ParseError> {
271+
Url::parse(s)
272+
}

ethereum/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ triehash-ethereum.workspace = true
1313
figment = { version = "0.10.7", features = ["toml", "env"] }
1414
serde_yaml = "0.9.14"
1515
strum = { version = "0.26.2", features = ["derive"] }
16+
url = "2.5.0"
1617

1718
# async/futures
1819
tokio.workspace = true

ethereum/src/config/cli.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::net::IpAddr;
22
use std::{collections::HashMap, path::PathBuf};
3+
use url::Url;
34

45
use alloy::primitives::B256;
56
use figment::{providers::Serialized, value::Value};
@@ -8,8 +9,8 @@ use serde::{Deserialize, Serialize};
89
/// Cli Config
910
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
1011
pub struct CliConfig {
11-
pub execution_rpc: Option<String>,
12-
pub consensus_rpc: Option<String>,
12+
pub execution_rpc: Option<Url>,
13+
pub consensus_rpc: Option<Url>,
1314
pub checkpoint: Option<B256>,
1415
pub rpc_bind_ip: Option<IpAddr>,
1516
pub rpc_port: Option<u16>,
@@ -24,11 +25,11 @@ impl CliConfig {
2425
let mut user_dict = HashMap::new();
2526

2627
if let Some(rpc) = &self.execution_rpc {
27-
user_dict.insert("execution_rpc", Value::from(rpc.clone()));
28+
user_dict.insert("execution_rpc", Value::from(rpc.to_string()));
2829
}
2930

3031
if let Some(rpc) = &self.consensus_rpc {
31-
user_dict.insert("consensus_rpc", Value::from(rpc.clone()));
32+
user_dict.insert("consensus_rpc", Value::from(rpc.to_string()));
3233
}
3334

3435
if let Some(checkpoint) = &self.checkpoint {

0 commit comments

Comments
 (0)