Skip to content

Commit

Permalink
Add function to return the current LSP
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman committed Jul 3, 2024
1 parent 960a4e8 commit 337e660
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions mutiny-core/src/nodemanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,11 @@ impl<S: MutinyStorage> NodeManager<S> {
Ok(peers)
}

pub async fn get_configured_lsp(&self) -> Result<Option<LspConfig>, MutinyError> {
let node = self.get_node_by_key_or_first(None).await?;
Ok(node.node_index().await.lsp)
}

/// Changes all the node's LSPs to the given config. If any of the nodes have an active channel with the
/// current LSP, it will fail to change the LSP.
///
Expand Down
11 changes: 10 additions & 1 deletion mutiny-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ use mutiny_core::{
labels::LabelStorage,
nodemanager::{create_lsp_config, NodeManager},
};
use mutiny_core::{logging::MutinyLogger, nostr::ProfileType};
use mutiny_core::{logging::MutinyLogger, lsp::LspConfig, nostr::ProfileType};
use nostr::prelude::Method;
use nostr::{Keys, ToBech32};
use std::collections::HashMap;
Expand Down Expand Up @@ -763,6 +763,15 @@ impl MutinyWallet {
Ok(())
}

/// Returns the current LSP config
pub async fn get_configured_lsp(&self) -> Result<JsValue, MutinyJsError> {
match self.inner.node_manager.get_configured_lsp().await? {
Some(LspConfig::VoltageFlow(config)) => Ok(JsValue::from_serde(&config)?),
Some(LspConfig::Lsps(config)) => Ok(JsValue::from_serde(&config)?),
None => Ok(JsValue::NULL),
}
}

/// Attempts to connect to a peer from the selected node.
#[wasm_bindgen]
pub async fn connect_to_peer(
Expand Down

0 comments on commit 337e660

Please sign in to comment.