Skip to content

Commit

Permalink
Make sure LSP url is a valid url when switching
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman committed Jun 11, 2024
1 parent 10bbc27 commit 7f1a4fa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
6 changes: 3 additions & 3 deletions mutiny-core/src/lsp/voltage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl LspClient {
url: &str,
logger: &MutinyLogger,
) -> Result<(PublicKey, String), MutinyError> {
let builder = http_client.get(format!("{}{}", url, GET_INFO_PATH));
let builder = http_client.get(format!("{}{}", url.trim(), GET_INFO_PATH));
let request = add_x_auth_token_if_needed(url, builder)?;

let response: reqwest::Response = utils::fetch_with_timeout(http_client, request)
Expand Down Expand Up @@ -296,7 +296,7 @@ impl Lsp for LspClient {

let builder = self
.http_client
.post(format!("{}{}", &self.url, PROPOSAL_PATH))
.post(format!("{}{}", &self.url.trim(), PROPOSAL_PATH))
.json(&payload);

let request = add_x_auth_token_if_needed(&self.url, builder)?;
Expand Down Expand Up @@ -353,7 +353,7 @@ impl Lsp for LspClient {
async fn get_lsp_fee_msat(&self, fee_request: FeeRequest) -> Result<FeeResponse, MutinyError> {
let builder = self
.http_client
.post(format!("{}{}", &self.url, FEE_PATH))
.post(format!("{}{}", &self.url.trim(), FEE_PATH))
.json(&fee_request);

let request = add_x_auth_token_if_needed(&self.url, builder)?;
Expand Down
21 changes: 18 additions & 3 deletions mutiny-core/src/nodemanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
#[cfg(not(target_arch = "wasm32"))]
use std::time::Instant;
use std::{collections::HashMap, ops::Deref, sync::Arc};
use url::Url;
#[cfg(target_arch = "wasm32")]
use web_time::Instant;

Expand Down Expand Up @@ -347,7 +348,15 @@ impl<S: MutinyStorage> NodeManagerBuilder<S> {
let lsp_config = if c.safe_mode {
None
} else {
create_lsp_config(c.lsp_url, c.lsp_connection_string, c.lsp_token)?
create_lsp_config(c.lsp_url, c.lsp_connection_string, c.lsp_token).unwrap_or_else(
|_| {
log_warn!(
logger,
"Failed to create lsp config, falling back to no LSP configured"
);
None
},
)
};
log_trace!(logger, "finished creating lsp config");

Expand Down Expand Up @@ -2036,8 +2045,14 @@ pub fn create_lsp_config(
) -> Result<Option<LspConfig>, MutinyError> {
match (lsp_url.clone(), lsp_connection_string.clone()) {
(Some(lsp_url), None) => {
if !lsp_url.is_empty() {
Ok(Some(LspConfig::new_voltage_flow(lsp_url)))
let trimmed = lsp_url.trim().to_string();
if !trimmed.is_empty() {
// make sure url is valid
if Url::parse(&trimmed).is_err() {
return Err(MutinyError::InvalidArgumentsError);
}

Ok(Some(LspConfig::new_voltage_flow(trimmed)))
} else {
Ok(None)
}
Expand Down

0 comments on commit 7f1a4fa

Please sign in to comment.