From 960a4e82ee25ca51a80bf159befe893f612543b5 Mon Sep 17 00:00:00 2001 From: benthecarman Date: Wed, 3 Jul 2024 11:41:46 -0500 Subject: [PATCH 1/2] Make lsp module pub --- mutiny-core/src/lib.rs | 2 +- mutiny-core/src/lsp/voltage.rs | 2 +- mutiny-core/src/scorer.rs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mutiny-core/src/lib.rs b/mutiny-core/src/lib.rs index 43a668bc7..281996c72 100644 --- a/mutiny-core/src/lib.rs +++ b/mutiny-core/src/lib.rs @@ -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; diff --git a/mutiny-core/src/lsp/voltage.rs b/mutiny-core/src/lsp/voltage.rs index 92c8c3408..6a34cde18 100644 --- a/mutiny-core/src/lsp/voltage.rs +++ b/mutiny-core/src/lsp/voltage.rs @@ -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, diff --git a/mutiny-core/src/scorer.rs b/mutiny-core/src/scorer.rs index 84e9d97c5..eba1fff21 100644 --- a/mutiny-core/src/scorer.rs +++ b/mutiny-core/src/scorer.rs @@ -277,9 +277,9 @@ fn build_preferred_hubs_set() -> HashSet { .collect() } -pub(crate) type ProbScorer = ProbabilisticScorer, Arc>; +pub type ProbScorer = ProbabilisticScorer, Arc>; -pub(crate) struct HubPreferentialScorer { +pub struct HubPreferentialScorer { inner: ProbScorer, preferred_hubs_set: HashSet, } From 337e660dd2be41c90f2d6f3f7ad9943c85d4f4f8 Mon Sep 17 00:00:00 2001 From: benthecarman Date: Wed, 3 Jul 2024 11:45:57 -0500 Subject: [PATCH 2/2] Add function to return the current LSP --- mutiny-core/src/nodemanager.rs | 5 +++++ mutiny-wasm/src/lib.rs | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/mutiny-core/src/nodemanager.rs b/mutiny-core/src/nodemanager.rs index 43b0e2699..e7039c10d 100644 --- a/mutiny-core/src/nodemanager.rs +++ b/mutiny-core/src/nodemanager.rs @@ -1344,6 +1344,11 @@ impl NodeManager { Ok(peers) } + pub async fn get_configured_lsp(&self) -> Result, 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. /// diff --git a/mutiny-wasm/src/lib.rs b/mutiny-wasm/src/lib.rs index 47197caef..8d22c263a 100644 --- a/mutiny-wasm/src/lib.rs +++ b/mutiny-wasm/src/lib.rs @@ -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; @@ -763,6 +763,15 @@ impl MutinyWallet { Ok(()) } + /// Returns the current LSP config + pub async fn get_configured_lsp(&self) -> Result { + 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(