From 39d109c0189fffd40baef0cb4cd1f62b8e2fbb35 Mon Sep 17 00:00:00 2001 From: benthecarman Date: Wed, 8 May 2024 11:52:01 -0500 Subject: [PATCH] Add function to resync hermes dms --- mutiny-core/src/hermes.rs | 22 +++++++++++++++++++++- mutiny-core/src/lib.rs | 8 ++++++++ mutiny-wasm/src/lib.rs | 5 +++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/mutiny-core/src/hermes.rs b/mutiny-core/src/hermes.rs index 75f08c551..606cba06f 100644 --- a/mutiny-core/src/hermes.rs +++ b/mutiny-core/src/hermes.rs @@ -30,7 +30,7 @@ use crate::event::{HTLCStatus, MillisatAmount, PaymentInfo}; use crate::federation::FedimintClient; use crate::labels::LabelStorage; use crate::nostr::RELAYS; -use crate::storage::persist_payment_info; +use crate::storage::{persist_payment_info, LAST_HERMES_SYNC_TIME_KEY}; use crate::{ blindauth::{BlindAuthClient, SignedToken}, error::MutinyError, @@ -319,6 +319,26 @@ impl HermesClient { Ok(()) } + /// Resyncs the hermes client by subscribing to older DMs. + pub async fn resync(&self) -> Result<(), MutinyError> { + // reset last sync time to zero + self.storage + .set_data(LAST_HERMES_SYNC_TIME_KEY.to_string(), 0, None)?; + + let received_dm_filter = Filter::new() + .kind(Kind::EncryptedDirectMessage) + .pubkey(self.public_key) + .since(Timestamp::from(0)); + + // subscribe to older DMs to resync + self.client.connect().await; + self.client.subscribe(vec![received_dm_filter], None).await; + + // the rest should happen in the background thread that handles the events + + Ok(()) + } + pub async fn change_federation_info( &self, federation: FederationIdentity, diff --git a/mutiny-core/src/lib.rs b/mutiny-core/src/lib.rs index 102af45a0..457776057 100644 --- a/mutiny-core/src/lib.rs +++ b/mutiny-core/src/lib.rs @@ -2983,6 +2983,14 @@ impl MutinyWallet { Ok(()) } + /// Starts up the hermes client if available + pub async fn resync_hermes(&self) -> Result<(), MutinyError> { + if let Some(hermes_client) = self.hermes_client.as_ref() { + hermes_client.resync().await?; + } + Ok(()) + } + /// Checks available blind tokens /// Only needs to be ran once successfully on startup pub fn check_blind_tokens(&self) { diff --git a/mutiny-wasm/src/lib.rs b/mutiny-wasm/src/lib.rs index b0033a227..66465d757 100644 --- a/mutiny-wasm/src/lib.rs +++ b/mutiny-wasm/src/lib.rs @@ -2054,6 +2054,11 @@ impl MutinyWallet { Ok(self.inner.check_lnurl_name().await?) } + /// Resyncs the hermes client by subscribing to older DMs. + pub async fn resync_lightning_address(&self) -> Result<(), MutinyJsError> { + Ok(self.inner.resync_hermes().await?) + } + /// Resets the scorer and network graph. This can be useful if you get stuck in a bad state. #[wasm_bindgen] pub async fn reset_router(&self) -> Result<(), MutinyJsError> {