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 resync hermes dms #1171

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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
Loading