@@ -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 _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
9024
9042
@@ -9027,7 +9045,7 @@ where
9027
9045
.add_new_awaiting_invoice(
9028
9046
payment_id, expiration, retry_strategy, max_total_routing_fee_msat
9029
9047
)
9030
- .map_err(|_| Bolt12SemanticError ::DuplicatePaymentId)?;
9048
+ .map_err(|_| Bolt12CreationError ::DuplicatePaymentId)?;
9031
9049
9032
9050
let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
9033
9051
if !offer.paths().is_empty() {
@@ -9054,7 +9072,7 @@ where
9054
9072
}
9055
9073
} else {
9056
9074
debug_assert!(false);
9057
- return Err(Bolt12SemanticError::MissingSigningPubkey);
9075
+ return Err(Bolt12CreationError::InvalidSemantics( Bolt12SemanticError::MissingSigningPubkey) );
9058
9076
}
9059
9077
9060
9078
Ok(())
@@ -9084,7 +9102,7 @@ where
9084
9102
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
9085
9103
pub fn request_refund_payment(
9086
9104
&self, refund: &Refund
9087
- ) -> Result<Bolt12Invoice, Bolt12SemanticError > {
9105
+ ) -> Result<Bolt12Invoice, Bolt12CreationError > {
9088
9106
let expanded_key = &self.inbound_payment_key;
9089
9107
let entropy = &*self.entropy_source;
9090
9108
let secp_ctx = &self.secp_ctx;
@@ -9093,7 +9111,7 @@ where
9093
9111
let relative_expiry = DEFAULT_RELATIVE_EXPIRY.as_secs() as u32;
9094
9112
9095
9113
if refund.chain() != self.chain_hash {
9096
- return Err(Bolt12SemanticError::UnsupportedChain);
9114
+ return Err(Bolt12CreationError::InvalidSemantics( Bolt12SemanticError::UnsupportedChain) );
9097
9115
}
9098
9116
9099
9117
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
@@ -9104,7 +9122,7 @@ where
9104
9122
let payment_paths = self.create_blinded_payment_paths(
9105
9123
amount_msats, payment_secret, payment_context
9106
9124
)
9107
- .map_err(|_| Bolt12SemanticError::MissingPaths )?;
9125
+ .map_err(|_| Bolt12CreationError::BlindedPathCreationFailed )?;
9108
9126
9109
9127
#[cfg(feature = "std")]
9110
9128
let builder = refund.respond_using_derived_keys(
@@ -9121,7 +9139,7 @@ where
9121
9139
let builder: InvoiceBuilder<DerivedSigningPubkey> = builder.into();
9122
9140
let invoice = builder.allow_mpp().build_and_sign(secp_ctx)?;
9123
9141
let reply_paths = self.create_blinded_paths(OffersContext::Unknown {})
9124
- .map_err(|_| Bolt12SemanticError::MissingPaths )?;
9142
+ .map_err(|_| Bolt12CreationError::BlindedPathCreationFailed )?;
9125
9143
9126
9144
let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
9127
9145
if refund.paths().is_empty() {
@@ -9150,7 +9168,7 @@ where
9150
9168
9151
9169
Ok(invoice)
9152
9170
},
9153
- Err(()) => Err(Bolt12SemanticError::InvalidAmount),
9171
+ Err(()) => Err(Bolt12CreationError::InvalidSemantics( Bolt12SemanticError::InvalidAmount) ),
9154
9172
}
9155
9173
}
9156
9174
0 commit comments