Skip to content

Commit d4a92b0

Browse files
committed
Add payer_id quantity fields
In this commit I exposed the payer_id and quantity fields to PaymentKind::Bolt12Offer and PaymentKind::Bolt12Refund. As of right now, I'm unsure how to access payer_id in bolt12.rs. At first thought I was going to use payee_pubkey but I imagine that isn't the payers publickey we want.
1 parent a903103 commit d4a92b0

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

bindings/ldk_node.udl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ interface PaymentKind {
281281
Onchain();
282282
Bolt11(PaymentHash hash, PaymentPreimage? preimage, PaymentSecret? secret);
283283
Bolt11Jit(PaymentHash hash, PaymentPreimage? preimage, PaymentSecret? secret, LSPFeeLimits lsp_fee_limits);
284-
Bolt12Offer(PaymentHash? hash, PaymentPreimage? preimage, PaymentSecret? secret, OfferId offer_id, UntrustedString? payer_note);
285-
Bolt12Refund(PaymentHash? hash, PaymentPreimage? preimage, PaymentSecret? secret, UntrustedString? payer_note);
284+
Bolt12Offer(PaymentHash? hash, PaymentPreimage? preimage, PaymentSecret? secret, OfferId offer_id, UntrustedString? payer_note, PublicKey? payer_id, u64? quantity);
285+
Bolt12Refund(PaymentHash? hash, PaymentPreimage? preimage, PaymentSecret? secret, UntrustedString? payer_note, PublicKey? payer_id, u64? quantity);
286286
Spontaneous(PaymentHash hash, PaymentPreimage? preimage);
287287
};
288288

src/event.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,14 +597,18 @@ where
597597
payment_context,
598598
..
599599
} => {
600-
let payer_note = payment_context.invoice_request.payer_note_truncated;
601600
let offer_id = payment_context.offer_id;
601+
let payer_note = payment_context.invoice_request.payer_note_truncated;
602+
let payer_id = payment_context.invoice_request.payer_id;
603+
let quantity = payment_context.invoice_request.quantity;
602604
let kind = PaymentKind::Bolt12Offer {
603605
hash: Some(payment_hash),
604606
preimage: payment_preimage,
605607
secret: Some(payment_secret),
606608
offer_id,
607609
payer_note,
610+
payer_id: Some(payer_id),
611+
quantity,
608612
};
609613

610614
let payment = PaymentDetails::new(

src/payment/bolt12.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ impl Bolt12Payment {
9797
secret: None,
9898
offer_id: offer.id(),
9999
payer_note: payer_note.map(UntrustedString),
100+
payer_id: None,
101+
quantity,
100102
};
101103
let payment = PaymentDetails::new(
102104
payment_id,
@@ -120,6 +122,8 @@ impl Bolt12Payment {
120122
secret: None,
121123
offer_id: offer.id(),
122124
payer_note: payer_note.map(UntrustedString),
125+
payer_id: None,
126+
quantity,
123127
};
124128
let payment = PaymentDetails::new(
125129
payment_id,
@@ -200,6 +204,8 @@ impl Bolt12Payment {
200204
secret: None,
201205
offer_id: offer.id(),
202206
payer_note: payer_note.map(UntrustedString),
207+
payer_id: None,
208+
quantity,
203209
};
204210
let payment = PaymentDetails::new(
205211
payment_id,
@@ -223,6 +229,8 @@ impl Bolt12Payment {
223229
secret: None,
224230
offer_id: offer.id(),
225231
payer_note: payer_note.map(UntrustedString),
232+
payer_id: None,
233+
quantity,
226234
};
227235
let payment = PaymentDetails::new(
228236
payment_id,
@@ -291,6 +299,8 @@ impl Bolt12Payment {
291299
preimage: None,
292300
secret: None,
293301
payer_note: refund.payer_note().map(|note| UntrustedString(note.to_string())),
302+
payer_id: None,
303+
quantity: None,
294304
};
295305

296306
let payment = PaymentDetails::new(
@@ -344,6 +354,8 @@ impl Bolt12Payment {
344354
preimage: None,
345355
secret: None,
346356
payer_note: refund.payer_note().map(|note| UntrustedString(note.to_string())),
357+
payer_id: None,
358+
quantity: None,
347359
};
348360
let payment = PaymentDetails::new(
349361
payment_id,

src/payment/store.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::logger::{log_error, Logger};
66
use crate::types::DynStore;
77
use crate::Error;
88

9+
use bitcoin::secp256k1::PublicKey;
910
use lightning::ln::channelmanager::PaymentId;
1011
use lightning::ln::msgs::DecodeError;
1112
use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret};
@@ -213,10 +214,20 @@ pub enum PaymentKind {
213214
secret: Option<PaymentSecret>,
214215
/// The ID of the offer this payment is for.
215216
offer_id: OfferId,
216-
/// The payer note for the payment.
217+
/// The payer note for the payment. Truncated to [PAYER_NOTE_LIMIT] characters.
217218
///
218219
/// This will always be `None` for payments serialized with version `v0.3.0`.
220+
///
221+
/// [PAYER_NOTE_LIMIT]: lightning::offers::invoice_request::PAYER_NOTE_LIMIT
219222
payer_note: Option<UntrustedString>,
223+
/// The payers ID for the payment.
224+
///
225+
/// This will always be `None` for payments serialized with version `v0.3.0`.
226+
payer_id: Option<PublicKey>,
227+
/// The quantity of items or units requested in the offer.
228+
///
229+
/// This will always be `None` for payments serialized with version `v0.3.0`.
230+
quantity: Option<u64>,
220231
},
221232
/// A [BOLT 12] 'refund' payment, i.e., a payment for a [`Refund`].
222233
///
@@ -233,6 +244,14 @@ pub enum PaymentKind {
233244
///
234245
/// This will always be `None` for payments serialized with version `v0.3.0`.
235246
payer_note: Option<UntrustedString>,
247+
/// The payers ID for the refund payment.
248+
///
249+
/// This will always be `None` for payments serialized with version `v0.3.0`.
250+
payer_id: Option<PublicKey>,
251+
/// The quantity of items or units requested in the offer.
252+
///
253+
/// This will always be `None` for payments serialized with version `v0.3.0`.
254+
quantity: Option<u64>,
236255
},
237256
/// A spontaneous ("keysend") payment.
238257
Spontaneous {
@@ -258,20 +277,24 @@ impl_writeable_tlv_based_enum!(PaymentKind,
258277
},
259278
(6, Bolt12Offer) => {
260279
(0, hash, option),
280+
(1, payer_note, option),
261281
(2, preimage, option),
282+
(3, payer_id, option),
262283
(4, secret, option),
284+
(5, quantity, option),
263285
(6, offer_id, required),
264-
(1, payer_note, option),
265286
},
266287
(8, Spontaneous) => {
267288
(0, hash, required),
268289
(2, preimage, option),
269290
},
270291
(10, Bolt12Refund) => {
271292
(0, hash, option),
293+
(1, payer_note, option),
272294
(2, preimage, option),
295+
(3, payer_id, option),
273296
(4, secret, option),
274-
(1, payer_note, option),
297+
(5, quantity, option),
275298
};
276299
);
277300

0 commit comments

Comments
 (0)