Skip to content

Commit 89ac3b2

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 21b958e commit 89ac3b2

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
@@ -130,7 +130,7 @@ interface Node {
130130
Bolt12Payment bolt12_payment();
131131
SpontaneousPayment spontaneous_payment();
132132
OnchainPayment onchain_payment();
133-
UnifiedQrPayment unified_qr_payment();
133+
UnifiedPayment unified_payment();
134134
LSPS1Liquidity lsps1_liquidity();
135135
[Throws=NodeError]
136136
void connect(PublicKey node_id, SocketAddress address, boolean persist);
@@ -252,11 +252,11 @@ interface FeeRate {
252252
u64 to_sat_per_vb_ceil();
253253
};
254254

255-
interface UnifiedQrPayment {
255+
interface UnifiedPayment {
256256
[Throws=NodeError]
257257
string receive(u64 amount_sats, [ByRef]string message, u32 expiry_sec);
258258
[Throws=NodeError]
259-
QrPaymentResult send([ByRef]string uri_str, RouteParametersConfig? route_parameters);
259+
UnifiedPaymentResult send([ByRef]string uri_str, RouteParametersConfig? route_parameters);
260260
};
261261

262262
interface LSPS1Liquidity {
@@ -431,7 +431,7 @@ interface PaymentKind {
431431
};
432432

433433
[Enum]
434-
interface QrPaymentResult {
434+
interface UnifiedPaymentResult {
435435
Onchain(Txid txid);
436436
Bolt11(PaymentId payment_id);
437437
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
@@ -145,7 +145,7 @@ use payment::asynchronous::om_mailbox::OnionMessageMailbox;
145145
use payment::asynchronous::static_invoice_store::StaticInvoiceStore;
146146
use payment::{
147147
Bolt11Payment, Bolt12Payment, OnchainPayment, PaymentDetails, SpontaneousPayment,
148-
UnifiedQrPayment,
148+
UnifiedPayment,
149149
};
150150
use peer_store::{PeerInfo, PeerStore};
151151
use rand::Rng;
@@ -932,12 +932,15 @@ impl Node {
932932
/// Returns a payment handler allowing to create [BIP 21] URIs with an on-chain, [BOLT 11],
933933
/// and [BOLT 12] payment options.
934934
///
935+
/// This handler allows you to send payments to these URIs as well as [BIP 353] HRNs.
936+
///
935937
/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
936938
/// [BOLT 12]: https://github.com/lightning/bolts/blob/master/12-offer-encoding.md
937939
/// [BIP 21]: https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki
940+
/// [BIP 353]: https://github.com/bitcoin/bips/blob/master/bip-0353.mediawiki
938941
#[cfg(not(feature = "uniffi"))]
939-
pub fn unified_qr_payment(&self) -> UnifiedQrPayment {
940-
UnifiedQrPayment::new(
942+
pub fn unified_payment(&self) -> UnifiedPayment {
943+
UnifiedPayment::new(
941944
self.onchain_payment().into(),
942945
self.bolt11_payment().into(),
943946
self.bolt12_payment().into(),
@@ -949,12 +952,15 @@ impl Node {
949952
/// Returns a payment handler allowing to create [BIP 21] URIs with an on-chain, [BOLT 11],
950953
/// and [BOLT 12] payment options.
951954
///
955+
/// This handler allows you to send payments to these URIs as well as [BIP 353] HRNs.
956+
///
952957
/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
953958
/// [BOLT 12]: https://github.com/lightning/bolts/blob/master/12-offer-encoding.md
954959
/// [BIP 21]: https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki
960+
/// [BIP 353]: https://github.com/bitcoin/bips/blob/master/bip-0353.mediawiki
955961
#[cfg(feature = "uniffi")]
956-
pub fn unified_qr_payment(&self) -> Arc<UnifiedQrPayment> {
957-
Arc::new(UnifiedQrPayment::new(
962+
pub fn unified_payment(&self) -> Arc<UnifiedPayment> {
963+
Arc::new(UnifiedPayment::new(
958964
self.onchain_payment(),
959965
self.bolt11_payment(),
960966
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;
@@ -1399,15 +1399,15 @@ async fn generate_bip21_uri() {
13991399

14001400
// Test 1: Verify URI generation (on-chain + BOLT11) works
14011401
// even before any channels are opened. This checks the graceful fallback behavior.
1402-
let initial_uqr_payment = node_b
1403-
.unified_qr_payment()
1402+
let initial_uni_payment = node_b
1403+
.unified_payment()
14041404
.receive(expected_amount_sats, "asdf", expiry_sec)
14051405
.expect("Failed to generate URI");
1406-
println!("Initial URI (no channels): {}", initial_uqr_payment);
1406+
println!("Initial URI (no channels): {}", initial_uni_payment);
14071407

1408-
assert!(initial_uqr_payment.contains("bitcoin:"));
1409-
assert!(initial_uqr_payment.contains("lightning="));
1410-
assert!(!initial_uqr_payment.contains("lno=")); // BOLT12 requires channels
1408+
assert!(initial_uni_payment.contains("bitcoin:"));
1409+
assert!(initial_uni_payment.contains("lightning="));
1410+
assert!(!initial_uni_payment.contains("lno=")); // BOLT12 requires channels
14111411

14121412
premine_and_distribute_funds(
14131413
&bitcoind.client,
@@ -1428,15 +1428,15 @@ async fn generate_bip21_uri() {
14281428
expect_channel_ready_event!(node_b, node_a.node_id());
14291429

14301430
// Test 2: Verify URI generation (on-chain + BOLT11 + BOLT12) works after channels are established.
1431-
let uqr_payment = node_b
1432-
.unified_qr_payment()
1431+
let uni_payment = node_b
1432+
.unified_payment()
14331433
.receive(expected_amount_sats, "asdf", expiry_sec)
14341434
.expect("Failed to generate URI");
14351435

1436-
println!("Generated URI: {}", uqr_payment);
1437-
assert!(uqr_payment.contains("bitcoin:"));
1438-
assert!(uqr_payment.contains("lightning="));
1439-
assert!(uqr_payment.contains("lno="));
1436+
println!("Generated URI: {}", uni_payment);
1437+
assert!(uni_payment.contains("bitcoin:"));
1438+
assert!(uni_payment.contains("lightning="));
1439+
assert!(uni_payment.contains("lno="));
14401440
}
14411441

14421442
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
@@ -1478,17 +1478,17 @@ async fn unified_qr_send_receive() {
14781478
let expected_amount_sats = 100_000;
14791479
let expiry_sec = 4_000;
14801480

1481-
let uqr_payment = node_b.unified_qr_payment().receive(expected_amount_sats, "asdf", expiry_sec);
1482-
let uri_str = uqr_payment.clone().unwrap();
1483-
let offer_payment_id: PaymentId = match node_a.unified_qr_payment().send(&uri_str, None) {
1484-
Ok(QrPaymentResult::Bolt12 { payment_id }) => {
1481+
let uni_payment = node_b.unified_payment().receive(expected_amount_sats, "asdf", expiry_sec);
1482+
let uri_str = uni_payment.clone().unwrap();
1483+
let offer_payment_id: PaymentId = match node_a.unified_payment().send(&uri_str, None) {
1484+
Ok(UnifiedPaymentResult::Bolt12 { payment_id }) => {
14851485
println!("\nBolt12 payment sent successfully with PaymentID: {:?}", payment_id);
14861486
payment_id
14871487
},
1488-
Ok(QrPaymentResult::Bolt11 { payment_id: _ }) => {
1488+
Ok(UnifiedPaymentResult::Bolt11 { payment_id: _ }) => {
14891489
panic!("Expected Bolt12 payment but got Bolt11");
14901490
},
1491-
Ok(QrPaymentResult::Onchain { txid: _ }) => {
1491+
Ok(UnifiedPaymentResult::Onchain { txid: _ }) => {
14921492
panic!("Expected Bolt12 payment but get On-chain transaction");
14931493
},
14941494
Err(e) => {
@@ -1501,15 +1501,15 @@ async fn unified_qr_send_receive() {
15011501
// Cut off the BOLT12 part to fallback to BOLT11.
15021502
let uri_str_without_offer = uri_str.split("&lno=").next().unwrap();
15031503
let invoice_payment_id: PaymentId =
1504-
match node_a.unified_qr_payment().send(uri_str_without_offer, None) {
1505-
Ok(QrPaymentResult::Bolt12 { payment_id: _ }) => {
1504+
match node_a.unified_payment().send(uri_str_without_offer, None) {
1505+
Ok(UnifiedPaymentResult::Bolt12 { payment_id: _ }) => {
15061506
panic!("Expected Bolt11 payment but got Bolt12");
15071507
},
1508-
Ok(QrPaymentResult::Bolt11 { payment_id }) => {
1508+
Ok(UnifiedPaymentResult::Bolt11 { payment_id }) => {
15091509
println!("\nBolt11 payment sent successfully with PaymentID: {:?}", payment_id);
15101510
payment_id
15111511
},
1512-
Ok(QrPaymentResult::Onchain { txid: _ }) => {
1512+
Ok(UnifiedPaymentResult::Onchain { txid: _ }) => {
15131513
panic!("Expected Bolt11 payment but got on-chain transaction");
15141514
},
15151515
Err(e) => {
@@ -1519,19 +1519,19 @@ async fn unified_qr_send_receive() {
15191519
expect_payment_successful_event!(node_a, Some(invoice_payment_id), None);
15201520

15211521
let expect_onchain_amount_sats = 800_000;
1522-
let onchain_uqr_payment =
1523-
node_b.unified_qr_payment().receive(expect_onchain_amount_sats, "asdf", 4_000).unwrap();
1522+
let onchain_uni_payment =
1523+
node_b.unified_payment().receive(expect_onchain_amount_sats, "asdf", 4_000).unwrap();
15241524

15251525
// Cut off any lightning part to fallback to on-chain only.
1526-
let uri_str_without_lightning = onchain_uqr_payment.split("&lightning=").next().unwrap();
1527-
let txid = match node_a.unified_qr_payment().send(&uri_str_without_lightning, None) {
1528-
Ok(QrPaymentResult::Bolt12 { payment_id: _ }) => {
1526+
let uri_str_without_lightning = onchain_uni_payment.split("&lightning=").next().unwrap();
1527+
let txid = match node_a.unified_payment().send(&uri_str_without_lightning, None) {
1528+
Ok(UnifiedPaymentResult::Bolt12 { payment_id: _ }) => {
15291529
panic!("Expected on-chain payment but got Bolt12")
15301530
},
1531-
Ok(QrPaymentResult::Bolt11 { payment_id: _ }) => {
1531+
Ok(UnifiedPaymentResult::Bolt11 { payment_id: _ }) => {
15321532
panic!("Expected on-chain payment but got Bolt11");
15331533
},
1534-
Ok(QrPaymentResult::Onchain { txid }) => {
1534+
Ok(UnifiedPaymentResult::Onchain { txid }) => {
15351535
println!("\nOn-chain transaction successful with Txid: {}", txid);
15361536
txid
15371537
},

0 commit comments

Comments
 (0)