Skip to content

Commit

Permalink
Add function to resync hermes dms
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman committed May 8, 2024
1 parent 256876a commit 39d109c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
22 changes: 21 additions & 1 deletion mutiny-core/src/hermes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -319,6 +319,26 @@ impl<S: MutinyStorage> HermesClient<S> {
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,
Expand Down
8 changes: 8 additions & 0 deletions mutiny-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2983,6 +2983,14 @@ impl<S: MutinyStorage> MutinyWallet<S> {
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) {
Expand Down
5 changes: 5 additions & 0 deletions mutiny-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down

0 comments on commit 39d109c

Please sign in to comment.