Skip to content

Commit

Permalink
fix(config): accept a string as rpcport value (#2026)
Browse files Browse the repository at this point in the history
  • Loading branch information
shamardy authored Dec 14, 2023
1 parent 52dab22 commit c66afb3
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion mm2src/mm2_core/src/mm_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,21 @@ impl MmCtx {

#[cfg(not(target_arch = "wasm32"))]
pub fn rpc_ip_port(&self) -> Result<SocketAddr, String> {
let port = self.conf["rpcport"].as_u64().unwrap_or(7783);
let port = match self.conf.get("rpcport") {
Some(rpcport) => {
// Check if it's a number or a string that can be parsed into a number
rpcport
.as_u64()
.or_else(|| rpcport.as_str().and_then(|s| s.parse::<u64>().ok()))
.ok_or_else(|| {
format!(
"Invalid `rpcport` value. Expected a positive integer, but received: {}",
rpcport
)
})?
},
None => 7783, // Default port if `rpcport` does not exist in the config
};
if port < 1000 {
return ERR!("rpcport < 1000");
}
Expand Down

0 comments on commit c66afb3

Please sign in to comment.