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 f6a8bf7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 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
11 changes: 9 additions & 2 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 @@ -2036,8 +2037,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 f6a8bf7

Please sign in to comment.