Skip to content

Commit 72ee31a

Browse files
committed
continue receive flow on offer/invoice creation failure
1 parent 387cc2d commit 72ee31a

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

src/payment/unified_qr.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,12 @@ impl UnifiedQrPayment {
7575
/// - `expiry_sec`: The expiration time for the payment, specified in seconds.
7676
///
7777
/// Returns a payable URI that can be used to request and receive a payment of the amount
78-
/// given. In case of an error, the function returns `Error::WalletOperationFailed`for on-chain
79-
/// address issues, `Error::InvoiceCreationFailed` for BOLT11 invoice issues, or
80-
/// `Error::OfferCreationFailed` for BOLT12 offer issues.
78+
/// given. The URI will almost always contain at least the on-chain address, and may additionally
79+
/// contain a BOLT11 invoice and/or BOLT12 offer if they were successfully generated.
80+
///
81+
/// Errors during invoice or offer generation are logged but don't prevent the URI generation,
82+
/// allowing for graceful degradation of functionality. Only complete failure to generate
83+
/// the on-chain address will result in an error return (`Error::WalletOperationFailed`).
8184
///
8285
/// The generated URI can then be given to a QR code library.
8386
///
@@ -95,7 +98,7 @@ impl UnifiedQrPayment {
9598
Ok(offer) => Some(offer),
9699
Err(e) => {
97100
log_error!(self.logger, "Failed to create offer: {}", e);
98-
return Err(Error::OfferCreationFailed);
101+
None
99102
},
100103
};
101104

@@ -111,7 +114,7 @@ impl UnifiedQrPayment {
111114
Ok(invoice) => Some(invoice),
112115
Err(e) => {
113116
log_error!(self.logger, "Failed to create invoice {}", e);
114-
return Err(Error::InvoiceCreationFailed);
117+
None
115118
},
116119
};
117120

tests/integration_tests_rust.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,22 @@ fn generate_bip21_uri() {
10831083
let address_a = node_a.onchain_payment().new_address().unwrap();
10841084
let premined_sats = 5_000_000;
10851085

1086+
let expected_amount_sats = 100_000;
1087+
let expiry_sec = 4_000;
1088+
1089+
// No channels exist yet
1090+
let initial_uqr_payment = node_b.unified_qr_payment().receive(expected_amount_sats, "asdf", expiry_sec);
1091+
1092+
match initial_uqr_payment.clone() {
1093+
Ok(ref uri) => {
1094+
println!("Generated URI: {}", uri);
1095+
assert!(uri.contains("bitcoin:"));
1096+
assert!(uri.contains("lightning="));
1097+
assert!(!uri.contains("lno=")); // BOLT12 requires channels
1098+
},
1099+
Err(e) => panic!("Failed to generate URI: {:?}", e),
1100+
}
1101+
10861102
premine_and_distribute_funds(
10871103
&bitcoind.client,
10881104
&electrsd.client,
@@ -1100,9 +1116,6 @@ fn generate_bip21_uri() {
11001116
expect_channel_ready_event!(node_a, node_b.node_id());
11011117
expect_channel_ready_event!(node_b, node_a.node_id());
11021118

1103-
let expected_amount_sats = 100_000;
1104-
let expiry_sec = 4_000;
1105-
11061119
let uqr_payment = node_b.unified_qr_payment().receive(expected_amount_sats, "asdf", expiry_sec);
11071120

11081121
match uqr_payment.clone() {

0 commit comments

Comments
 (0)