Skip to content

Commit 5c8be84

Browse files
committed
f Revert Bolt12CreationError to Bolt12SemanticError
Revert the return type of `create_refund_builder` and `pay_for_offer` from `Bolt12CreationError` back to `Bolt12SemanticError`. This change is temporary, as a future commit will introduce `Bolt12RequestError` for these functions.
1 parent 61f7348 commit 5c8be84

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,12 +1946,13 @@ where
19461946
/// ```
19471947
/// # use core::time::Duration;
19481948
/// # use lightning::events::{Event, EventsProvider};
1949-
/// # use lightning::ln::channelmanager::{AChannelManager, Bolt12CreationError, PaymentId, RecentPaymentDetails, Retry};
1949+
/// # use lightning::ln::channelmanager::{AChannelManager, PaymentId, RecentPaymentDetails, Retry};
1950+
/// # use lightning::offers::parse::Bolt12SemanticError;
19501951
/// #
19511952
/// # fn example<T: AChannelManager>(
19521953
/// # channel_manager: T, amount_msats: u64, absolute_expiry: Duration, retry: Retry,
19531954
/// # max_total_routing_fee_msat: Option<u64>
1954-
/// # ) -> Result<(), Bolt12CreationError> {
1955+
/// # ) -> Result<(), Bolt12SemanticError> {
19551956
/// # let channel_manager = channel_manager.get_cm();
19561957
/// let payment_id = PaymentId([42; 32]);
19571958
/// let refund = channel_manager
@@ -2688,10 +2689,6 @@ pub enum RecentPaymentDetails {
26882689
pub enum Bolt12CreationError {
26892690
/// Error from BOLT 12 semantic checks.
26902691
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,
26952692
/// Failed to create a blinded path.
26962693
BlindedPathCreationFailed,
26972694
}
@@ -9205,7 +9202,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
92059202
pub fn create_refund_builder(
92069203
&$self, amount_msats: u64, absolute_expiry: Duration, payment_id: PaymentId,
92079204
retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
9208-
) -> Result<$builder, Bolt12CreationError> {
9205+
) -> Result<$builder, Bolt12SemanticError> {
92099206
let node_id = $self.get_our_node_id();
92109207
let expanded_key = &$self.inbound_payment_key;
92119208
let entropy = &*$self.entropy_source;
@@ -9215,7 +9212,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
92159212
let context = OffersContext::OutboundPayment { payment_id, nonce, hmac: None };
92169213
let path = $self.create_blinded_paths_using_absolute_expiry(context, Some(absolute_expiry))
92179214
.and_then(|paths| paths.into_iter().next().ok_or(()))
9218-
.map_err(|()| Bolt12CreationError::BlindedPathCreationFailed)?;
9215+
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
92199216

92209217
let builder = RefundBuilder::deriving_signing_pubkey(
92219218
node_id, expanded_key, nonce, secp_ctx, amount_msats, payment_id
@@ -9231,7 +9228,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
92319228
.add_new_awaiting_invoice(
92329229
payment_id, expiration, retry_strategy, max_total_routing_fee_msat, None,
92339230
)
9234-
.map_err(|()| Bolt12CreationError::DuplicatePaymentId)?;
9231+
.map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;
92359232

92369233
Ok(builder.into())
92379234
}
@@ -9323,7 +9320,7 @@ where
93239320
&self, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
93249321
payer_note: Option<String>, payment_id: PaymentId, retry_strategy: Retry,
93259322
max_total_routing_fee_msat: Option<u64>
9326-
) -> Result<(), Bolt12CreationError> {
9323+
) -> Result<(), Bolt12SemanticError> {
93279324
let expanded_key = &self.inbound_payment_key;
93289325
let entropy = &*self.entropy_source;
93299326
let secp_ctx = &self.secp_ctx;
@@ -9353,7 +9350,7 @@ where
93539350
OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) }
93549351
);
93559352
let reply_paths = self.create_blinded_paths(context)
9356-
.map_err(|()| Bolt12CreationError::BlindedPathCreationFailed)?;
9353+
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
93579354

93589355
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
93599356

@@ -9367,7 +9364,7 @@ where
93679364
payment_id, expiration, retry_strategy, max_total_routing_fee_msat,
93689365
Some(retryable_invoice_request)
93699366
)
9370-
.map_err(|()| Bolt12CreationError::DuplicatePaymentId)?;
9367+
.map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;
93719368

93729369
self.enqueue_invoice_request(invoice_request, reply_paths)?;
93739370
Ok(())

lightning/src/ln/offers_tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,7 +1697,7 @@ fn fails_creating_or_paying_for_offer_without_connected_peers() {
16971697

16981698
match david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None) {
16991699
Ok(_) => panic!("Expected error"),
1700-
Err(e) => assert_eq!(e, Bolt12CreationError::BlindedPathCreationFailed),
1700+
Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
17011701
}
17021702

17031703
assert!(nodes[0].node.list_recent_payments().is_empty());
@@ -1755,7 +1755,7 @@ fn fails_creating_refund_or_sending_invoice_without_connected_peers() {
17551755
10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
17561756
) {
17571757
Ok(_) => panic!("Expected error"),
1758-
Err(e) => assert_eq!(e, Bolt12CreationError::BlindedPathCreationFailed),
1758+
Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
17591759
}
17601760

17611761
let mut args = ReconnectArgs::new(charlie, david);
@@ -1801,7 +1801,7 @@ fn fails_creating_invoice_request_for_unsupported_chain() {
18011801
let payment_id = PaymentId([1; 32]);
18021802
match bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None) {
18031803
Ok(_) => panic!("Expected error"),
1804-
Err(e) => assert_eq!(e, Bolt12CreationError::InvalidSemantics(Bolt12SemanticError::UnsupportedChain)),
1804+
Err(e) => assert_eq!(e, Bolt12SemanticError::UnsupportedChain),
18051805
}
18061806
}
18071807

@@ -1860,7 +1860,7 @@ fn fails_creating_invoice_request_without_blinded_reply_path() {
18601860

18611861
match david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None) {
18621862
Ok(_) => panic!("Expected error"),
1863-
Err(e) => assert_eq!(e, Bolt12CreationError::BlindedPathCreationFailed),
1863+
Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
18641864
}
18651865

18661866
assert!(nodes[0].node.list_recent_payments().is_empty());
@@ -1900,7 +1900,7 @@ fn fails_creating_invoice_request_with_duplicate_payment_id() {
19001900

19011901
match david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None) {
19021902
Ok(_) => panic!("Expected error"),
1903-
Err(e) => assert_eq!(e, Bolt12CreationError::DuplicatePaymentId),
1903+
Err(e) => assert_eq!(e, Bolt12SemanticError::DuplicatePaymentId),
19041904
}
19051905

19061906
expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
@@ -1928,7 +1928,7 @@ fn fails_creating_refund_with_duplicate_payment_id() {
19281928
10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
19291929
) {
19301930
Ok(_) => panic!("Expected error"),
1931-
Err(e) => assert_eq!(e, Bolt12CreationError::DuplicatePaymentId),
1931+
Err(e) => assert_eq!(e, Bolt12SemanticError::DuplicatePaymentId),
19321932
}
19331933

19341934
expect_recent_payment!(nodes[0], RecentPaymentDetails::AwaitingInvoice, payment_id);

lightning/src/offers/parse.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ pub enum Bolt12SemanticError {
180180
MissingPayerSigningPubkey,
181181
/// A payer id was expected but was missing.
182182
MissingPayerId,
183+
/// The payment id for a refund or request is already in use.
184+
DuplicatePaymentId,
183185
/// Blinded paths were expected but were missing.
184186
MissingPaths,
185187
/// Blinded paths were provided but were not expected.

0 commit comments

Comments
 (0)