Skip to content

Commit ebccab7

Browse files
committed
f Introduce ternary enum PaymentStoreUpdateResult
1 parent 6aa4916 commit ebccab7

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

src/payment/bolt11.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::liquidity::LiquiditySource;
1616
use crate::logger::{log_error, log_info, LdkLogger, Logger};
1717
use crate::payment::store::{
1818
LSPFeeLimits, PaymentDetails, PaymentDetailsUpdate, PaymentDirection, PaymentKind,
19-
PaymentStatus, PaymentStore,
19+
PaymentStatus, PaymentStore, PaymentStoreUpdateResult,
2020
};
2121
use crate::payment::SendingParameters;
2222
use crate::peer_store::{PeerInfo, PeerStore};
@@ -394,8 +394,8 @@ impl Bolt11Payment {
394394
/// failed back, e.g., if the correct preimage can't be retrieved in time before the claim
395395
/// deadline has been reached.
396396
///
397-
/// Will check that the payment is known and pending before failing the payment, and will
398-
/// return an error otherwise.
397+
/// Will check that the payment is known before failing the payment, and will return an error
398+
/// otherwise.
399399
///
400400
/// [`receive_for_hash`]: Self::receive_for_hash
401401
/// [`receive_variable_amount_for_hash`]: Self::receive_variable_amount_for_hash
@@ -409,8 +409,9 @@ impl Bolt11Payment {
409409
};
410410

411411
match self.payment_store.update(&update) {
412-
Ok(true) => (),
413-
Ok(false) => {
412+
Ok(PaymentStoreUpdateResult::EntryUpdated)
413+
| Ok(PaymentStoreUpdateResult::EntryUnchanged) => (),
414+
Ok(PaymentStoreUpdateResult::EntryNotFound) => {
414415
log_error!(
415416
self.logger,
416417
"Failed to manually fail unknown payment with hash {}",
@@ -421,7 +422,7 @@ impl Bolt11Payment {
421422
Err(e) => {
422423
log_error!(
423424
self.logger,
424-
"Failed to manually fail unknown payment with hash {}: {}",
425+
"Failed to manually fail payment with hash {}: {}",
425426
payment_hash,
426427
e
427428
);

src/payment/store.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,12 @@ impl From<&PaymentDetails> for PaymentDetailsUpdate {
590590
}
591591
}
592592

593+
pub(crate) enum PaymentStoreUpdateResult {
594+
EntryUpdated,
595+
EntryUnchanged,
596+
EntryNotFound,
597+
}
598+
593599
pub(crate) struct PaymentStore<L: Deref>
594600
where
595601
L::Target: LdkLogger,
@@ -670,17 +676,22 @@ where
670676
self.payments.lock().unwrap().get(id).cloned()
671677
}
672678

673-
pub(crate) fn update(&self, update: &PaymentDetailsUpdate) -> Result<bool, Error> {
674-
let mut updated = false;
679+
pub(crate) fn update(
680+
&self, update: &PaymentDetailsUpdate,
681+
) -> Result<PaymentStoreUpdateResult, Error> {
675682
let mut locked_payments = self.payments.lock().unwrap();
676683

677684
if let Some(payment) = locked_payments.get_mut(&update.id) {
678-
updated = payment.update(update);
685+
let updated = payment.update(update);
679686
if updated {
680687
self.persist_info(&update.id, payment)?;
688+
Ok(PaymentStoreUpdateResult::EntryUpdated)
689+
} else {
690+
Ok(PaymentStoreUpdateResult::EntryUnchanged)
681691
}
692+
} else {
693+
Ok(PaymentStoreUpdateResult::EntryNotFound)
682694
}
683-
Ok(updated)
684695
}
685696

686697
pub(crate) fn list_filter<F: FnMut(&&PaymentDetails) -> bool>(

0 commit comments

Comments
 (0)