@@ -1804,12 +1804,12 @@ where
1804
1804
/// ```
1805
1805
/// # use core::time::Duration;
1806
1806
/// # use lightning::events::{Event, EventsProvider};
1807
- /// # use lightning::ln::channelmanager::{AChannelManager, Bolt12CreationError , PaymentId, RecentPaymentDetails, Retry};
1807
+ /// # use lightning::ln::channelmanager::{AChannelManager, Bolt12RequestError , PaymentId, RecentPaymentDetails, Retry};
1808
1808
/// #
1809
1809
/// # fn example<T: AChannelManager>(
1810
1810
/// # channel_manager: T, amount_msats: u64, absolute_expiry: Duration, retry: Retry,
1811
1811
/// # max_total_routing_fee_msat: Option<u64>
1812
- /// # ) -> Result<(), Bolt12CreationError > {
1812
+ /// # ) -> Result<(), Bolt12RequestError > {
1813
1813
/// # let channel_manager = channel_manager.get_cm();
1814
1814
/// let payment_id = PaymentId([42; 32]);
1815
1815
/// let refund = channel_manager
@@ -2529,10 +2529,6 @@ pub enum RecentPaymentDetails {
2529
2529
pub enum Bolt12CreationError {
2530
2530
/// Error from BOLT 12 semantic checks.
2531
2531
InvalidSemantics(Bolt12SemanticError),
2532
- /// The payment id for a refund or request is already in use.
2533
- DuplicatePaymentId,
2534
- /// There is insufficient liquidity to complete the payment.
2535
- InsufficientLiquidity,
2536
2532
/// Failed to create a blinded path.
2537
2533
BlindedPathCreationFailed,
2538
2534
}
@@ -2543,6 +2539,34 @@ impl From<Bolt12SemanticError> for Bolt12CreationError {
2543
2539
}
2544
2540
}
2545
2541
2542
+ /// Error during requesting a BOLT 12 related payment.
2543
+ #[derive(Debug, Clone, PartialEq)]
2544
+ pub enum Bolt12RequestError {
2545
+ /// Error from BOLT 12 semantic checks.
2546
+ InvalidSemantics(Bolt12SemanticError),
2547
+ /// The payment id for a refund or request is already in use.
2548
+ DuplicatePaymentId,
2549
+ /// There is insufficient liquidity to complete the payment.
2550
+ InsufficientLiquidity,
2551
+ /// Failed to create a blinded path.
2552
+ BlindedPathCreationFailed,
2553
+
2554
+ }
2555
+
2556
+ impl From<Bolt12SemanticError> for Bolt12RequestError {
2557
+ fn from(err: Bolt12SemanticError) -> Self {
2558
+ Bolt12RequestError::InvalidSemantics(err)
2559
+ }
2560
+ }
2561
+
2562
+ impl From<Bolt12CreationError> for Bolt12RequestError {
2563
+ fn from(err: Bolt12CreationError) -> Self {
2564
+ match err {
2565
+ Bolt12CreationError::InvalidSemantics(semantic_err) => Bolt12RequestError::InvalidSemantics(semantic_err),
2566
+ Bolt12CreationError::BlindedPathCreationFailed => Bolt12RequestError::BlindedPathCreationFailed,
2567
+ }
2568
+ }
2569
+ }
2546
2570
2547
2571
/// Route hints used in constructing invoices for [phantom node payents].
2548
2572
///
@@ -8897,7 +8921,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
8897
8921
pub fn create_refund_builder(
8898
8922
&$self, amount_msats: u64, absolute_expiry: Duration, payment_id: PaymentId,
8899
8923
retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
8900
- ) -> Result<$builder, Bolt12CreationError > {
8924
+ ) -> Result<$builder, Bolt12RequestError > {
8901
8925
let node_id = $self.get_our_node_id();
8902
8926
let expanded_key = &$self.inbound_payment_key;
8903
8927
let entropy = &*$self.entropy_source;
@@ -8907,12 +8931,12 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
8907
8931
let context = OffersContext::OutboundPayment { payment_id, nonce };
8908
8932
let path = $self.create_blinded_paths_using_absolute_expiry(context, Some(absolute_expiry))
8909
8933
.and_then(|paths| paths.into_iter().next().ok_or(()))
8910
- .map_err(|_| Bolt12CreationError ::BlindedPathCreationFailed)?;
8934
+ .map_err(|_| Bolt12RequestError ::BlindedPathCreationFailed)?;
8911
8935
8912
8936
let total_liquidity: u64 = $self.list_channels().iter().filter(|channel| channel.is_usable).map(|channel| channel.next_outbound_htlc_limit_msat).sum();
8913
8937
if amount_msats > total_liquidity {
8914
8938
log_error!($self.logger, "Insufficient liquidity for payment with payment id: {}", payment_id);
8915
- return Err(Bolt12CreationError ::InsufficientLiquidity);
8939
+ return Err(Bolt12RequestError ::InsufficientLiquidity);
8916
8940
}
8917
8941
8918
8942
let builder = RefundBuilder::deriving_payer_id(
@@ -8929,7 +8953,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
8929
8953
.add_new_awaiting_invoice(
8930
8954
payment_id, expiration, retry_strategy, max_total_routing_fee_msat,
8931
8955
)
8932
- .map_err(|_| Bolt12CreationError ::DuplicatePaymentId)?;
8956
+ .map_err(|_| Bolt12RequestError ::DuplicatePaymentId)?;
8933
8957
8934
8958
Ok(builder.into())
8935
8959
}
@@ -9020,7 +9044,7 @@ where
9020
9044
&self, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
9021
9045
payer_note: Option<String>, payment_id: PaymentId, retry_strategy: Retry,
9022
9046
max_total_routing_fee_msat: Option<u64>
9023
- ) -> Result<(), Bolt12CreationError > {
9047
+ ) -> Result<(), Bolt12RequestError > {
9024
9048
let expanded_key = &self.inbound_payment_key;
9025
9049
let entropy = &*self.entropy_source;
9026
9050
let secp_ctx = &self.secp_ctx;
@@ -9061,7 +9085,7 @@ where
9061
9085
if let Some(amount) = total_amount_msats {
9062
9086
if amount > total_liquidity {
9063
9087
log_error!(self.logger, "Insufficient liquidity for payment with payment id: {}", payment_id);
9064
- return Err(Bolt12CreationError ::InsufficientLiquidity);
9088
+ return Err(Bolt12RequestError ::InsufficientLiquidity);
9065
9089
}
9066
9090
}
9067
9091
@@ -9072,7 +9096,7 @@ where
9072
9096
.add_new_awaiting_invoice(
9073
9097
payment_id, expiration, retry_strategy, max_total_routing_fee_msat
9074
9098
)
9075
- .map_err(|_| Bolt12CreationError ::DuplicatePaymentId)?;
9099
+ .map_err(|_| Bolt12RequestError ::DuplicatePaymentId)?;
9076
9100
9077
9101
let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
9078
9102
if !offer.paths().is_empty() {
@@ -9099,7 +9123,7 @@ where
9099
9123
}
9100
9124
} else {
9101
9125
debug_assert!(false);
9102
- return Err(Bolt12CreationError ::InvalidSemantics(Bolt12SemanticError::MissingSigningPubkey));
9126
+ return Err(Bolt12RequestError ::InvalidSemantics(Bolt12SemanticError::MissingSigningPubkey));
9103
9127
}
9104
9128
9105
9129
Ok(())
0 commit comments