Skip to content

Commit d22d118

Browse files
committed
Rename UnifiedQRPayment to UnifiedPayment
Rename the primary payment handler struct from UnifiedQRPayment to UnifiedPayment. Also rename QRPaymentResult to UnifiedPaymentResult. This change aligns with the prior module rename and reflects that the component handles a broader range of payment inputs.
1 parent 3d63755 commit d22d118

File tree

6 files changed

+61
-51
lines changed

6 files changed

+61
-51
lines changed

bindings/ldk_node.udl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ interface Node {
139139
Bolt12Payment bolt12_payment();
140140
SpontaneousPayment spontaneous_payment();
141141
OnchainPayment onchain_payment();
142-
UnifiedQrPayment unified_qr_payment();
142+
UnifiedPayment unified_payment();
143143
LSPS1Liquidity lsps1_liquidity();
144144
[Throws=NodeError]
145145
void connect(PublicKey node_id, SocketAddress address, boolean persist);
@@ -265,11 +265,11 @@ interface FeeRate {
265265
u64 to_sat_per_vb_ceil();
266266
};
267267

268-
interface UnifiedQrPayment {
268+
interface UnifiedPayment {
269269
[Throws=NodeError]
270270
string receive(u64 amount_sats, [ByRef]string message, u32 expiry_sec);
271271
[Throws=NodeError]
272-
QrPaymentResult send([ByRef]string uri_str, RouteParametersConfig? route_parameters);
272+
UnifiedPaymentResult send([ByRef]string uri_str, RouteParametersConfig? route_parameters);
273273
};
274274

275275
interface LSPS1Liquidity {
@@ -447,7 +447,7 @@ interface PaymentKind {
447447
};
448448

449449
[Enum]
450-
interface QrPaymentResult {
450+
interface UnifiedPaymentResult {
451451
Onchain(Txid txid);
452452
Bolt11(PaymentId payment_id);
453453
Bolt12(PaymentId payment_id);

src/ffi/types.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ pub use crate::logger::{LogLevel, LogRecord, LogWriter};
5454
pub use crate::payment::store::{
5555
ConfirmationStatus, LSPFeeLimits, PaymentDirection, PaymentKind, PaymentStatus,
5656
};
57-
pub use crate::payment::QrPaymentResult;
57+
pub use crate::payment::UnifiedPaymentResult;
58+
59+
pub use lightning::onion_message::dns_resolution::HumanReadableName as LdkHumanReadableName;
60+
5861
use crate::{hex_utils, SocketAddress, UniffiCustomTypeConverter, UserChannelId};
5962

6063
impl UniffiCustomTypeConverter for PublicKey {

src/lib.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ use payment::asynchronous::om_mailbox::OnionMessageMailbox;
149149
use payment::asynchronous::static_invoice_store::StaticInvoiceStore;
150150
use payment::{
151151
Bolt11Payment, Bolt12Payment, OnchainPayment, PaymentDetails, SpontaneousPayment,
152-
UnifiedQrPayment,
152+
UnifiedPayment,
153153
};
154154
use peer_store::{PeerInfo, PeerStore};
155155
use rand::Rng;
@@ -945,12 +945,15 @@ impl Node {
945945
/// Returns a payment handler allowing to create [BIP 21] URIs with an on-chain, [BOLT 11],
946946
/// and [BOLT 12] payment options.
947947
///
948+
/// This handler allows you to send payments to these URIs as well as [BIP 353] HRNs.
949+
///
948950
/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
949951
/// [BOLT 12]: https://github.com/lightning/bolts/blob/master/12-offer-encoding.md
950952
/// [BIP 21]: https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki
953+
/// [BIP 353]: https://github.com/bitcoin/bips/blob/master/bip-0353.mediawiki
951954
#[cfg(not(feature = "uniffi"))]
952-
pub fn unified_qr_payment(&self) -> UnifiedQrPayment {
953-
UnifiedQrPayment::new(
955+
pub fn unified_payment(&self) -> UnifiedPayment {
956+
UnifiedPayment::new(
954957
self.onchain_payment().into(),
955958
self.bolt11_payment().into(),
956959
self.bolt12_payment().into(),
@@ -962,12 +965,15 @@ impl Node {
962965
/// Returns a payment handler allowing to create [BIP 21] URIs with an on-chain, [BOLT 11],
963966
/// and [BOLT 12] payment options.
964967
///
968+
/// This handler allows you to send payments to these URIs as well as [BIP 353] HRNs.
969+
///
965970
/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
966971
/// [BOLT 12]: https://github.com/lightning/bolts/blob/master/12-offer-encoding.md
967972
/// [BIP 21]: https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki
973+
/// [BIP 353]: https://github.com/bitcoin/bips/blob/master/bip-0353.mediawiki
968974
#[cfg(feature = "uniffi")]
969-
pub fn unified_qr_payment(&self) -> Arc<UnifiedQrPayment> {
970-
Arc::new(UnifiedQrPayment::new(
975+
pub fn unified_payment(&self) -> Arc<UnifiedPayment> {
976+
Arc::new(UnifiedPayment::new(
971977
self.onchain_payment(),
972978
self.bolt11_payment(),
973979
self.bolt12_payment(),

src/payment/mod.rs

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

src/payment/unified.rs

Lines changed: 11 additions & 10 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>,
@@ -144,7 +144,7 @@ impl UnifiedQrPayment {
144144
/// [BIP 21]: https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki
145145
pub fn send(
146146
&self, uri_str: &str, route_parameters: Option<RouteParametersConfig>,
147-
) -> Result<QrPaymentResult, Error> {
147+
) -> Result<UnifiedPaymentResult, Error> {
148148
let uri: bip21::Uri<NetworkUnchecked, Extras> =
149149
uri_str.parse().map_err(|_| Error::InvalidUri)?;
150150

@@ -153,16 +153,18 @@ impl UnifiedQrPayment {
153153

154154
if let Some(offer) = uri_network_checked.extras.bolt12_offer {
155155
let offer = maybe_wrap(offer);
156+
156157
match self.bolt12_payment.send(&offer, None, None, route_parameters) {
157-
Ok(payment_id) => return Ok(QrPaymentResult::Bolt12 { payment_id }),
158+
Ok(payment_id) => return Ok(UnifiedPaymentResult::Bolt12 { payment_id }),
158159
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),
159160
}
160161
}
161162

162163
if let Some(invoice) = uri_network_checked.extras.bolt11_invoice {
163164
let invoice = maybe_wrap(invoice);
165+
164166
match self.bolt11_invoice.send(&invoice, route_parameters) {
165-
Ok(payment_id) => return Ok(QrPaymentResult::Bolt11 { payment_id }),
167+
Ok(payment_id) => return Ok(UnifiedPaymentResult::Bolt11 { payment_id }),
166168
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),
167169
}
168170
}
@@ -181,7 +183,7 @@ impl UnifiedQrPayment {
181183
None,
182184
)?;
183185

184-
Ok(QrPaymentResult::Onchain { txid })
186+
Ok(UnifiedPaymentResult::Onchain { txid })
185187
}
186188
}
187189

@@ -194,7 +196,7 @@ impl UnifiedQrPayment {
194196
/// [`PaymentId`]: lightning::ln::channelmanager::PaymentId
195197
/// [`Txid`]: bitcoin::hash_types::Txid
196198
#[derive(Debug)]
197-
pub enum QrPaymentResult {
199+
pub enum UnifiedPaymentResult {
198200
/// An on-chain payment.
199201
Onchain {
200202
/// The transaction ID (txid) of the on-chain payment.
@@ -308,9 +310,8 @@ impl DeserializationError for Extras {
308310

309311
#[cfg(test)]
310312
mod tests {
311-
use super::*;
312-
use crate::payment::unified::Extras;
313-
use bitcoin::{Address, Network};
313+
use super::{Amount, Bolt11Invoice, Extras, Offer};
314+
use bitcoin::{address::NetworkUnchecked, Address, Network};
314315
use std::str::FromStr;
315316

316317
#[test]

tests/integration_tests_rust.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use ldk_node::config::{AsyncPaymentsRole, EsploraSyncConfig};
2929
use ldk_node::liquidity::LSPS2ServiceConfig;
3030
use ldk_node::payment::{
3131
ConfirmationStatus, PaymentDetails, PaymentDirection, PaymentKind, PaymentStatus,
32-
QrPaymentResult,
32+
UnifiedPaymentResult,
3333
};
3434
use ldk_node::{Builder, DynStore, Event, NodeError};
3535
use lightning::ln::channelmanager::PaymentId;
@@ -1528,15 +1528,15 @@ async fn generate_bip21_uri() {
15281528

15291529
// Test 1: Verify URI generation (on-chain + BOLT11) works
15301530
// even before any channels are opened. This checks the graceful fallback behavior.
1531-
let initial_uqr_payment = node_b
1532-
.unified_qr_payment()
1531+
let initial_uni_payment = node_b
1532+
.unified_payment()
15331533
.receive(expected_amount_sats, "asdf", expiry_sec)
15341534
.expect("Failed to generate URI");
1535-
println!("Initial URI (no channels): {}", initial_uqr_payment);
1535+
println!("Initial URI (no channels): {}", initial_uni_payment);
15361536

1537-
assert!(initial_uqr_payment.contains("bitcoin:"));
1538-
assert!(initial_uqr_payment.contains("lightning="));
1539-
assert!(!initial_uqr_payment.contains("lno=")); // BOLT12 requires channels
1537+
assert!(initial_uni_payment.contains("bitcoin:"));
1538+
assert!(initial_uni_payment.contains("lightning="));
1539+
assert!(!initial_uni_payment.contains("lno=")); // BOLT12 requires channels
15401540

15411541
premine_and_distribute_funds(
15421542
&bitcoind.client,
@@ -1557,15 +1557,15 @@ async fn generate_bip21_uri() {
15571557
expect_channel_ready_event!(node_b, node_a.node_id());
15581558

15591559
// Test 2: Verify URI generation (on-chain + BOLT11 + BOLT12) works after channels are established.
1560-
let uqr_payment = node_b
1561-
.unified_qr_payment()
1560+
let uni_payment = node_b
1561+
.unified_payment()
15621562
.receive(expected_amount_sats, "asdf", expiry_sec)
15631563
.expect("Failed to generate URI");
15641564

1565-
println!("Generated URI: {}", uqr_payment);
1566-
assert!(uqr_payment.contains("bitcoin:"));
1567-
assert!(uqr_payment.contains("lightning="));
1568-
assert!(uqr_payment.contains("lno="));
1565+
println!("Generated URI: {}", uni_payment);
1566+
assert!(uni_payment.contains("bitcoin:"));
1567+
assert!(uni_payment.contains("lightning="));
1568+
assert!(uni_payment.contains("lno="));
15691569
}
15701570

15711571
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
@@ -1607,17 +1607,17 @@ async fn unified_qr_send_receive() {
16071607
let expected_amount_sats = 100_000;
16081608
let expiry_sec = 4_000;
16091609

1610-
let uqr_payment = node_b.unified_qr_payment().receive(expected_amount_sats, "asdf", expiry_sec);
1611-
let uri_str = uqr_payment.clone().unwrap();
1612-
let offer_payment_id: PaymentId = match node_a.unified_qr_payment().send(&uri_str, None) {
1613-
Ok(QrPaymentResult::Bolt12 { payment_id }) => {
1610+
let uni_payment = node_b.unified_payment().receive(expected_amount_sats, "asdf", expiry_sec);
1611+
let uri_str = uni_payment.clone().unwrap();
1612+
let offer_payment_id: PaymentId = match node_a.unified_payment().send(&uri_str, None) {
1613+
Ok(UnifiedPaymentResult::Bolt12 { payment_id }) => {
16141614
println!("\nBolt12 payment sent successfully with PaymentID: {:?}", payment_id);
16151615
payment_id
16161616
},
1617-
Ok(QrPaymentResult::Bolt11 { payment_id: _ }) => {
1617+
Ok(UnifiedPaymentResult::Bolt11 { payment_id: _ }) => {
16181618
panic!("Expected Bolt12 payment but got Bolt11");
16191619
},
1620-
Ok(QrPaymentResult::Onchain { txid: _ }) => {
1620+
Ok(UnifiedPaymentResult::Onchain { txid: _ }) => {
16211621
panic!("Expected Bolt12 payment but get On-chain transaction");
16221622
},
16231623
Err(e) => {
@@ -1630,15 +1630,15 @@ async fn unified_qr_send_receive() {
16301630
// Cut off the BOLT12 part to fallback to BOLT11.
16311631
let uri_str_without_offer = uri_str.split("&lno=").next().unwrap();
16321632
let invoice_payment_id: PaymentId =
1633-
match node_a.unified_qr_payment().send(uri_str_without_offer, None) {
1634-
Ok(QrPaymentResult::Bolt12 { payment_id: _ }) => {
1633+
match node_a.unified_payment().send(uri_str_without_offer, None) {
1634+
Ok(UnifiedPaymentResult::Bolt12 { payment_id: _ }) => {
16351635
panic!("Expected Bolt11 payment but got Bolt12");
16361636
},
1637-
Ok(QrPaymentResult::Bolt11 { payment_id }) => {
1637+
Ok(UnifiedPaymentResult::Bolt11 { payment_id }) => {
16381638
println!("\nBolt11 payment sent successfully with PaymentID: {:?}", payment_id);
16391639
payment_id
16401640
},
1641-
Ok(QrPaymentResult::Onchain { txid: _ }) => {
1641+
Ok(UnifiedPaymentResult::Onchain { txid: _ }) => {
16421642
panic!("Expected Bolt11 payment but got on-chain transaction");
16431643
},
16441644
Err(e) => {
@@ -1648,19 +1648,19 @@ async fn unified_qr_send_receive() {
16481648
expect_payment_successful_event!(node_a, Some(invoice_payment_id), None);
16491649

16501650
let expect_onchain_amount_sats = 800_000;
1651-
let onchain_uqr_payment =
1652-
node_b.unified_qr_payment().receive(expect_onchain_amount_sats, "asdf", 4_000).unwrap();
1651+
let onchain_uni_payment =
1652+
node_b.unified_payment().receive(expect_onchain_amount_sats, "asdf", 4_000).unwrap();
16531653

16541654
// Cut off any lightning part to fallback to on-chain only.
1655-
let uri_str_without_lightning = onchain_uqr_payment.split("&lightning=").next().unwrap();
1656-
let txid = match node_a.unified_qr_payment().send(&uri_str_without_lightning, None) {
1657-
Ok(QrPaymentResult::Bolt12 { payment_id: _ }) => {
1655+
let uri_str_without_lightning = onchain_uni_payment.split("&lightning=").next().unwrap();
1656+
let txid = match node_a.unified_payment().send(&uri_str_without_lightning, None) {
1657+
Ok(UnifiedPaymentResult::Bolt12 { payment_id: _ }) => {
16581658
panic!("Expected on-chain payment but got Bolt12")
16591659
},
1660-
Ok(QrPaymentResult::Bolt11 { payment_id: _ }) => {
1660+
Ok(UnifiedPaymentResult::Bolt11 { payment_id: _ }) => {
16611661
panic!("Expected on-chain payment but got Bolt11");
16621662
},
1663-
Ok(QrPaymentResult::Onchain { txid }) => {
1663+
Ok(UnifiedPaymentResult::Onchain { txid }) => {
16641664
println!("\nOn-chain transaction successful with Txid: {}", txid);
16651665
txid
16661666
},

0 commit comments

Comments
 (0)