Skip to content

Commit 16fbedc

Browse files
committed
rename UnifiedQRPayment to UnifiedPayment, rename QRPaymentResult to UnifiedPaymentResult
These renamings are necessary to reflect the expanded responsibilities for this module.
1 parent 67d5420 commit 16fbedc

File tree

6 files changed

+55
-49
lines changed

6 files changed

+55
-49
lines changed

bindings/ldk_node.udl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ interface Node {
127127
Bolt12Payment bolt12_payment();
128128
SpontaneousPayment spontaneous_payment();
129129
OnchainPayment onchain_payment();
130-
UnifiedQrPayment unified_qr_payment();
130+
UnifiedPayment unified_payment();
131131
LSPS1Liquidity lsps1_liquidity();
132132
[Throws=NodeError]
133133
void connect(PublicKey node_id, SocketAddress address, boolean persist);
@@ -243,11 +243,11 @@ interface FeeRate {
243243
u64 to_sat_per_vb_ceil();
244244
};
245245

246-
interface UnifiedQrPayment {
246+
interface UnifiedPayment {
247247
[Throws=NodeError]
248248
string receive(u64 amount_sats, [ByRef]string message, u32 expiry_sec);
249-
[Throws=NodeError]
250-
QrPaymentResult send([ByRef]string uri_str);
249+
[Throws=NodeError, Async]
250+
UnifiedPaymentResult send([ByRef]string uri_str, u64? amount_msat);
251251
};
252252

253253
interface LSPS1Liquidity {
@@ -418,7 +418,7 @@ interface PaymentKind {
418418
};
419419

420420
[Enum]
421-
interface QrPaymentResult {
421+
interface UnifiedPaymentResult {
422422
Onchain(Txid txid);
423423
Bolt11(PaymentId payment_id);
424424
Bolt12(PaymentId payment_id);

src/ffi/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub use crate::logger::{LogLevel, LogRecord, LogWriter};
2020
pub use crate::payment::store::{
2121
ConfirmationStatus, LSPFeeLimits, PaymentDirection, PaymentKind, PaymentStatus,
2222
};
23-
pub use crate::payment::{MaxTotalRoutingFeeLimit, QrPaymentResult, SendingParameters};
23+
pub use crate::payment::{MaxTotalRoutingFeeLimit, SendingParameters, UnifiedPaymentResult};
2424

2525
pub use lightning::chain::channelmonitor::BalanceSource;
2626
pub use lightning::events::{ClosureReason, PaymentFailureReason};

src/lib.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ use io::utils::write_node_metrics;
139139
use liquidity::{LSPS1Liquidity, LiquiditySource};
140140
use payment::{
141141
Bolt11Payment, Bolt12Payment, OnchainPayment, PaymentDetails, SpontaneousPayment,
142-
UnifiedQrPayment,
142+
UnifiedPayment,
143143
};
144144
use peer_store::{PeerInfo, PeerStore};
145145
use runtime::Runtime;
@@ -885,12 +885,15 @@ impl Node {
885885
/// Returns a payment handler allowing to create [BIP 21] URIs with an on-chain, [BOLT 11],
886886
/// and [BOLT 12] payment options.
887887
///
888+
/// This handler allows you to send payments to these URIs as well as [BIP 353] HRNs.
889+
///
888890
/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
889891
/// [BOLT 12]: https://github.com/lightning/bolts/blob/master/12-offer-encoding.md
890892
/// [BIP 21]: https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki
893+
/// [BIP 353]: https://github.com/bitcoin/bips/blob/master/bip-0353.mediawiki
891894
#[cfg(not(feature = "uniffi"))]
892-
pub fn unified_qr_payment(&self) -> UnifiedQrPayment {
893-
UnifiedQrPayment::new(
895+
pub fn unified_payment(&self) -> UnifiedPayment {
896+
UnifiedPayment::new(
894897
self.onchain_payment().into(),
895898
self.bolt11_payment().into(),
896899
self.bolt12_payment().into(),
@@ -902,12 +905,15 @@ impl Node {
902905
/// Returns a payment handler allowing to create [BIP 21] URIs with an on-chain, [BOLT 11],
903906
/// and [BOLT 12] payment options.
904907
///
908+
/// This handler allows you to send payments to these URIs as well as [BIP 353] HRNs.
909+
///
905910
/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
906911
/// [BOLT 12]: https://github.com/lightning/bolts/blob/master/12-offer-encoding.md
907912
/// [BIP 21]: https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki
913+
/// [BIP 353]: https://github.com/bitcoin/bips/blob/master/bip-0353.mediawiki
908914
#[cfg(feature = "uniffi")]
909-
pub fn unified_qr_payment(&self) -> Arc<UnifiedQrPayment> {
910-
Arc::new(UnifiedQrPayment::new(
915+
pub fn unified_payment(&self) -> Arc<UnifiedPayment> {
916+
Arc::new(UnifiedPayment::new(
911917
self.onchain_payment(),
912918
self.bolt11_payment(),
913919
self.bolt12_payment(),

src/payment/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub use spontaneous::SpontaneousPayment;
2121
pub use store::{
2222
ConfirmationStatus, LSPFeeLimits, PaymentDetails, PaymentDirection, PaymentKind, PaymentStatus,
2323
};
24-
pub use unified::{QrPaymentResult, UnifiedQrPayment};
24+
pub use unified::{UnifiedPayment, UnifiedPaymentResult};
2525

2626
/// Represents information used to send a payment.
2727
#[derive(Clone, Debug, PartialEq)]

src/payment/unified.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ struct Extras {
4646
/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
4747
/// [BOLT 12]: https://github.com/lightning/bolts/blob/master/12-offer-encoding.md
4848
/// [`Node::unified_qr_payment`]: crate::Node::unified_qr_payment
49-
pub struct UnifiedQrPayment {
49+
pub struct UnifiedPayment {
5050
onchain_payment: Arc<OnchainPayment>,
5151
bolt11_invoice: Arc<Bolt11Payment>,
5252
bolt12_payment: Arc<Bolt12Payment>,
5353
config: Arc<Config>,
5454
logger: Arc<Logger>,
5555
}
5656

57-
impl UnifiedQrPayment {
57+
impl UnifiedPayment {
5858
pub(crate) fn new(
5959
onchain_payment: Arc<OnchainPayment>, bolt11_invoice: Arc<Bolt11Payment>,
6060
bolt12_payment: Arc<Bolt12Payment>, config: Arc<Config>, logger: Arc<Logger>,
@@ -139,7 +139,7 @@ impl UnifiedQrPayment {
139139
/// occurs, an `Error` is returned detailing the issue encountered.
140140
///
141141
/// [BIP 21]: https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki
142-
pub fn send(&self, uri_str: &str) -> Result<QrPaymentResult, Error> {
142+
pub fn send(&self, uri_str: &str) -> Result<UnifiedPaymentResult, Error> {
143143
let uri: bip21::Uri<NetworkUnchecked, Extras> =
144144
uri_str.parse().map_err(|_| Error::InvalidUri)?;
145145

@@ -149,15 +149,15 @@ impl UnifiedQrPayment {
149149
if let Some(offer) = uri_network_checked.extras.bolt12_offer {
150150
let offer = maybe_wrap(offer);
151151
match self.bolt12_payment.send(&offer, None, None) {
152-
Ok(payment_id) => return Ok(QrPaymentResult::Bolt12 { payment_id }),
152+
Ok(payment_id) => return Ok(UnifiedPaymentResult::Bolt12 { payment_id }),
153153
Err(e) => log_error!(self.logger, "Failed to send BOLT12 offer: {:?}. This is part of a unified QR code payment. Falling back to the BOLT11 invoice.", e),
154154
}
155155
}
156156

157157
if let Some(invoice) = uri_network_checked.extras.bolt11_invoice {
158158
let invoice = maybe_wrap(invoice);
159159
match self.bolt11_invoice.send(&invoice, None) {
160-
Ok(payment_id) => return Ok(QrPaymentResult::Bolt11 { payment_id }),
160+
Ok(payment_id) => return Ok(UnifiedPaymentResult::Bolt11 { payment_id }),
161161
Err(e) => log_error!(self.logger, "Failed to send BOLT11 invoice: {:?}. This is part of a unified QR code payment. Falling back to the on-chain transaction.", e),
162162
}
163163
}
@@ -176,7 +176,7 @@ impl UnifiedQrPayment {
176176
None,
177177
)?;
178178

179-
Ok(QrPaymentResult::Onchain { txid })
179+
Ok(UnifiedPaymentResult::Onchain { txid })
180180
}
181181
}
182182

@@ -189,7 +189,7 @@ impl UnifiedQrPayment {
189189
/// [`PaymentId`]: lightning::ln::channelmanager::PaymentId
190190
/// [`Txid`]: bitcoin::hash_types::Txid
191191
#[derive(Debug)]
192-
pub enum QrPaymentResult {
192+
pub enum UnifiedPaymentResult {
193193
/// An on-chain payment.
194194
Onchain {
195195
/// The transaction ID (txid) of the on-chain payment.

tests/integration_tests_rust.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use ldk_node::config::EsploraSyncConfig;
2222
use ldk_node::liquidity::LSPS2ServiceConfig;
2323
use ldk_node::payment::{
2424
ConfirmationStatus, PaymentDetails, PaymentDirection, PaymentKind, PaymentStatus,
25-
QrPaymentResult, SendingParameters,
25+
SendingParameters, UnifiedPaymentResult,
2626
};
2727
use ldk_node::{Builder, Event, NodeError};
2828

@@ -1235,15 +1235,15 @@ fn generate_bip21_uri() {
12351235

12361236
// Test 1: Verify URI generation (on-chain + BOLT11) works
12371237
// even before any channels are opened. This checks the graceful fallback behavior.
1238-
let initial_uqr_payment = node_b
1239-
.unified_qr_payment()
1238+
let initial_uni_payment = node_b
1239+
.unified_payment()
12401240
.receive(expected_amount_sats, "asdf", expiry_sec)
12411241
.expect("Failed to generate URI");
1242-
println!("Initial URI (no channels): {}", initial_uqr_payment);
1242+
println!("Initial URI (no channels): {}", initial_uni_payment);
12431243

1244-
assert!(initial_uqr_payment.contains("bitcoin:"));
1245-
assert!(initial_uqr_payment.contains("lightning="));
1246-
assert!(!initial_uqr_payment.contains("lno=")); // BOLT12 requires channels
1244+
assert!(initial_uni_payment.contains("bitcoin:"));
1245+
assert!(initial_uni_payment.contains("lightning="));
1246+
assert!(!initial_uni_payment.contains("lno=")); // BOLT12 requires channels
12471247

12481248
premine_and_distribute_funds(
12491249
&bitcoind.client,
@@ -1263,15 +1263,15 @@ fn generate_bip21_uri() {
12631263
expect_channel_ready_event!(node_b, node_a.node_id());
12641264

12651265
// Test 2: Verify URI generation (on-chain + BOLT11 + BOLT12) works after channels are established.
1266-
let uqr_payment = node_b
1267-
.unified_qr_payment()
1266+
let uni_payment = node_b
1267+
.unified_payment()
12681268
.receive(expected_amount_sats, "asdf", expiry_sec)
12691269
.expect("Failed to generate URI");
12701270

1271-
println!("Generated URI: {}", uqr_payment);
1272-
assert!(uqr_payment.contains("bitcoin:"));
1273-
assert!(uqr_payment.contains("lightning="));
1274-
assert!(uqr_payment.contains("lno="));
1271+
println!("Generated URI: {}", uni_payment);
1272+
assert!(uni_payment.contains("bitcoin:"));
1273+
assert!(uni_payment.contains("lightning="));
1274+
assert!(uni_payment.contains("lno="));
12751275
}
12761276

12771277
#[test]
@@ -1312,17 +1312,17 @@ fn unified_qr_send_receive() {
13121312
let expected_amount_sats = 100_000;
13131313
let expiry_sec = 4_000;
13141314

1315-
let uqr_payment = node_b.unified_qr_payment().receive(expected_amount_sats, "asdf", expiry_sec);
1316-
let uri_str = uqr_payment.clone().unwrap();
1317-
let offer_payment_id: PaymentId = match node_a.unified_qr_payment().send(&uri_str) {
1318-
Ok(QrPaymentResult::Bolt12 { payment_id }) => {
1315+
let uni_payment = node_b.unified_payment().receive(expected_amount_sats, "asdf", expiry_sec);
1316+
let uri_str = uni_payment.clone().unwrap();
1317+
let offer_payment_id: PaymentId = match node_a.unified_payment().send(&uri_str) {
1318+
Ok(UnifiedPaymentResult::Bolt12 { payment_id }) => {
13191319
println!("\nBolt12 payment sent successfully with PaymentID: {:?}", payment_id);
13201320
payment_id
13211321
},
1322-
Ok(QrPaymentResult::Bolt11 { payment_id: _ }) => {
1322+
Ok(UnifiedPaymentResult::Bolt11 { payment_id: _ }) => {
13231323
panic!("Expected Bolt12 payment but got Bolt11");
13241324
},
1325-
Ok(QrPaymentResult::Onchain { txid: _ }) => {
1325+
Ok(UnifiedPaymentResult::Onchain { txid: _ }) => {
13261326
panic!("Expected Bolt12 payment but get On-chain transaction");
13271327
},
13281328
Err(e) => {
@@ -1335,15 +1335,15 @@ fn unified_qr_send_receive() {
13351335
// Cut off the BOLT12 part to fallback to BOLT11.
13361336
let uri_str_without_offer = uri_str.split("&lno=").next().unwrap();
13371337
let invoice_payment_id: PaymentId =
1338-
match node_a.unified_qr_payment().send(uri_str_without_offer) {
1339-
Ok(QrPaymentResult::Bolt12 { payment_id: _ }) => {
1338+
match node_a.unified_payment().send(uri_str_without_offer) {
1339+
Ok(UnifiedPaymentResult::Bolt12 { payment_id: _ }) => {
13401340
panic!("Expected Bolt11 payment but got Bolt12");
13411341
},
1342-
Ok(QrPaymentResult::Bolt11 { payment_id }) => {
1342+
Ok(UnifiedPaymentResult::Bolt11 { payment_id }) => {
13431343
println!("\nBolt11 payment sent successfully with PaymentID: {:?}", payment_id);
13441344
payment_id
13451345
},
1346-
Ok(QrPaymentResult::Onchain { txid: _ }) => {
1346+
Ok(UnifiedPaymentResult::Onchain { txid: _ }) => {
13471347
panic!("Expected Bolt11 payment but got on-chain transaction");
13481348
},
13491349
Err(e) => {
@@ -1353,19 +1353,19 @@ fn unified_qr_send_receive() {
13531353
expect_payment_successful_event!(node_a, Some(invoice_payment_id), None);
13541354

13551355
let expect_onchain_amount_sats = 800_000;
1356-
let onchain_uqr_payment =
1357-
node_b.unified_qr_payment().receive(expect_onchain_amount_sats, "asdf", 4_000).unwrap();
1356+
let onchain_uni_payment =
1357+
node_b.unified_payment().receive(expect_onchain_amount_sats, "asdf", 4_000).unwrap();
13581358

13591359
// Cut off any lightning part to fallback to on-chain only.
1360-
let uri_str_without_lightning = onchain_uqr_payment.split("&lightning=").next().unwrap();
1361-
let txid = match node_a.unified_qr_payment().send(&uri_str_without_lightning) {
1362-
Ok(QrPaymentResult::Bolt12 { payment_id: _ }) => {
1360+
let uri_str_without_lightning = onchain_uni_payment.split("&lightning=").next().unwrap();
1361+
let txid = match node_a.unified_payment().send(&uri_str_without_lightning) {
1362+
Ok(UnifiedPaymentResult::Bolt12 { payment_id: _ }) => {
13631363
panic!("Expected on-chain payment but got Bolt12")
13641364
},
1365-
Ok(QrPaymentResult::Bolt11 { payment_id: _ }) => {
1365+
Ok(UnifiedPaymentResult::Bolt11 { payment_id: _ }) => {
13661366
panic!("Expected on-chain payment but got Bolt11");
13671367
},
1368-
Ok(QrPaymentResult::Onchain { txid }) => {
1368+
Ok(UnifiedPaymentResult::Onchain { txid }) => {
13691369
println!("\nOn-chain transaction successful with Txid: {}", txid);
13701370
txid
13711371
},

0 commit comments

Comments
 (0)