@@ -1844,10 +1844,9 @@ where
18441844///
18451845/// ```
18461846/// # use lightning::events::{Event, EventsProvider, PaymentPurpose};
1847- /// # use lightning::ln::channelmanager::AChannelManager;
1848- /// # use lightning::offers::parse::Bolt12SemanticError;
1847+ /// # use lightning::ln::channelmanager::{AChannelManager, Bolt12CreationError};
18491848/// #
1850- /// # fn example<T: AChannelManager>(channel_manager: T) -> Result<(), Bolt12SemanticError > {
1849+ /// # fn example<T: AChannelManager>(channel_manager: T) -> Result<(), Bolt12CreationError > {
18511850/// # let channel_manager = channel_manager.get_cm();
18521851/// # let absolute_expiry = None;
18531852/// let offer = channel_manager
@@ -1947,13 +1946,12 @@ where
19471946/// ```
19481947/// # use core::time::Duration;
19491948/// # use lightning::events::{Event, EventsProvider};
1950- /// # use lightning::ln::channelmanager::{AChannelManager, PaymentId, RecentPaymentDetails, Retry};
1951- /// # use lightning::offers::parse::Bolt12SemanticError;
1949+ /// # use lightning::ln::channelmanager::{AChannelManager, Bolt12CreationError, PaymentId, RecentPaymentDetails, Retry};
19521950/// #
19531951/// # fn example<T: AChannelManager>(
19541952/// # channel_manager: T, amount_msats: u64, absolute_expiry: Duration, retry: Retry,
19551953/// # max_total_routing_fee_msat: Option<u64>
1956- /// # ) -> Result<(), Bolt12SemanticError > {
1954+ /// # ) -> Result<(), Bolt12CreationError > {
19571955/// # let channel_manager = channel_manager.get_cm();
19581956/// let payment_id = PaymentId([42; 32]);
19591957/// let refund = channel_manager
@@ -2685,6 +2683,26 @@ pub enum RecentPaymentDetails {
26852683 },
26862684}
26872685
2686+ /// Error during creation and handling of BOLT 12 related payments.
2687+ #[derive(Debug, Clone, PartialEq)]
2688+ pub enum Bolt12CreationError {
2689+ /// Error from BOLT 12 semantic checks.
2690+ InvalidSemantics(Bolt12SemanticError),
2691+ /// The payment id for a refund or request is already in use.
2692+ DuplicatePaymentId,
2693+ /// There is insufficient liquidity to complete the payment.
2694+ InsufficientLiquidity,
2695+ /// Failed to create a blinded path.
2696+ BlindedPathCreationFailed,
2697+ }
2698+
2699+ impl From<Bolt12SemanticError> for Bolt12CreationError {
2700+ fn from(err: Bolt12SemanticError) -> Self {
2701+ Bolt12CreationError::InvalidSemantics(err)
2702+ }
2703+ }
2704+
2705+
26882706/// Route hints used in constructing invoices for [phantom node payents].
26892707///
26902708/// [phantom node payments]: crate::sign::PhantomKeysManager
@@ -9114,7 +9132,7 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
91149132 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
91159133 pub fn create_offer_builder(
91169134 &$self, absolute_expiry: Option<Duration>
9117- ) -> Result<$builder, Bolt12SemanticError > {
9135+ ) -> Result<$builder, Bolt12CreationError > {
91189136 let node_id = $self.get_our_node_id();
91199137 let expanded_key = &$self.inbound_payment_key;
91209138 let entropy = &*$self.entropy_source;
@@ -9124,7 +9142,7 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
91249142 let context = OffersContext::InvoiceRequest { nonce };
91259143 let path = $self.create_blinded_paths_using_absolute_expiry(context, absolute_expiry)
91269144 .and_then(|paths| paths.into_iter().next().ok_or(()))
9127- .map_err(|_| Bolt12SemanticError::MissingPaths )?;
9145+ .map_err(|()| Bolt12CreationError::BlindedPathCreationFailed )?;
91289146 let builder = OfferBuilder::deriving_signing_pubkey(node_id, expanded_key, nonce, secp_ctx)
91299147 .chain_hash($self.chain_hash)
91309148 .path(path);
@@ -9187,7 +9205,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
91879205 pub fn create_refund_builder(
91889206 &$self, amount_msats: u64, absolute_expiry: Duration, payment_id: PaymentId,
91899207 retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
9190- ) -> Result<$builder, Bolt12SemanticError > {
9208+ ) -> Result<$builder, Bolt12CreationError > {
91919209 let node_id = $self.get_our_node_id();
91929210 let expanded_key = &$self.inbound_payment_key;
91939211 let entropy = &*$self.entropy_source;
@@ -9197,7 +9215,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
91979215 let context = OffersContext::OutboundPayment { payment_id, nonce, hmac: None };
91989216 let path = $self.create_blinded_paths_using_absolute_expiry(context, Some(absolute_expiry))
91999217 .and_then(|paths| paths.into_iter().next().ok_or(()))
9200- .map_err(|_| Bolt12SemanticError::MissingPaths )?;
9218+ .map_err(|()| Bolt12CreationError::BlindedPathCreationFailed )?;
92019219
92029220 let builder = RefundBuilder::deriving_signing_pubkey(
92039221 node_id, expanded_key, nonce, secp_ctx, amount_msats, payment_id
@@ -9213,7 +9231,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
92139231 .add_new_awaiting_invoice(
92149232 payment_id, expiration, retry_strategy, max_total_routing_fee_msat, None,
92159233 )
9216- .map_err(|_| Bolt12SemanticError ::DuplicatePaymentId)?;
9234+ .map_err(|()| Bolt12CreationError ::DuplicatePaymentId)?;
92179235
92189236 Ok(builder.into())
92199237 }
@@ -9305,7 +9323,7 @@ where
93059323 &self, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
93069324 payer_note: Option<String>, payment_id: PaymentId, retry_strategy: Retry,
93079325 max_total_routing_fee_msat: Option<u64>
9308- ) -> Result<(), Bolt12SemanticError > {
9326+ ) -> Result<(), Bolt12CreationError > {
93099327 let expanded_key = &self.inbound_payment_key;
93109328 let entropy = &*self.entropy_source;
93119329 let secp_ctx = &self.secp_ctx;
@@ -9335,7 +9353,7 @@ where
93359353 OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) }
93369354 );
93379355 let reply_paths = self.create_blinded_paths(context)
9338- .map_err(|_| Bolt12SemanticError::MissingPaths )?;
9356+ .map_err(|()| Bolt12CreationError::BlindedPathCreationFailed )?;
93399357
93409358 let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
93419359
@@ -9349,9 +9367,10 @@ where
93499367 payment_id, expiration, retry_strategy, max_total_routing_fee_msat,
93509368 Some(retryable_invoice_request)
93519369 )
9352- .map_err(|_| Bolt12SemanticError ::DuplicatePaymentId)?;
9370+ .map_err(|()| Bolt12CreationError ::DuplicatePaymentId)?;
93539371
9354- self.enqueue_invoice_request(invoice_request, reply_paths)
9372+ self.enqueue_invoice_request(invoice_request, reply_paths)?;
9373+ Ok(())
93559374 }
93569375
93579376 fn enqueue_invoice_request(
@@ -9414,7 +9433,7 @@ where
94149433 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
94159434 pub fn request_refund_payment(
94169435 &self, refund: &Refund
9417- ) -> Result<Bolt12Invoice, Bolt12SemanticError > {
9436+ ) -> Result<Bolt12Invoice, Bolt12CreationError > {
94189437 let expanded_key = &self.inbound_payment_key;
94199438 let entropy = &*self.entropy_source;
94209439 let secp_ctx = &self.secp_ctx;
@@ -9423,7 +9442,7 @@ where
94239442 let relative_expiry = DEFAULT_RELATIVE_EXPIRY.as_secs() as u32;
94249443
94259444 if refund.chain() != self.chain_hash {
9426- return Err(Bolt12SemanticError::UnsupportedChain);
9445+ return Err(Bolt12CreationError::InvalidSemantics( Bolt12SemanticError::UnsupportedChain) );
94279446 }
94289447
94299448 let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
@@ -9434,7 +9453,7 @@ where
94349453 let payment_paths = self.create_blinded_payment_paths(
94359454 amount_msats, payment_secret, payment_context
94369455 )
9437- .map_err(|_| Bolt12SemanticError::MissingPaths )?;
9456+ .map_err(|()| Bolt12CreationError::BlindedPathCreationFailed )?;
94389457
94399458 #[cfg(feature = "std")]
94409459 let builder = refund.respond_using_derived_keys(
@@ -9457,7 +9476,7 @@ where
94579476 payment_hash: invoice.payment_hash(), nonce, hmac
94589477 });
94599478 let reply_paths = self.create_blinded_paths(context)
9460- .map_err(|_| Bolt12SemanticError::MissingPaths )?;
9479+ .map_err(|()| Bolt12CreationError::BlindedPathCreationFailed )?;
94619480
94629481 let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
94639482 if refund.paths().is_empty() {
@@ -9486,7 +9505,7 @@ where
94869505
94879506 Ok(invoice)
94889507 },
9489- Err(()) => Err(Bolt12SemanticError::InvalidAmount),
9508+ Err(()) => Err(Bolt12CreationError::InvalidSemantics( Bolt12SemanticError::InvalidAmount) ),
94909509 }
94919510 }
94929511
0 commit comments