Skip to content

Commit 80b87e6

Browse files
committed
Rename UnifiedQRPayment to UnifiedPayment
Rename the UnifiedQRPayment handler 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 5a353b8 commit 80b87e6

File tree

6 files changed

+59
-48
lines changed

6 files changed

+59
-48
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 {
@@ -456,7 +456,7 @@ interface PaymentKind {
456456
};
457457

458458
[Enum]
459-
interface QrPaymentResult {
459+
interface UnifiedPaymentResult {
460460
Onchain(Txid txid);
461461
Bolt11(PaymentId payment_id);
462462
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;
@@ -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: 9 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>,
@@ -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.

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, Event, NodeError};
3535
use lightning::ln::channelmanager::PaymentId;
@@ -1545,15 +1545,15 @@ async fn generate_bip21_uri() {
15451545

15461546
// Test 1: Verify URI generation (on-chain + BOLT11) works
15471547
// even before any channels are opened. This checks the graceful fallback behavior.
1548-
let initial_uqr_payment = node_b
1549-
.unified_qr_payment()
1548+
let initial_uni_payment = node_b
1549+
.unified_payment()
15501550
.receive(expected_amount_sats, "asdf", expiry_sec)
15511551
.expect("Failed to generate URI");
1552-
println!("Initial URI (no channels): {}", initial_uqr_payment);
1552+
println!("Initial URI (no channels): {}", initial_uni_payment);
15531553

1554-
assert!(initial_uqr_payment.contains("bitcoin:"));
1555-
assert!(initial_uqr_payment.contains("lightning="));
1556-
assert!(!initial_uqr_payment.contains("lno=")); // BOLT12 requires channels
1554+
assert!(initial_uni_payment.contains("bitcoin:"));
1555+
assert!(initial_uni_payment.contains("lightning="));
1556+
assert!(!initial_uni_payment.contains("lno=")); // BOLT12 requires channels
15571557

15581558
premine_and_distribute_funds(
15591559
&bitcoind.client,
@@ -1574,15 +1574,15 @@ async fn generate_bip21_uri() {
15741574
expect_channel_ready_event!(node_b, node_a.node_id());
15751575

15761576
// Test 2: Verify URI generation (on-chain + BOLT11 + BOLT12) works after channels are established.
1577-
let uqr_payment = node_b
1578-
.unified_qr_payment()
1577+
let uni_payment = node_b
1578+
.unified_payment()
15791579
.receive(expected_amount_sats, "asdf", expiry_sec)
15801580
.expect("Failed to generate URI");
15811581

1582-
println!("Generated URI: {}", uqr_payment);
1583-
assert!(uqr_payment.contains("bitcoin:"));
1584-
assert!(uqr_payment.contains("lightning="));
1585-
assert!(uqr_payment.contains("lno="));
1582+
println!("Generated URI: {}", uni_payment);
1583+
assert!(uni_payment.contains("bitcoin:"));
1584+
assert!(uni_payment.contains("lightning="));
1585+
assert!(uni_payment.contains("lno="));
15861586
}
15871587

15881588
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
@@ -1624,17 +1624,17 @@ async fn unified_qr_send_receive() {
16241624
let expected_amount_sats = 100_000;
16251625
let expiry_sec = 4_000;
16261626

1627-
let uqr_payment = node_b.unified_qr_payment().receive(expected_amount_sats, "asdf", expiry_sec);
1628-
let uri_str = uqr_payment.clone().unwrap();
1629-
let offer_payment_id: PaymentId = match node_a.unified_qr_payment().send(&uri_str, None) {
1630-
Ok(QrPaymentResult::Bolt12 { payment_id }) => {
1627+
let uni_payment = node_b.unified_payment().receive(expected_amount_sats, "asdf", expiry_sec);
1628+
let uri_str = uni_payment.clone().unwrap();
1629+
let offer_payment_id: PaymentId = match node_a.unified_payment().send(&uri_str, None) {
1630+
Ok(UnifiedPaymentResult::Bolt12 { payment_id }) => {
16311631
println!("\nBolt12 payment sent successfully with PaymentID: {:?}", payment_id);
16321632
payment_id
16331633
},
1634-
Ok(QrPaymentResult::Bolt11 { payment_id: _ }) => {
1634+
Ok(UnifiedPaymentResult::Bolt11 { payment_id: _ }) => {
16351635
panic!("Expected Bolt12 payment but got Bolt11");
16361636
},
1637-
Ok(QrPaymentResult::Onchain { txid: _ }) => {
1637+
Ok(UnifiedPaymentResult::Onchain { txid: _ }) => {
16381638
panic!("Expected Bolt12 payment but get On-chain transaction");
16391639
},
16401640
Err(e) => {
@@ -1647,15 +1647,15 @@ async fn unified_qr_send_receive() {
16471647
// Cut off the BOLT12 part to fallback to BOLT11.
16481648
let uri_str_without_offer = uri_str.split("&lno=").next().unwrap();
16491649
let invoice_payment_id: PaymentId =
1650-
match node_a.unified_qr_payment().send(uri_str_without_offer, None) {
1651-
Ok(QrPaymentResult::Bolt12 { payment_id: _ }) => {
1650+
match node_a.unified_payment().send(uri_str_without_offer, None) {
1651+
Ok(UnifiedPaymentResult::Bolt12 { payment_id: _ }) => {
16521652
panic!("Expected Bolt11 payment but got Bolt12");
16531653
},
1654-
Ok(QrPaymentResult::Bolt11 { payment_id }) => {
1654+
Ok(UnifiedPaymentResult::Bolt11 { payment_id }) => {
16551655
println!("\nBolt11 payment sent successfully with PaymentID: {:?}", payment_id);
16561656
payment_id
16571657
},
1658-
Ok(QrPaymentResult::Onchain { txid: _ }) => {
1658+
Ok(UnifiedPaymentResult::Onchain { txid: _ }) => {
16591659
panic!("Expected Bolt11 payment but got on-chain transaction");
16601660
},
16611661
Err(e) => {
@@ -1665,19 +1665,19 @@ async fn unified_qr_send_receive() {
16651665
expect_payment_successful_event!(node_a, Some(invoice_payment_id), None);
16661666

16671667
let expect_onchain_amount_sats = 800_000;
1668-
let onchain_uqr_payment =
1669-
node_b.unified_qr_payment().receive(expect_onchain_amount_sats, "asdf", 4_000).unwrap();
1668+
let onchain_uni_payment =
1669+
node_b.unified_payment().receive(expect_onchain_amount_sats, "asdf", 4_000).unwrap();
16701670

16711671
// Cut off any lightning part to fallback to on-chain only.
1672-
let uri_str_without_lightning = onchain_uqr_payment.split("&lightning=").next().unwrap();
1673-
let txid = match node_a.unified_qr_payment().send(&uri_str_without_lightning, None) {
1674-
Ok(QrPaymentResult::Bolt12 { payment_id: _ }) => {
1672+
let uri_str_without_lightning = onchain_uni_payment.split("&lightning=").next().unwrap();
1673+
let txid = match node_a.unified_payment().send(&uri_str_without_lightning, None) {
1674+
Ok(UnifiedPaymentResult::Bolt12 { payment_id: _ }) => {
16751675
panic!("Expected on-chain payment but got Bolt12")
16761676
},
1677-
Ok(QrPaymentResult::Bolt11 { payment_id: _ }) => {
1677+
Ok(UnifiedPaymentResult::Bolt11 { payment_id: _ }) => {
16781678
panic!("Expected on-chain payment but got Bolt11");
16791679
},
1680-
Ok(QrPaymentResult::Onchain { txid }) => {
1680+
Ok(UnifiedPaymentResult::Onchain { txid }) => {
16811681
println!("\nOn-chain transaction successful with Txid: {}", txid);
16821682
txid
16831683
},

0 commit comments

Comments
 (0)