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

Only disable zaps if no federations left #1205

Merged
merged 1 commit into from
Jun 6, 2024
Merged
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
2 changes: 1 addition & 1 deletion mutiny-core/src/federation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ pub trait FedimintClient {
pub(crate) struct FederationClient<S: MutinyStorage> {
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<S>,
Expand Down
15 changes: 6 additions & 9 deletions mutiny-core/src/hermes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -193,7 +194,7 @@ impl<S: MutinyStorage> HermesClient<S> {
&base_url_check_clone,
nostr_client_check_clone,
current_address_check_clone,
f,
&f.invite_code,
&logger_check_clone,
)
.await
Expand Down Expand Up @@ -321,14 +322,14 @@ impl<S: MutinyStorage> HermesClient<S> {

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
Expand Down Expand Up @@ -434,7 +435,7 @@ async fn change_federation_info(
base_url: &str,
nostr_client: Client,
current_address: Arc<RwLock<(Option<String>, bool)>>,
federation: FederationIdentity,
invite_code: &InviteCode,
logger: &MutinyLogger,
) -> Result<(), MutinyError> {
// make sure name is registered already
Expand All @@ -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
Expand Down
22 changes: 16 additions & 6 deletions mutiny-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2836,12 +2836,22 @@ impl<S: MutinyStorage> MutinyWallet<S> {
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}")
}
}
}
}
Expand Down Expand Up @@ -3547,7 +3557,7 @@ pub(crate) async fn create_new_federation<S: MutinyStorage>(
// 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(_) => (),
Expand Down
Loading