Skip to content

Commit 10da0bf

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 dd725bc commit 10da0bf

File tree

6 files changed

+122
-76
lines changed

6 files changed

+122
-76
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);
259+
UnifiedPaymentResult send([ByRef]string uri_str);
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: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,51 @@ 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::chain::channelmonitor::BalanceSource;
60+
pub use lightning::events::{ClosureReason, PaymentFailureReason};
61+
pub use lightning::ln::types::ChannelId;
62+
pub use lightning::offers::offer::OfferId;
63+
pub use lightning::routing::gossip::{NodeAlias, NodeId, RoutingFees};
64+
pub use lightning::routing::router::RouteParametersConfig;
65+
pub use lightning_types::string::UntrustedString;
66+
67+
pub use lightning_types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
68+
69+
pub use lightning_invoice::{Description, SignedRawBolt11Invoice};
70+
71+
pub use lightning_liquidity::lsps0::ser::LSPSDateTime;
72+
pub use lightning_liquidity::lsps1::msgs::{
73+
LSPS1ChannelInfo, LSPS1OrderId, LSPS1OrderParams, LSPS1PaymentState,
74+
};
75+
76+
pub use bitcoin::{Address, BlockHash, FeeRate, Network, OutPoint, Txid};
77+
78+
pub use bip39::Mnemonic;
79+
80+
pub use vss_client::headers::{VssHeaderProvider, VssHeaderProviderError};
81+
82+
use crate::builder::sanitize_alias;
83+
use crate::error::Error;
5884
use crate::{hex_utils, SocketAddress, UniffiCustomTypeConverter, UserChannelId};
5985

86+
use bitcoin::hashes::sha256::Hash as Sha256;
87+
use bitcoin::hashes::Hash;
88+
use bitcoin::secp256k1::PublicKey;
89+
use lightning::ln::channelmanager::PaymentId;
90+
use lightning::offers::invoice::Bolt12Invoice as LdkBolt12Invoice;
91+
use lightning::offers::offer::{Amount as LdkAmount, Offer as LdkOffer};
92+
use lightning::offers::refund::Refund as LdkRefund;
93+
use lightning::util::ser::Writeable;
94+
use lightning_invoice::{Bolt11Invoice as LdkBolt11Invoice, Bolt11InvoiceDescriptionRef};
95+
96+
use std::convert::TryInto;
97+
use std::ops::Deref;
98+
use std::str::FromStr;
99+
use std::sync::Arc;
100+
use std::time::Duration;
101+
60102
impl UniffiCustomTypeConverter for PublicKey {
61103
type Builtin = String;
62104

src/lib.rs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -131,25 +131,13 @@ use gossip::GossipSource;
131131
use graph::NetworkGraph;
132132
pub use io::utils::generate_entropy_mnemonic;
133133
use io::utils::write_node_metrics;
134-
use lightning::chain::BestBlock;
135-
use lightning::events::bump_transaction::Wallet as LdkWallet;
136-
use lightning::impl_writeable_tlv_based;
137-
use lightning::ln::channel_state::ChannelShutdownState;
138-
use lightning::ln::channelmanager::PaymentId;
139-
use lightning::ln::msgs::SocketAddress;
140-
use lightning::routing::gossip::NodeAlias;
141-
use lightning::util::persist::KVStoreSync;
142-
use lightning_background_processor::process_events_async;
143134
use liquidity::{LSPS1Liquidity, LiquiditySource};
144-
use logger::{log_debug, log_error, log_info, log_trace, LdkLogger, Logger};
145-
use payment::asynchronous::om_mailbox::OnionMessageMailbox;
146135
use payment::asynchronous::static_invoice_store::StaticInvoiceStore;
147136
use payment::{
148137
Bolt11Payment, Bolt12Payment, OnchainPayment, PaymentDetails, SpontaneousPayment,
149-
UnifiedQrPayment,
138+
UnifiedPayment,
150139
};
151140
use peer_store::{PeerInfo, PeerStore};
152-
use rand::Rng;
153141
use runtime::Runtime;
154142
use types::{
155143
Broadcaster, BumpTransactionEventHandler, ChainMonitor, ChannelManager, Graph, KeysManager,
@@ -159,6 +147,18 @@ pub use types::{
159147
ChannelDetails, CustomTlvRecord, DynStore, PeerDetails, SyncAndAsyncKVStore, UserChannelId,
160148
};
161149

150+
use lightning::chain::BestBlock;
151+
use lightning::events::bump_transaction::Wallet as LdkWallet;
152+
use lightning::impl_writeable_tlv_based;
153+
use lightning::ln::channel_state::ChannelShutdownState;
154+
use lightning::ln::channelmanager::PaymentId;
155+
use lightning::ln::msgs::SocketAddress;
156+
use lightning::routing::gossip::NodeAlias;
157+
use lightning::util::persist::KVStoreSync;
158+
use lightning_background_processor::process_events_async;
159+
use logger::{log_debug, log_error, log_info, log_trace, LdkLogger, Logger};
160+
use payment::asynchronous::om_mailbox::OnionMessageMailbox;
161+
use rand::Rng;
162162
pub use {
163163
bip39, bitcoin, lightning, lightning_invoice, lightning_liquidity, lightning_types, tokio,
164164
vss_client,
@@ -927,12 +927,15 @@ impl Node {
927927
/// Returns a payment handler allowing to create [BIP 21] URIs with an on-chain, [BOLT 11],
928928
/// and [BOLT 12] payment options.
929929
///
930+
/// This handler allows you to send payments to these URIs as well as [BIP 353] HRNs.
931+
///
930932
/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
931933
/// [BOLT 12]: https://github.com/lightning/bolts/blob/master/12-offer-encoding.md
932934
/// [BIP 21]: https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki
935+
/// [BIP 353]: https://github.com/bitcoin/bips/blob/master/bip-0353.mediawiki
933936
#[cfg(not(feature = "uniffi"))]
934-
pub fn unified_qr_payment(&self) -> UnifiedQrPayment {
935-
UnifiedQrPayment::new(
937+
pub fn unified_payment(&self) -> UnifiedPayment {
938+
UnifiedPayment::new(
936939
self.onchain_payment().into(),
937940
self.bolt11_payment().into(),
938941
self.bolt12_payment().into(),
@@ -944,12 +947,15 @@ impl Node {
944947
/// Returns a payment handler allowing to create [BIP 21] URIs with an on-chain, [BOLT 11],
945948
/// and [BOLT 12] payment options.
946949
///
950+
/// This handler allows you to send payments to these URIs as well as [BIP 353] HRNs.
951+
///
947952
/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
948953
/// [BOLT 12]: https://github.com/lightning/bolts/blob/master/12-offer-encoding.md
949954
/// [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
950956
#[cfg(feature = "uniffi")]
951-
pub fn unified_qr_payment(&self) -> Arc<UnifiedQrPayment> {
952-
Arc::new(UnifiedQrPayment::new(
957+
pub fn unified_payment(&self) -> Arc<UnifiedPayment> {
958+
Arc::new(UnifiedPayment::new(
953959
self.onchain_payment(),
954960
self.bolt11_payment(),
955961
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 & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ struct Extras {
4545
/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
4646
/// [BOLT 12]: https://github.com/lightning/bolts/blob/master/12-offer-encoding.md
4747
/// [`Node::unified_qr_payment`]: crate::Node::unified_qr_payment
48-
pub struct UnifiedQrPayment {
48+
pub struct UnifiedPayment {
4949
onchain_payment: Arc<OnchainPayment>,
5050
bolt11_invoice: Arc<Bolt11Payment>,
5151
bolt12_payment: Arc<Bolt12Payment>,
5252
config: Arc<Config>,
5353
logger: Arc<Logger>,
5454
}
5555

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

@@ -148,15 +148,15 @@ impl UnifiedQrPayment {
148148
if let Some(offer) = uri_network_checked.extras.bolt12_offer {
149149
let offer = maybe_wrap(offer);
150150
match self.bolt12_payment.send(&offer, None, None) {
151-
Ok(payment_id) => return Ok(QrPaymentResult::Bolt12 { payment_id }),
151+
Ok(payment_id) => return Ok(UnifiedPaymentResult::Bolt12 { payment_id }),
152152
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),
153153
}
154154
}
155155

156156
if let Some(invoice) = uri_network_checked.extras.bolt11_invoice {
157157
let invoice = maybe_wrap(invoice);
158158
match self.bolt11_invoice.send(&invoice, None) {
159-
Ok(payment_id) => return Ok(QrPaymentResult::Bolt11 { payment_id }),
159+
Ok(payment_id) => return Ok(UnifiedPaymentResult::Bolt11 { payment_id }),
160160
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),
161161
}
162162
}
@@ -175,7 +175,7 @@ impl UnifiedQrPayment {
175175
None,
176176
)?;
177177

178-
Ok(QrPaymentResult::Onchain { txid })
178+
Ok(UnifiedPaymentResult::Onchain { txid })
179179
}
180180
}
181181

@@ -188,7 +188,7 @@ impl UnifiedQrPayment {
188188
/// [`PaymentId`]: lightning::ln::channelmanager::PaymentId
189189
/// [`Txid`]: bitcoin::hash_types::Txid
190190
#[derive(Debug)]
191-
pub enum QrPaymentResult {
191+
pub enum UnifiedPaymentResult {
192192
/// An on-chain payment.
193193
Onchain {
194194
/// The transaction ID (txid) of the on-chain payment.
@@ -302,9 +302,8 @@ impl DeserializationError for Extras {
302302

303303
#[cfg(test)]
304304
mod tests {
305-
use super::*;
306-
use crate::payment::unified::Extras;
307-
use bitcoin::{Address, Network};
305+
use super::{Amount, Bolt11Invoice, Extras, Offer};
306+
use bitcoin::{address::NetworkUnchecked, Address, Network};
308307
use std::str::FromStr;
309308

310309
#[test]

tests/integration_tests_rust.rs

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// accordance with one or both of these licenses.
77

88
mod common;
9-
9+
use lightning::util::persist::KVStoreSync;
1010
use std::collections::HashSet;
1111
use std::str::FromStr;
1212
use std::sync::Arc;
@@ -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;
@@ -1392,15 +1392,15 @@ async fn generate_bip21_uri() {
13921392

13931393
// Test 1: Verify URI generation (on-chain + BOLT11) works
13941394
// even before any channels are opened. This checks the graceful fallback behavior.
1395-
let initial_uqr_payment = node_b
1396-
.unified_qr_payment()
1395+
let initial_uni_payment = node_b
1396+
.unified_payment()
13971397
.receive(expected_amount_sats, "asdf", expiry_sec)
13981398
.expect("Failed to generate URI");
1399-
println!("Initial URI (no channels): {}", initial_uqr_payment);
1399+
println!("Initial URI (no channels): {}", initial_uni_payment);
14001400

1401-
assert!(initial_uqr_payment.contains("bitcoin:"));
1402-
assert!(initial_uqr_payment.contains("lightning="));
1403-
assert!(!initial_uqr_payment.contains("lno=")); // BOLT12 requires channels
1401+
assert!(initial_uni_payment.contains("bitcoin:"));
1402+
assert!(initial_uni_payment.contains("lightning="));
1403+
assert!(!initial_uni_payment.contains("lno=")); // BOLT12 requires channels
14041404

14051405
premine_and_distribute_funds(
14061406
&bitcoind.client,
@@ -1421,15 +1421,15 @@ async fn generate_bip21_uri() {
14211421
expect_channel_ready_event!(node_b, node_a.node_id());
14221422

14231423
// Test 2: Verify URI generation (on-chain + BOLT11 + BOLT12) works after channels are established.
1424-
let uqr_payment = node_b
1425-
.unified_qr_payment()
1424+
let uni_payment = node_b
1425+
.unified_payment()
14261426
.receive(expected_amount_sats, "asdf", expiry_sec)
14271427
.expect("Failed to generate URI");
14281428

1429-
println!("Generated URI: {}", uqr_payment);
1430-
assert!(uqr_payment.contains("bitcoin:"));
1431-
assert!(uqr_payment.contains("lightning="));
1432-
assert!(uqr_payment.contains("lno="));
1429+
println!("Generated URI: {}", uni_payment);
1430+
assert!(uni_payment.contains("bitcoin:"));
1431+
assert!(uni_payment.contains("lightning="));
1432+
assert!(uni_payment.contains("lno="));
14331433
}
14341434

14351435
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
@@ -1471,17 +1471,17 @@ async fn unified_qr_send_receive() {
14711471
let expected_amount_sats = 100_000;
14721472
let expiry_sec = 4_000;
14731473

1474-
let uqr_payment = node_b.unified_qr_payment().receive(expected_amount_sats, "asdf", expiry_sec);
1475-
let uri_str = uqr_payment.clone().unwrap();
1476-
let offer_payment_id: PaymentId = match node_a.unified_qr_payment().send(&uri_str) {
1477-
Ok(QrPaymentResult::Bolt12 { payment_id }) => {
1474+
let uni_payment = node_b.unified_payment().receive(expected_amount_sats, "asdf", expiry_sec);
1475+
let uri_str = uni_payment.clone().unwrap();
1476+
let offer_payment_id: PaymentId = match node_a.unified_payment().send(&uri_str) {
1477+
Ok(UnifiedPaymentResult::Bolt12 { payment_id }) => {
14781478
println!("\nBolt12 payment sent successfully with PaymentID: {:?}", payment_id);
14791479
payment_id
14801480
},
1481-
Ok(QrPaymentResult::Bolt11 { payment_id: _ }) => {
1481+
Ok(UnifiedPaymentResult::Bolt11 { payment_id: _ }) => {
14821482
panic!("Expected Bolt12 payment but got Bolt11");
14831483
},
1484-
Ok(QrPaymentResult::Onchain { txid: _ }) => {
1484+
Ok(UnifiedPaymentResult::Onchain { txid: _ }) => {
14851485
panic!("Expected Bolt12 payment but get On-chain transaction");
14861486
},
14871487
Err(e) => {
@@ -1493,38 +1493,37 @@ async fn unified_qr_send_receive() {
14931493

14941494
// Cut off the BOLT12 part to fallback to BOLT11.
14951495
let uri_str_without_offer = uri_str.split("&lno=").next().unwrap();
1496-
let invoice_payment_id: PaymentId =
1497-
match node_a.unified_qr_payment().send(uri_str_without_offer) {
1498-
Ok(QrPaymentResult::Bolt12 { payment_id: _ }) => {
1499-
panic!("Expected Bolt11 payment but got Bolt12");
1500-
},
1501-
Ok(QrPaymentResult::Bolt11 { payment_id }) => {
1502-
println!("\nBolt11 payment sent successfully with PaymentID: {:?}", payment_id);
1503-
payment_id
1504-
},
1505-
Ok(QrPaymentResult::Onchain { txid: _ }) => {
1506-
panic!("Expected Bolt11 payment but got on-chain transaction");
1507-
},
1508-
Err(e) => {
1509-
panic!("Expected Bolt11 payment but got error: {:?}", e);
1510-
},
1511-
};
1496+
let invoice_payment_id: PaymentId = match node_a.unified_payment().send(uri_str_without_offer) {
1497+
Ok(UnifiedPaymentResult::Bolt12 { payment_id: _ }) => {
1498+
panic!("Expected Bolt11 payment but got Bolt12");
1499+
},
1500+
Ok(UnifiedPaymentResult::Bolt11 { payment_id }) => {
1501+
println!("\nBolt11 payment sent successfully with PaymentID: {:?}", payment_id);
1502+
payment_id
1503+
},
1504+
Ok(UnifiedPaymentResult::Onchain { txid: _ }) => {
1505+
panic!("Expected Bolt11 payment but got on-chain transaction");
1506+
},
1507+
Err(e) => {
1508+
panic!("Expected Bolt11 payment but got error: {:?}", e);
1509+
},
1510+
};
15121511
expect_payment_successful_event!(node_a, Some(invoice_payment_id), None);
15131512

15141513
let expect_onchain_amount_sats = 800_000;
1515-
let onchain_uqr_payment =
1516-
node_b.unified_qr_payment().receive(expect_onchain_amount_sats, "asdf", 4_000).unwrap();
1514+
let onchain_uni_payment =
1515+
node_b.unified_payment().receive(expect_onchain_amount_sats, "asdf", 4_000).unwrap();
15171516

15181517
// Cut off any lightning part to fallback to on-chain only.
1519-
let uri_str_without_lightning = onchain_uqr_payment.split("&lightning=").next().unwrap();
1520-
let txid = match node_a.unified_qr_payment().send(&uri_str_without_lightning) {
1521-
Ok(QrPaymentResult::Bolt12 { payment_id: _ }) => {
1518+
let uri_str_without_lightning = onchain_uni_payment.split("&lightning=").next().unwrap();
1519+
let txid = match node_a.unified_payment().send(&uri_str_without_lightning) {
1520+
Ok(UnifiedPaymentResult::Bolt12 { payment_id: _ }) => {
15221521
panic!("Expected on-chain payment but got Bolt12")
15231522
},
1524-
Ok(QrPaymentResult::Bolt11 { payment_id: _ }) => {
1523+
Ok(UnifiedPaymentResult::Bolt11 { payment_id: _ }) => {
15251524
panic!("Expected on-chain payment but got Bolt11");
15261525
},
1527-
Ok(QrPaymentResult::Onchain { txid }) => {
1526+
Ok(UnifiedPaymentResult::Onchain { txid }) => {
15281527
println!("\nOn-chain transaction successful with Txid: {}", txid);
15291528
txid
15301529
},

0 commit comments

Comments
 (0)