Skip to content

Commit

Permalink
fixed merge conflicts with clap4
Browse files Browse the repository at this point in the history
  • Loading branch information
lijunwangs committed Mar 7, 2025
1 parent 1eec6b5 commit 5b479b4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 63 deletions.
71 changes: 14 additions & 57 deletions vortexor/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ fn port_range_validator(port_range: &str) -> Result<(), String> {
}
}

fn validate_http_url(input: String) -> Result<(), String> {
fn validate_http_url(input: &str) -> Result<(), String> {
// Attempt to parse the input as a URL
let parsed_url = Url::parse(&input).map_err(|e| format!("Invalid URL: {}", e))?;
let parsed_url = Url::parse(input).map_err(|e| format!("Invalid URL: {}", e))?;

// Check the scheme of the URL
match parsed_url.scheme() {
Expand All @@ -75,31 +75,9 @@ fn validate_http_url(input: String) -> Result<(), String> {
}
}

fn validate_websocket_url(input: String) -> Result<(), String> {
fn validate_websocket_url(input: &str) -> Result<(), String> {
// Attempt to parse the input as a URL
let parsed_url = Url::parse(&input).map_err(|e| format!("Invalid URL: {}", e))?;

// Check the scheme of the URL
match parsed_url.scheme() {
"ws" | "wss" => Ok(()),
scheme => Err(format!("Invalid scheme: {}. Must be ws, or wss.", scheme)),
}
}

fn validate_http_url(input: String) -> Result<(), String> {
// Attempt to parse the input as a URL
let parsed_url = Url::parse(&input).map_err(|e| format!("Invalid URL: {}", e))?;

// Check the scheme of the URL
match parsed_url.scheme() {
"http" | "https" => Ok(()),
scheme => Err(format!("Invalid scheme: {}. Must be http, https.", scheme)),
}
}

fn validate_websocket_url(input: String) -> Result<(), String> {
// Attempt to parse the input as a URL
let parsed_url = Url::parse(&input).map_err(|e| format!("Invalid URL: {}", e))?;
let parsed_url = Url::parse(input).map_err(|e| format!("Invalid URL: {}", e))?;

// Check the scheme of the URL
match parsed_url.scheme() {
Expand Down Expand Up @@ -261,44 +239,23 @@ pub fn command(version: &str, default_args: DefaultArgs) -> Command {
.help("The destination validator address to which the vortexor will forward transactions."),
)
.arg(
Arg::with_name("rpc_server")
.short("r")
.long("rpc-server")
.value_name("HOST:PORT")
.takes_value(true)
.multiple(true)
.validator(validate_http_url)
.help("The address of RPC server to which the vortexor will forward transaction"),
)
.arg(
Arg::with_name("websocket_server")
.short("w")
.long("websocket-server")
.value_name("HOST:PORT")
.takes_value(true)
.multiple(true)
.validator(validate_websocket_url)
.help("The address of websocket server to which the vortexor will forward transaction. \
If multiple rpc servers are set, the count of websocket servers must match that of the rpc servers."),
)
.arg(
Arg::with_name("rpc_server")
.short("r")
Arg::new("rpc_server")
.short('r')
.long("rpc-server")
.value_name("HOST:PORT")
.takes_value(true)
.multiple(true)
.validator(validate_http_url)
.num_args(1)
.action(ArgAction::Append)
.value_parser(validate_http_url)
.help("The address of RPC server to which the vortexor will forward transaction"),
)
.arg(
Arg::with_name("websocket_server")
.short("w")
Arg::new("websocket_server")
.short('w')
.long("websocket-server")
.value_name("HOST:PORT")
.takes_value(true)
.multiple(true)
.validator(validate_websocket_url)
.num_args(1)
.action(ArgAction::Append)
.value_parser(validate_websocket_url)
.help("The address of websocket server to which the vortexor will forward transaction. \
If multiple rpc servers are set, the count of websocket servers must match that of the rpc servers."),
)
Expand Down
14 changes: 8 additions & 6 deletions vortexor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use {
solana_core::banking_trace::BankingTracer,
solana_logger::redirect_stderr_to_file,
solana_net_utils::{bind_in_range_with_config, SocketConfig},
solana_sdk::{net::DEFAULT_TPU_COALESCE, signature::read_keypair_file, pubkey::Pubkey, signer::Signer},
solana_sdk::{
net::DEFAULT_TPU_COALESCE, pubkey::Pubkey, signature::read_keypair_file, signer::Signer,
},
solana_streamer::streamer::StakedNodes,
solana_vortexor::{
cli::{command, DefaultArgs},
Expand Down Expand Up @@ -132,20 +134,20 @@ pub fn main() {
.into_iter()
.collect::<Vec<_>>();

let rpc_servers = values_t!(matches, "rpc_server", String)
let rpc_servers = matches
.get_many::<String>("rpc_server")
.unwrap_or_default()
.into_iter()
.collect::<Vec<_>>();

let websocket_servers = values_t!(matches, "websocket_server", String)
let websocket_servers = matches
.get_many::<String>("websocket_server")
.unwrap_or_default()
.into_iter()
.collect::<Vec<_>>();

let servers = rpc_servers
.iter()
.zip(websocket_servers.iter())
.map(|(rpc, ws)| (rpc.clone(), ws.clone()))
.map(|(rpc, ws)| (rpc.to_string(), ws.to_string()))
.collect::<Vec<_>>();

info!("Creating the PacketBatchSender: at address: {:?} for the following initial destinations: {destinations:?}",
Expand Down

0 comments on commit 5b479b4

Please sign in to comment.