Skip to content

Commit

Permalink
Update http_urls
Browse files Browse the repository at this point in the history
Signed-off-by: Danil <deniallugo@gmail.com>
  • Loading branch information
Deniallugo committed Jun 20, 2024
1 parent 8b7ed53 commit 14c7a64
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
21 changes: 20 additions & 1 deletion zk_toolbox/crates/config/src/general.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::path::PathBuf;

use serde::{Deserialize, Serialize};
use url::Url;

use crate::{consts::GENERAL_FILE, traits::FileConfigWithDefaultName};

Expand Down Expand Up @@ -35,13 +36,31 @@ impl GeneralConfig {
}
}

pub fn update_ports(&mut self, ports_config: &PortsConfig) {
pub fn update_ports(&mut self, ports_config: &PortsConfig) -> anyhow::Result<()> {
self.api.web3_json_rpc.http_port = ports_config.web3_json_rpc_http_port;
update_port_in_url(
&mut self.api.web3_json_rpc.http_url,
ports_config.web3_json_rpc_http_port,
)?;
self.api.web3_json_rpc.ws_port = ports_config.web3_json_rpc_ws_port;
update_port_in_url(
&mut self.api.web3_json_rpc.ws_url,
ports_config.web3_json_rpc_ws_port,
)?;
self.api.healthcheck.port = ports_config.healthcheck_port;
self.api.merkle_tree.port = ports_config.merkle_tree_port;
self.api.prometheus.listener_port = ports_config.prometheus_listener_port;
Ok(())
}
}

fn update_port_in_url(http_url: &mut String, port: u16) -> anyhow::Result<()> {
let mut http_url_url = Url::parse(&http_url)?;
if let Err(()) = http_url_url.set_port(Some(port)) {
anyhow::bail!("Wrong url, setting port is impossible");
}
*http_url = http_url_url.as_str().to_string();
Ok(())
}

impl FileConfigWithDefaultName for GeneralConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn prepare_configs(
main_node_rate_limit_rps: None,
};
let mut general_en = general.clone();
general_en.update_ports(&general.ports_config().next_empty_ports_config());
general_en.update_ports(&general.ports_config().next_empty_ports_config())?;
let secrets = SecretsConfig {
database: DatabaseSecrets {
server_url: args.db.full_url(),
Expand Down
2 changes: 1 addition & 1 deletion zk_toolbox/crates/zk_inception/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use xshell::Shell;

use crate::commands::{
args::RunServerArgs, chain::ChainCommands, ecosystem::EcosystemCommands,
external_node::ExternalNodeCommands,
external_node::ExternalNodeCommands, prover::ProverCommands,
};

pub mod accept_ownership;
Expand Down

0 comments on commit 14c7a64

Please sign in to comment.