Skip to content

Commit e396a1a

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

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

src/payment/unified_qr.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,20 @@ impl UnifiedQrPayment {
6868
/// can always pay using the provided on-chain address, while newer wallets will
6969
/// typically opt to use the provided BOLT11 invoice or BOLT12 offer.
7070
///
71+
/// The URI will always include an on-chain address. A BOLT11 invoice will be included
72+
/// unless invoice generation fails, while a BOLT12 offer will only be included when
73+
/// the node has suitable channels for routing.
74+
///
7175
/// # Parameters
7276
/// - `amount_sats`: The amount to be received, specified in satoshis.
7377
/// - `description`: A description or note associated with the payment.
7478
/// This message is visible to the payer and can provide context or details about the payment.
7579
/// - `expiry_sec`: The expiration time for the payment, specified in seconds.
7680
///
7781
/// 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.
82+
/// given. Failure to generate the on-chain address will result in an error return
83+
/// (`Error::WalletOperationFailed`), while failures in invoice or offer generation will
84+
/// result in those components being omitted from the URI.
8185
///
8286
/// The generated URI can then be given to a QR code library.
8387
///
@@ -95,7 +99,7 @@ impl UnifiedQrPayment {
9599
Ok(offer) => Some(offer),
96100
Err(e) => {
97101
log_error!(self.logger, "Failed to create offer: {}", e);
98-
return Err(Error::OfferCreationFailed);
102+
None
99103
},
100104
};
101105

@@ -111,7 +115,7 @@ impl UnifiedQrPayment {
111115
Ok(invoice) => Some(invoice),
112116
Err(e) => {
113117
log_error!(self.logger, "Failed to create invoice {}", e);
114-
return Err(Error::InvoiceCreationFailed);
118+
None
115119
},
116120
};
117121

tests/integration_tests_rust.rs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,21 @@ 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+
// Test 1: Verify URI generation (on-chain + BOLT11) works
1090+
// even before any channels are opened. This checks the graceful fallback behavior.
1091+
let initial_uqr_payment = node_b
1092+
.unified_qr_payment()
1093+
.receive(expected_amount_sats, "asdf", expiry_sec)
1094+
.expect("Failed to generate URI");
1095+
println!("Initial URI (no channels): {}", initial_uqr_payment);
1096+
1097+
assert!(initial_uqr_payment.contains("bitcoin:"));
1098+
assert!(initial_uqr_payment.contains("lightning="));
1099+
assert!(!initial_uqr_payment.contains("lno=")); // BOLT12 requires channels
1100+
10861101
premine_and_distribute_funds(
10871102
&bitcoind.client,
10881103
&electrsd.client,
@@ -1100,20 +1115,16 @@ fn generate_bip21_uri() {
11001115
expect_channel_ready_event!(node_a, node_b.node_id());
11011116
expect_channel_ready_event!(node_b, node_a.node_id());
11021117

1103-
let expected_amount_sats = 100_000;
1104-
let expiry_sec = 4_000;
1105-
1106-
let uqr_payment = node_b.unified_qr_payment().receive(expected_amount_sats, "asdf", expiry_sec);
1118+
// Test 2: Verify URI generation (on-chain + BOLT11 + BOLT12) works after channels are established.
1119+
let uqr_payment = node_b
1120+
.unified_qr_payment()
1121+
.receive(expected_amount_sats, "asdf", expiry_sec)
1122+
.expect("Failed to generate URI");
11071123

1108-
match uqr_payment.clone() {
1109-
Ok(ref uri) => {
1110-
println!("Generated URI: {}", uri);
1111-
assert!(uri.contains("bitcoin:"));
1112-
assert!(uri.contains("lightning="));
1113-
assert!(uri.contains("lno="));
1114-
},
1115-
Err(e) => panic!("Failed to generate URI: {:?}", e),
1116-
}
1124+
println!("Generated URI: {}", uqr_payment);
1125+
assert!(uqr_payment.contains("bitcoin:"));
1126+
assert!(uqr_payment.contains("lightning="));
1127+
assert!(uqr_payment.contains("lno="));
11171128
}
11181129

11191130
#[test]

0 commit comments

Comments
 (0)