Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to return the current LSP #1234

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mutiny-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub mod labels;
mod ldkstorage;
pub mod lnurlauth;
pub mod logging;
mod lsp;
pub mod lsp;
mod messagehandler;
mod networking;
mod node;
Expand Down
2 changes: 1 addition & 1 deletion mutiny-core/src/lsp/voltage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl<'de> Deserialize<'de> for VoltageConfig {
}

#[derive(Clone)]
pub(crate) struct LspClient {
pub struct LspClient {
pub pubkey: PublicKey,
pub connection_string: String,
pub url: String,
Expand Down
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
4 changes: 2 additions & 2 deletions mutiny-core/src/scorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,9 @@ fn build_preferred_hubs_set() -> HashSet<NodeId> {
.collect()
}

pub(crate) type ProbScorer = ProbabilisticScorer<Arc<NetworkGraph>, Arc<MutinyLogger>>;
pub type ProbScorer = ProbabilisticScorer<Arc<NetworkGraph>, Arc<MutinyLogger>>;

pub(crate) struct HubPreferentialScorer {
pub struct HubPreferentialScorer {
inner: ProbScorer,
preferred_hubs_set: HashSet<NodeId>,
}
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
Loading