@@ -1700,10 +1700,9 @@ where
1700
1700
///
1701
1701
/// ```
1702
1702
/// # use lightning::events::{Event, EventsProvider, PaymentPurpose};
1703
- /// # use lightning::ln::channelmanager::AChannelManager;
1704
- /// # use lightning::offers::parse::Bolt12SemanticError;
1703
+ /// # use lightning::ln::channelmanager::{AChannelManager, Bolt12CreationError};
1705
1704
/// #
1706
- /// # fn example<T: AChannelManager>(channel_manager: T) -> Result<(), Bolt12SemanticError > {
1705
+ /// # fn example<T: AChannelManager>(channel_manager: T) -> Result<(), Bolt12CreationError > {
1707
1706
/// # let channel_manager = channel_manager.get_cm();
1708
1707
/// # let absolute_expiry = None;
1709
1708
/// let offer = channel_manager
@@ -1805,13 +1804,12 @@ where
1805
1804
/// ```
1806
1805
/// # use core::time::Duration;
1807
1806
/// # use lightning::events::{Event, EventsProvider};
1808
- /// # use lightning::ln::channelmanager::{AChannelManager, PaymentId, RecentPaymentDetails, Retry};
1809
- /// # use lightning::offers::parse::Bolt12SemanticError;
1807
+ /// # use lightning::ln::channelmanager::{AChannelManager, Bolt12CreationError, PaymentId, RecentPaymentDetails, Retry};
1810
1808
/// #
1811
1809
/// # fn example<T: AChannelManager>(
1812
1810
/// # channel_manager: T, amount_msats: u64, absolute_expiry: Duration, retry: Retry,
1813
1811
/// # max_total_routing_fee_msat: Option<u64>
1814
- /// # ) -> Result<(), Bolt12SemanticError > {
1812
+ /// # ) -> Result<(), Bolt12CreationError > {
1815
1813
/// # let channel_manager = channel_manager.get_cm();
1816
1814
/// let payment_id = PaymentId([42; 32]);
1817
1815
/// let refund = channel_manager
@@ -2526,6 +2524,26 @@ pub enum RecentPaymentDetails {
2526
2524
},
2527
2525
}
2528
2526
2527
+ /// Error during creation and handling of BOLT 12 related payments.
2528
+ #[derive(Debug, Clone, PartialEq)]
2529
+ pub enum Bolt12CreationError {
2530
+ /// Error from BOLT 12 semantic checks.
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
+ /// Failed to create a blinded path.
2537
+ BlindedPathCreationFailed,
2538
+ }
2539
+
2540
+ impl From<Bolt12SemanticError> for Bolt12CreationError {
2541
+ fn from(err: Bolt12SemanticError) -> Self {
2542
+ Bolt12CreationError::InvalidSemantics(err)
2543
+ }
2544
+ }
2545
+
2546
+
2529
2547
/// Route hints used in constructing invoices for [phantom node payents].
2530
2548
///
2531
2549
/// [phantom node payments]: crate::sign::PhantomKeysManager
@@ -8801,7 +8819,7 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
8801
8819
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
8802
8820
pub fn create_offer_builder(
8803
8821
&$self, absolute_expiry: Option<Duration>
8804
- ) -> Result<$builder, Bolt12SemanticError > {
8822
+ ) -> Result<$builder, Bolt12CreationError > {
8805
8823
let node_id = $self.get_our_node_id();
8806
8824
let expanded_key = &$self.inbound_payment_key;
8807
8825
let entropy = &*$self.entropy_source;
@@ -8811,7 +8829,7 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
8811
8829
let context = OffersContext::InvoiceRequest { nonce };
8812
8830
let path = $self.create_blinded_paths_using_absolute_expiry(context, absolute_expiry)
8813
8831
.and_then(|paths| paths.into_iter().next().ok_or(()))
8814
- .map_err(|_| Bolt12SemanticError::MissingPaths )?;
8832
+ .map_err(|_| Bolt12CreationError::BlindedPathCreationFailed )?;
8815
8833
let builder = OfferBuilder::deriving_signing_pubkey(node_id, expanded_key, nonce, secp_ctx)
8816
8834
.chain_hash($self.chain_hash)
8817
8835
.path(path);
@@ -8874,7 +8892,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
8874
8892
pub fn create_refund_builder(
8875
8893
&$self, amount_msats: u64, absolute_expiry: Duration, payment_id: PaymentId,
8876
8894
retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
8877
- ) -> Result<$builder, Bolt12SemanticError > {
8895
+ ) -> Result<$builder, Bolt12CreationError > {
8878
8896
let node_id = $self.get_our_node_id();
8879
8897
let expanded_key = &$self.inbound_payment_key;
8880
8898
let entropy = &*$self.entropy_source;
@@ -8884,7 +8902,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
8884
8902
let context = OffersContext::OutboundPayment { payment_id, nonce };
8885
8903
let path = $self.create_blinded_paths_using_absolute_expiry(context, Some(absolute_expiry))
8886
8904
.and_then(|paths| paths.into_iter().next().ok_or(()))
8887
- .map_err(|_| Bolt12SemanticError::MissingPaths )?;
8905
+ .map_err(|_| Bolt12CreationError::BlindedPathCreationFailed )?;
8888
8906
8889
8907
let builder = RefundBuilder::deriving_payer_id(
8890
8908
node_id, expanded_key, nonce, secp_ctx, amount_msats, payment_id
@@ -8900,7 +8918,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
8900
8918
.add_new_awaiting_invoice(
8901
8919
payment_id, expiration, retry_strategy, max_total_routing_fee_msat,
8902
8920
)
8903
- .map_err(|_| Bolt12SemanticError ::DuplicatePaymentId)?;
8921
+ .map_err(|_| Bolt12CreationError ::DuplicatePaymentId)?;
8904
8922
8905
8923
Ok(builder.into())
8906
8924
}
@@ -8991,7 +9009,7 @@ where
8991
9009
&self, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
8992
9010
payer_note: Option<String>, payment_id: PaymentId, retry_strategy: Retry,
8993
9011
max_total_routing_fee_msat: Option<u64>
8994
- ) -> Result<(), Bolt12SemanticError > {
9012
+ ) -> Result<(), Bolt12CreationError > {
8995
9013
let expanded_key = &self.inbound_payment_key;
8996
9014
let entropy = &*self.entropy_source;
8997
9015
let secp_ctx = &self.secp_ctx;
@@ -9018,7 +9036,7 @@ where
9018
9036
9019
9037
let context = OffersContext::OutboundPayment { payment_id, nonce };
9020
9038
let reply_paths = self.create_blinded_paths(context)
9021
- .map_err(|_| Bolt12SemanticError::MissingPaths )?;
9039
+ .map_err(|_| Bolt12CreationError::BlindedPathCreationFailed )?;
9022
9040
9023
9041
let total_liquidity: u64 = self.list_usable_channels().iter().map(|channel| channel.next_outbound_htlc_limit_msat).sum();
9024
9042
let total_amount_msats = match invoice_request.amount_msats() {
@@ -9032,7 +9050,7 @@ where
9032
9050
if let Some(amount) = total_amount_msats {
9033
9051
if amount > total_liquidity {
9034
9052
log_error!(self.logger, "Insufficient liquidity for payment with payment id: {}", payment_id);
9035
- return Err(Bolt12SemanticError ::InsufficientLiquidity);
9053
+ return Err(Bolt12CreationError ::InsufficientLiquidity);
9036
9054
}
9037
9055
}
9038
9056
@@ -9043,7 +9061,7 @@ where
9043
9061
.add_new_awaiting_invoice(
9044
9062
payment_id, expiration, retry_strategy, max_total_routing_fee_msat
9045
9063
)
9046
- .map_err(|_| Bolt12SemanticError ::DuplicatePaymentId)?;
9064
+ .map_err(|_| Bolt12CreationError ::DuplicatePaymentId)?;
9047
9065
9048
9066
let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
9049
9067
if !offer.paths().is_empty() {
@@ -9070,7 +9088,7 @@ where
9070
9088
}
9071
9089
} else {
9072
9090
debug_assert!(false);
9073
- return Err(Bolt12SemanticError::MissingSigningPubkey);
9091
+ return Err(Bolt12CreationError::InvalidSemantics( Bolt12SemanticError::MissingSigningPubkey) );
9074
9092
}
9075
9093
9076
9094
Ok(())
@@ -9100,7 +9118,7 @@ where
9100
9118
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
9101
9119
pub fn request_refund_payment(
9102
9120
&self, refund: &Refund
9103
- ) -> Result<Bolt12Invoice, Bolt12SemanticError > {
9121
+ ) -> Result<Bolt12Invoice, Bolt12CreationError > {
9104
9122
let expanded_key = &self.inbound_payment_key;
9105
9123
let entropy = &*self.entropy_source;
9106
9124
let secp_ctx = &self.secp_ctx;
@@ -9109,7 +9127,7 @@ where
9109
9127
let relative_expiry = DEFAULT_RELATIVE_EXPIRY.as_secs() as u32;
9110
9128
9111
9129
if refund.chain() != self.chain_hash {
9112
- return Err(Bolt12SemanticError::UnsupportedChain);
9130
+ return Err(Bolt12CreationError::InvalidSemantics( Bolt12SemanticError::UnsupportedChain) );
9113
9131
}
9114
9132
9115
9133
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
@@ -9120,7 +9138,7 @@ where
9120
9138
let payment_paths = self.create_blinded_payment_paths(
9121
9139
amount_msats, payment_secret, payment_context
9122
9140
)
9123
- .map_err(|_| Bolt12SemanticError::MissingPaths )?;
9141
+ .map_err(|_| Bolt12CreationError::BlindedPathCreationFailed )?;
9124
9142
9125
9143
#[cfg(feature = "std")]
9126
9144
let builder = refund.respond_using_derived_keys(
@@ -9137,7 +9155,7 @@ where
9137
9155
let builder: InvoiceBuilder<DerivedSigningPubkey> = builder.into();
9138
9156
let invoice = builder.allow_mpp().build_and_sign(secp_ctx)?;
9139
9157
let reply_paths = self.create_blinded_paths(OffersContext::Unknown {})
9140
- .map_err(|_| Bolt12SemanticError::MissingPaths )?;
9158
+ .map_err(|_| Bolt12CreationError::BlindedPathCreationFailed )?;
9141
9159
9142
9160
let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
9143
9161
if refund.paths().is_empty() {
@@ -9166,7 +9184,7 @@ where
9166
9184
9167
9185
Ok(invoice)
9168
9186
},
9169
- Err(()) => Err(Bolt12SemanticError::InvalidAmount),
9187
+ Err(()) => Err(Bolt12CreationError::InvalidSemantics( Bolt12SemanticError::InvalidAmount) ),
9170
9188
}
9171
9189
}
9172
9190
0 commit comments