Skip to content

Commit cf3f415

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 77a006f commit cf3f415

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
@@ -149,7 +149,7 @@ interface Node {
149149
Bolt12Payment bolt12_payment();
150150
SpontaneousPayment spontaneous_payment();
151151
OnchainPayment onchain_payment();
152-
UnifiedQrPayment unified_qr_payment();
152+
UnifiedPayment unified_payment();
153153
LSPS1Liquidity lsps1_liquidity();
154154
[Throws=NodeError]
155155
void connect(PublicKey node_id, SocketAddress address, boolean persist);
@@ -275,11 +275,11 @@ interface FeeRate {
275275
u64 to_sat_per_vb_ceil();
276276
};
277277

278-
interface UnifiedQrPayment {
278+
interface UnifiedPayment {
279279
[Throws=NodeError]
280280
string receive(u64 amount_sats, [ByRef]string message, u32 expiry_sec);
281281
[Throws=NodeError]
282-
QrPaymentResult send([ByRef]string uri_str, RouteParametersConfig? route_parameters);
282+
UnifiedPaymentResult send([ByRef]string uri_str, RouteParametersConfig? route_parameters);
283283
};
284284

285285
interface LSPS1Liquidity {
@@ -455,7 +455,7 @@ interface PaymentKind {
455455
};
456456

457457
[Enum]
458-
interface QrPaymentResult {
458+
interface UnifiedPaymentResult {
459459
Onchain(Txid txid);
460460
Bolt11(PaymentId payment_id);
461461
Bolt12(PaymentId payment_id);

src/ffi/types.rs

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

6164
impl UniffiCustomTypeConverter for PublicKey {

src/lib.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ use payment::asynchronous::om_mailbox::OnionMessageMailbox;
152152
use payment::asynchronous::static_invoice_store::StaticInvoiceStore;
153153
use payment::{
154154
Bolt11Payment, Bolt12Payment, OnchainPayment, PaymentDetails, SpontaneousPayment,
155-
UnifiedQrPayment,
155+
UnifiedPayment,
156156
};
157157
use peer_store::{PeerInfo, PeerStore};
158158
use rand::Rng;
@@ -947,12 +947,15 @@ impl Node {
947947
/// Returns a payment handler allowing to create [BIP 21] URIs with an on-chain, [BOLT 11],
948948
/// and [BOLT 12] payment options.
949949
///
950+
/// This handler allows you to send payments to these URIs as well as [BIP 353] HRNs.
951+
///
950952
/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
951953
/// [BOLT 12]: https://github.com/lightning/bolts/blob/master/12-offer-encoding.md
952954
/// [BIP 21]: https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki
955+
/// [BIP 353]: https://github.com/bitcoin/bips/blob/master/bip-0353.mediawiki
953956
#[cfg(not(feature = "uniffi"))]
954-
pub fn unified_qr_payment(&self) -> UnifiedQrPayment {
955-
UnifiedQrPayment::new(
957+
pub fn unified_payment(&self) -> UnifiedPayment {
958+
UnifiedPayment::new(
956959
self.onchain_payment().into(),
957960
self.bolt11_payment().into(),
958961
self.bolt12_payment().into(),
@@ -964,12 +967,15 @@ impl Node {
964967
/// Returns a payment handler allowing to create [BIP 21] URIs with an on-chain, [BOLT 11],
965968
/// and [BOLT 12] payment options.
966969
///
970+
/// This handler allows you to send payments to these URIs as well as [BIP 353] HRNs.
971+
///
967972
/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
968973
/// [BOLT 12]: https://github.com/lightning/bolts/blob/master/12-offer-encoding.md
969974
/// [BIP 21]: https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki
975+
/// [BIP 353]: https://github.com/bitcoin/bips/blob/master/bip-0353.mediawiki
970976
#[cfg(feature = "uniffi")]
971-
pub fn unified_qr_payment(&self) -> Arc<UnifiedQrPayment> {
972-
Arc::new(UnifiedQrPayment::new(
977+
pub fn unified_payment(&self) -> Arc<UnifiedPayment> {
978+
Arc::new(UnifiedPayment::new(
973979
self.onchain_payment(),
974980
self.bolt11_payment(),
975981
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;
@@ -1527,15 +1527,15 @@ async fn generate_bip21_uri() {
15271527

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

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

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

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

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

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

1609-
let uqr_payment = node_b.unified_qr_payment().receive(expected_amount_sats, "asdf", expiry_sec);
1610-
let uri_str = uqr_payment.clone().unwrap();
1611-
let offer_payment_id: PaymentId = match node_a.unified_qr_payment().send(&uri_str, None) {
1612-
Ok(QrPaymentResult::Bolt12 { payment_id }) => {
1609+
let uni_payment = node_b.unified_payment().receive(expected_amount_sats, "asdf", expiry_sec);
1610+
let uri_str = uni_payment.clone().unwrap();
1611+
let offer_payment_id: PaymentId = match node_a.unified_payment().send(&uri_str, None) {
1612+
Ok(UnifiedPaymentResult::Bolt12 { payment_id }) => {
16131613
println!("\nBolt12 payment sent successfully with PaymentID: {:?}", payment_id);
16141614
payment_id
16151615
},
1616-
Ok(QrPaymentResult::Bolt11 { payment_id: _ }) => {
1616+
Ok(UnifiedPaymentResult::Bolt11 { payment_id: _ }) => {
16171617
panic!("Expected Bolt12 payment but got Bolt11");
16181618
},
1619-
Ok(QrPaymentResult::Onchain { txid: _ }) => {
1619+
Ok(UnifiedPaymentResult::Onchain { txid: _ }) => {
16201620
panic!("Expected Bolt12 payment but get On-chain transaction");
16211621
},
16221622
Err(e) => {
@@ -1629,15 +1629,15 @@ async fn unified_qr_send_receive() {
16291629
// Cut off the BOLT12 part to fallback to BOLT11.
16301630
let uri_str_without_offer = uri_str.split("&lno=").next().unwrap();
16311631
let invoice_payment_id: PaymentId =
1632-
match node_a.unified_qr_payment().send(uri_str_without_offer, None) {
1633-
Ok(QrPaymentResult::Bolt12 { payment_id: _ }) => {
1632+
match node_a.unified_payment().send(uri_str_without_offer, None) {
1633+
Ok(UnifiedPaymentResult::Bolt12 { payment_id: _ }) => {
16341634
panic!("Expected Bolt11 payment but got Bolt12");
16351635
},
1636-
Ok(QrPaymentResult::Bolt11 { payment_id }) => {
1636+
Ok(UnifiedPaymentResult::Bolt11 { payment_id }) => {
16371637
println!("\nBolt11 payment sent successfully with PaymentID: {:?}", payment_id);
16381638
payment_id
16391639
},
1640-
Ok(QrPaymentResult::Onchain { txid: _ }) => {
1640+
Ok(UnifiedPaymentResult::Onchain { txid: _ }) => {
16411641
panic!("Expected Bolt11 payment but got on-chain transaction");
16421642
},
16431643
Err(e) => {
@@ -1647,19 +1647,19 @@ async fn unified_qr_send_receive() {
16471647
expect_payment_successful_event!(node_a, Some(invoice_payment_id), None);
16481648

16491649
let expect_onchain_amount_sats = 800_000;
1650-
let onchain_uqr_payment =
1651-
node_b.unified_qr_payment().receive(expect_onchain_amount_sats, "asdf", 4_000).unwrap();
1650+
let onchain_uni_payment =
1651+
node_b.unified_payment().receive(expect_onchain_amount_sats, "asdf", 4_000).unwrap();
16521652

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

0 commit comments

Comments
 (0)