Skip to content

Commit

Permalink
add custom port to rooch server start
Browse files Browse the repository at this point in the history
  • Loading branch information
bytedeveloperr committed Sep 4, 2023
1 parent b155dc6 commit 4fb201b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions crates/rooch-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ pub struct RoochOpt {
// /// This option only work for node init start.
// pub genesis_config: Option<String>,
pub store: Option<StoreConfig>,

/// Optional custom port, which the rooch server should listen on.
#[serde(skip_serializing_if = "Option::is_none")]
pub port: Option<u16>,
}

impl std::fmt::Display for RoochOpt {
Expand All @@ -92,6 +96,7 @@ impl RoochOpt {
base_data_dir: None,
chain_id: Some(RoochChainID::DEV),
store: None,
port: None,
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions crates/rooch-config/src/server_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ impl ServerConfig {

format!("{}://{}:{}", schema, self.host, self.port)
}

pub fn new_with_port(port: u16) -> Self {
Self {
port,
..Default::default()
}
}
}

impl Display for ServerConfig {
Expand Down
4 changes: 3 additions & 1 deletion crates/rooch-rpc-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ pub async fn run_start_server(opt: &RoochOpt) -> Result<ServerHandle> {
// tracing_subscriber can only be inited once.
let _ = tracing_subscriber::fmt::try_init();

let config = ServerConfig::default();
let config = opt
.port
.map_or(ServerConfig::default(), |port| ServerConfig::new_with_port(port));
let chain_id = opt.chain_id.clone().unwrap_or_default().chain_id();

let addr: SocketAddr = format!("{}:{}", config.host, config.port).parse()?;
Expand Down
1 change: 1 addition & 0 deletions crates/rooch/src/commands/server/commands/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ impl CleanCommand {
base_data_dir: None,
chain_id: self.chain_id.clone(),
store: None,
port: None,
};
let base_config = BaseConfig::load_with_opt(&opt)?;
let mut store_config = StoreConfig::default();
Expand Down
4 changes: 4 additions & 0 deletions crates/rooch/src/commands/server/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ pub struct StartCommand {
// #[serde(skip_serializing_if = "Option::is_none")]
#[clap(long, short = 'n', help = R_OPT_NET_HELP)]
pub chain_id: Option<RoochChainID>,

#[clap(long, short = 'p', help = R_OPT_NET_HELP)]
pub port: Option<u16>,
}

#[async_trait]
Expand All @@ -30,6 +33,7 @@ impl CommandAction<()> for StartCommand {
base_data_dir: None,
chain_id: self.chain_id,
store: None,
port: self.port,
};
service.start(&rooch_opt).await.map_err(RoochError::from)?;

Expand Down

0 comments on commit 4fb201b

Please sign in to comment.