diff --git a/mutiny-core/src/federation.rs b/mutiny-core/src/federation.rs index 7198c52a5..1793df2b2 100644 --- a/mutiny-core/src/federation.rs +++ b/mutiny-core/src/federation.rs @@ -529,13 +529,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( @@ -605,7 +604,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), @@ -798,23 +797,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 102af45a0..02e5b409b 100644 --- a/mutiny-core/src/lib.rs +++ b/mutiny-core/src/lib.rs @@ -2816,15 +2816,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 privacy level is NotAvailable as that is the default + if privacy_level != PrivacyLevel::NotAvailable { + 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");