Skip to content
This repository has been archived by the owner on Feb 3, 2025. It is now read-only.

Commit

Permalink
Hook in blindauth/hermes init and core functions
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyGiorgio committed Mar 21, 2024
1 parent 210623b commit 27e1532
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mutiny-core/src/blindauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ impl<S: MutinyStorage> BlindAuthClient<S> {
.collect::<Vec<SignedToken>>()
}

pub async fn used_token(&self, token: SignedToken) -> Result<(), MutinyError> {
pub async fn used_token(&self, token: &SignedToken) -> Result<(), MutinyError> {
// once a token has sufficiently been used, mark it as spent and save it back
let mut token_storage_guard = self.token_storage.write().await;

Expand Down
9 changes: 8 additions & 1 deletion mutiny-core/src/hermes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ impl<S: MutinyStorage> HermesClient<S> {
})
}

/// Starts the hermes background checker
/// This should only error if there's an initial unrecoverable error
/// Otherwise it will loop in the background until a stop signal
pub fn start(&self) -> Result<(), MutinyError> {
let logger = self.logger.clone();
let stop = self.stop.clone();
Expand Down Expand Up @@ -229,11 +232,15 @@ impl<S: MutinyStorage> HermesClient<S> {
sig: unblinded_sig,
};
register_name(&self.http_client.clone(), &self.base_url, req).await?;
// TODO store the fact that this succeeded

// Mark the token as spent successfully
self.blind_auth.used_token(available_paid_token).await?;

Ok(())
}

pub async fn get_first_federation(&self) -> Option<FederationIdentity> {
async fn get_first_federation(&self) -> Option<FederationIdentity> {
let federations = self.federations.read().await;
match federations.iter().next() {
Some((_, n)) => Some(n.get_mutiny_federation_identity().await),
Expand Down
58 changes: 58 additions & 0 deletions mutiny-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,12 @@ impl<S: MutinyStorage> MutinyWalletBuilder<S> {
// start the federation background processor
mw.start_fedimint_background_checker().await;

// start the blind auth fetching process
mw.check_blind_tokens();

// start the hermes background process
mw.start_hermes()?;

log_info!(
mw.logger,
"Final setup took {}ms",
Expand Down Expand Up @@ -2449,6 +2455,58 @@ impl<S: MutinyStorage> MutinyWallet<S> {
}
Ok(invoices)
}

pub async fn check_available_lnurl_name(&self, name: String) -> Result<bool, MutinyError> {
if let Some(hermes_client) = self.hermes_client.clone() {
Ok(hermes_client.check_available_name(name).await?)
} else {
Err(MutinyError::NotFound)
}
}

pub async fn reserve_lnurl_name(&self, name: String) -> Result<(), MutinyError> {
if let Some(hermes_client) = self.hermes_client.clone() {
Ok(hermes_client.reserve_name(name).await?)
} else {
Err(MutinyError::NotFound)
}
}

/// Starts up the hermes client if available
pub fn start_hermes(&self) -> Result<(), MutinyError> {
if let Some(hermes_client) = self.hermes_client.clone() {
hermes_client.start()?
}
Ok(())
}

/// Checks available blind tokens
/// Only needs to be ran once successfully on startup
pub fn check_blind_tokens(&self) {
if let Some(blind_auth_client) = self.blind_auth_client.clone() {
let logger = self.logger.clone();
let stop = self.stop.clone();
utils::spawn(async move {
loop {
if stop.load(Ordering::Relaxed) {
break;
};

match blind_auth_client.redeem_available_tokens().await {
Ok(_) => {
log_debug!(logger, "checked available tokens");
break;
}
Err(e) => {
log_error!(logger, "error checking redeeming available tokens: {e}")
}
}

sleep(10_000).await;
}
});
}
}
}

impl<S: MutinyStorage> InvoiceHandler for MutinyWallet<S> {
Expand Down

0 comments on commit 27e1532

Please sign in to comment.