From 337e660dd2be41c90f2d6f3f7ad9943c85d4f4f8 Mon Sep 17 00:00:00 2001 From: benthecarman Date: Wed, 3 Jul 2024 11:45:57 -0500 Subject: [PATCH] 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(