Skip to content

Commit

Permalink
Merge pull request #344 from breez/ok300-fix-connect-lsp
Browse files Browse the repository at this point in the history
`connect_lsp`: Only connect to known LSPs from `list_lsps`
  • Loading branch information
ok300 authored Jul 24, 2023
2 parents c500ec1 + ca08b22 commit a30195c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
1 change: 0 additions & 1 deletion libs/sdk-bindings/src/uniffi_binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ impl BlockingBreezServices {

pub fn connect_lsp(&self, lsp_id: String) -> SdkResult<()> {
rt().block_on(self.breez_services.connect_lsp(lsp_id))
.map_err(|e| e.into())
}

/// Convenience method to look up LSP info based on current LSP ID
Expand Down
1 change: 1 addition & 0 deletions libs/sdk-core/src/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ pub fn list_lsps() -> Result<Vec<LspInformation>> {
/// See [BreezServices::connect_lsp]
pub fn connect_lsp(lsp_id: String) -> Result<()> {
block_on(async { get_breez_services()?.connect_lsp(lsp_id).await })
.map_err(anyhow::Error::new::<SdkError>)
}

/// See [BreezServices::fetch_lsp_info]
Expand Down
15 changes: 11 additions & 4 deletions libs/sdk-core/src/breez_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,17 @@ impl BreezServices {
}

/// Select the LSP to be used and provide inbound liquidity
pub async fn connect_lsp(&self, lsp_id: String) -> Result<()> {
self.persister.set_lsp_id(lsp_id)?;
self.sync().await?;
Ok(())
pub async fn connect_lsp(&self, lsp_id: String) -> SdkResult<()> {
match self.list_lsps().await?.iter().any(|lsp| lsp.id == lsp_id) {
true => {
self.persister.set_lsp_id(lsp_id)?;
self.sync().await?;
Ok(())
}
false => Err(SdkError::LspConnectFailed {
err: format!("Unknown LSP: {lsp_id}"),
}),
}
}

/// Get the current LSP's ID
Expand Down

0 comments on commit a30195c

Please sign in to comment.