diff --git a/mutiny-core/src/federation.rs b/mutiny-core/src/federation.rs index b52a2687a..527041e8e 100644 --- a/mutiny-core/src/federation.rs +++ b/mutiny-core/src/federation.rs @@ -603,13 +603,12 @@ impl FederationClient { fn maybe_update_after_checking_fedimint( &self, updated_invoice: MutinyInvoice, - ) -> Result<(), MutinyError> { + ) -> Result { maybe_update_after_checking_fedimint( updated_invoice, self.logger.clone(), self.storage.clone(), - )?; - Ok(()) + ) } pub(crate) async fn pay_invoice( @@ -679,7 +678,7 @@ impl FederationClient { }; inv.fees_paid = Some(sats_round_up(&outgoing_payment.fee)); - self.maybe_update_after_checking_fedimint(inv.clone())?; + inv = self.maybe_update_after_checking_fedimint(inv)?; match inv.status { HTLCStatus::Succeeded => Ok(inv), @@ -1081,23 +1080,28 @@ fn subscribe_operation_ext( } fn maybe_update_after_checking_fedimint( - updated_invoice: MutinyInvoice, + mut updated_invoice: MutinyInvoice, logger: Arc, storage: S, -) -> Result<(), MutinyError> { +) -> Result { match updated_invoice.status { HTLCStatus::Succeeded | HTLCStatus::Failed => { - log_debug!(logger, "Saving updated payment"); let hash = updated_invoice.payment_hash.into_32(); let inbound = updated_invoice.inbound; - let mut payment_info = PaymentInfo::from(updated_invoice); - payment_info.last_update = now().as_secs(); + updated_invoice.last_updated = now().as_secs(); + let payment_info = PaymentInfo::from(updated_invoice.clone()); + log_debug!( + logger, + "Saving updated payment: {} {}", + hash.to_lower_hex_string(), + payment_info.last_update + ); persist_payment_info(&storage, &hash, &payment_info, inbound)?; } HTLCStatus::Pending | HTLCStatus::InFlight => (), } - Ok(()) + Ok(updated_invoice) } impl FedimintClient for FederationClient { diff --git a/mutiny-core/src/lib.rs b/mutiny-core/src/lib.rs index 84521a994..b87684ded 100644 --- a/mutiny-core/src/lib.rs +++ b/mutiny-core/src/lib.rs @@ -3132,15 +3132,18 @@ impl MutinyWallet { } let mut inv = self.pay_invoice(&invoice, None, labels).await?; - // save privacy level to storage - inv.privacy_level = privacy_level; - persist_payment_info( - &self.storage, - &inv.payment_hash.into_32(), - &inv.clone().into(), - false, - )?; - + // save privacy level to storage, can skip if its the default privacy level + if privacy_level != PrivacyLevel::default() { + inv.privacy_level = privacy_level; + let hash = inv.payment_hash.into_32(); + log_debug!( + self.logger, + "Saving updated payment: {} {}", + hash.to_lower_hex_string(), + inv.last_updated + ); + persist_payment_info(&self.storage, &hash, &inv.clone().into(), false)?; + } Ok(inv) } else { log_error!(self.logger, "LNURL return invoice with incorrect amount");