From faa310767ece5a50332e8cd07c8986eab2bb690b Mon Sep 17 00:00:00 2001 From: benthecarman Date: Thu, 6 Jun 2024 16:01:01 -0500 Subject: [PATCH] Only disable zaps if no federations left --- mutiny-core/src/federation.rs | 2 +- mutiny-core/src/hermes.rs | 15 ++++++--------- mutiny-core/src/lib.rs | 22 ++++++++++++++++------ 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/mutiny-core/src/federation.rs b/mutiny-core/src/federation.rs index 2c91ef826..2de6f569d 100644 --- a/mutiny-core/src/federation.rs +++ b/mutiny-core/src/federation.rs @@ -241,7 +241,7 @@ pub trait FedimintClient { pub(crate) struct FederationClient { pub(crate) uuid: String, pub(crate) fedimint_client: ClientHandleArc, - invite_code: InviteCode, + pub(crate) invite_code: InviteCode, storage: S, #[allow(dead_code)] fedimint_storage: FedimintStorage, diff --git a/mutiny-core/src/hermes.rs b/mutiny-core/src/hermes.rs index 75f08c551..2a03c9c54 100644 --- a/mutiny-core/src/hermes.rs +++ b/mutiny-core/src/hermes.rs @@ -11,6 +11,7 @@ use bitcoin::hashes::hex::FromHex; use bitcoin::key::Parity; use bitcoin::secp256k1::ThirtyTwoByteHash; use bitcoin::{bip32::ExtendedPrivKey, secp256k1::Secp256k1}; +use fedimint_core::api::InviteCode; use fedimint_core::config::FederationId; use futures::{pin_mut, select, FutureExt}; use lightning::util::logger::Logger; @@ -193,7 +194,7 @@ impl HermesClient { &base_url_check_clone, nostr_client_check_clone, current_address_check_clone, - f, + &f.invite_code, &logger_check_clone, ) .await @@ -321,14 +322,14 @@ impl HermesClient { pub async fn change_federation_info( &self, - federation: FederationIdentity, + invite_code: &InviteCode, ) -> Result<(), MutinyError> { change_federation_info( &self.http_client, &self.base_url, self.client.clone(), self.current_address.clone(), - federation, + invite_code, &self.logger, ) .await @@ -434,7 +435,7 @@ async fn change_federation_info( base_url: &str, nostr_client: Client, current_address: Arc, bool)>>, - federation: FederationIdentity, + invite_code: &InviteCode, logger: &MutinyLogger, ) -> Result<(), MutinyError> { // make sure name is registered already @@ -444,11 +445,7 @@ async fn change_federation_info( // create nostr event let signer = nostr_client.signer().await?; - let event_builder = EventBuilder::new( - NEW_FEDERATION_EVENT_KIND, - federation.invite_code.to_string(), - [], - ); + let event_builder = EventBuilder::new(NEW_FEDERATION_EVENT_KIND, invite_code.to_string(), []); let event = signer.sign_event_builder(event_builder).await?; // send request diff --git a/mutiny-core/src/lib.rs b/mutiny-core/src/lib.rs index dcd8e0de2..58da86cc9 100644 --- a/mutiny-core/src/lib.rs +++ b/mutiny-core/src/lib.rs @@ -2836,12 +2836,22 @@ impl MutinyWallet { return Err(MutinyError::NotFound); } - // remove the federation from hermes + // update hermes to change the federation if let Some(h) = self.hermes_client.as_ref() { - match h.disable_zaps().await { - Ok(_) => (), - Err(e) => { - log_error!(self.logger, "could not disable hermes zaps: {e}") + match federations_guard.values().next() { + None => { + log_debug!(self.logger, "No federations left, disabling hermes zaps"); + match h.disable_zaps().await { + Ok(_) => (), + Err(e) => { + log_error!(self.logger, "could not disable hermes zaps: {e}") + } + } + } + Some(f) => { + if let Err(e) = h.change_federation_info(&f.invite_code).await { + log_error!(self.logger, "could not change hermes federation: {e}") + } } } } @@ -3547,7 +3557,7 @@ pub(crate) async fn create_new_federation( // change the federation with hermes, if available if let Some(h) = hermes_client { match h - .change_federation_info(new_federation_identity.clone()) + .change_federation_info(&new_federation_identity.invite_code) .await { Ok(_) => (),