Skip to content

Commit 8d58464

Browse files
committed
Add quantity param to bolt12 send
Set the quantity by the user in the `send` method. We also expose the quantity in required function calls.
1 parent f912c22 commit 8d58464

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

bindings/ldk_node.udl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ interface Bolt11Payment {
120120

121121
interface Bolt12Payment {
122122
[Throws=NodeError]
123-
PaymentId send([ByRef]Offer offer, string? payer_note);
123+
PaymentId send([ByRef]Offer offer, u64? quantity, string? payer_note);
124124
[Throws=NodeError]
125125
PaymentId send_using_amount([ByRef]Offer offer, string? payer_note, u64 amount_msat);
126126
[Throws=NodeError]

src/payment/bolt12.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,15 @@ impl Bolt12Payment {
4848
///
4949
/// If `payer_note` is `Some` it will be seen by the recipient and reflected back in the invoice
5050
/// response.
51-
pub fn send(&self, offer: &Offer, payer_note: Option<String>) -> Result<PaymentId, Error> {
51+
///
52+
/// If `quantity` is `Some` it represents the number of items requested.
53+
pub fn send(
54+
&self, offer: &Offer, quantity: Option<u64>, payer_note: Option<String>,
55+
) -> Result<PaymentId, Error> {
5256
let rt_lock = self.runtime.read().unwrap();
5357
if rt_lock.is_none() {
5458
return Err(Error::NotRunning);
5559
}
56-
57-
let quantity = None;
5860
let mut random_bytes = [0u8; 32];
5961
rand::thread_rng().fill_bytes(&mut random_bytes);
6062
let payment_id = PaymentId(random_bytes);
@@ -295,7 +297,7 @@ impl Bolt12Payment {
295297
preimage: None,
296298
secret: None,
297299
payer_note: refund.payer_note().map(|note| UntrustedString(note.to_string())),
298-
quantity,
300+
quantity: refund.quantity(),
299301
};
300302

301303
let payment = PaymentDetails::new(
@@ -349,7 +351,7 @@ impl Bolt12Payment {
349351
preimage: None,
350352
secret: None,
351353
payer_note: refund.payer_note().map(|note| UntrustedString(note.to_string())),
352-
quantity,
354+
quantity: refund.quantity(),
353355
};
354356
let payment = PaymentDetails::new(
355357
payment_id,

src/payment/unified_qr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl UnifiedQrPayment {
136136
uri.clone().require_network(self.config.network).map_err(|_| Error::InvalidNetwork)?;
137137

138138
if let Some(offer) = uri_network_checked.extras.bolt12_offer {
139-
match self.bolt12_payment.send(&offer, None) {
139+
match self.bolt12_payment.send(&offer, None, None) {
140140
Ok(payment_id) => return Ok(QrPaymentResult::Bolt12 { payment_id }),
141141
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),
142142
}

tests/integration_tests_rust.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ fn simple_bolt12_send_receive() {
425425

426426
let expected_amount_msat = 100_000_000;
427427
let offer = node_b.bolt12_payment().receive(expected_amount_msat, "asdf").unwrap();
428-
let payment_id = node_a.bolt12_payment().send(&offer, None).unwrap();
428+
let payment_id = node_a.bolt12_payment().send(&offer, None, None).unwrap();
429429

430430
expect_payment_successful_event!(node_a, Some(payment_id), None);
431431
let node_a_payments = node_a.list_payments();
@@ -523,7 +523,7 @@ fn simple_bolt12_send_receive() {
523523
let node_b_payments = node_b.list_payments_with_filter(|p| p.id == node_b_payment_id);
524524
assert_eq!(node_b_payments.len(), 1);
525525
match node_b_payments.first().unwrap().kind {
526-
PaymentKind::Bolt12Refund { hash, preimage, secret: _ , ..} => {
526+
PaymentKind::Bolt12Refund { hash, preimage, secret: _, .. } => {
527527
assert!(hash.is_some());
528528
assert!(preimage.is_some());
529529
//TODO: We should eventually set and assert the secret sender-side, too, but the BOLT12

0 commit comments

Comments
 (0)