Skip to content

Commit

Permalink
Add payer_id quantity fields
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
slanesuke committed Jul 19, 2024
1 parent a903103 commit d4a92b0
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
4 changes: 2 additions & 2 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ interface PaymentKind {
Onchain();
Bolt11(PaymentHash hash, PaymentPreimage? preimage, PaymentSecret? secret);
Bolt11Jit(PaymentHash hash, PaymentPreimage? preimage, PaymentSecret? secret, LSPFeeLimits lsp_fee_limits);
Bolt12Offer(PaymentHash? hash, PaymentPreimage? preimage, PaymentSecret? secret, OfferId offer_id, UntrustedString? payer_note);
Bolt12Refund(PaymentHash? hash, PaymentPreimage? preimage, PaymentSecret? secret, UntrustedString? payer_note);
Bolt12Offer(PaymentHash? hash, PaymentPreimage? preimage, PaymentSecret? secret, OfferId offer_id, UntrustedString? payer_note, PublicKey? payer_id, u64? quantity);
Bolt12Refund(PaymentHash? hash, PaymentPreimage? preimage, PaymentSecret? secret, UntrustedString? payer_note, PublicKey? payer_id, u64? quantity);
Spontaneous(PaymentHash hash, PaymentPreimage? preimage);
};

Expand Down
6 changes: 5 additions & 1 deletion src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,14 +597,18 @@ where
payment_context,
..
} => {
let payer_note = payment_context.invoice_request.payer_note_truncated;
let offer_id = payment_context.offer_id;
let payer_note = payment_context.invoice_request.payer_note_truncated;
let payer_id = payment_context.invoice_request.payer_id;
let quantity = payment_context.invoice_request.quantity;
let kind = PaymentKind::Bolt12Offer {
hash: Some(payment_hash),
preimage: payment_preimage,
secret: Some(payment_secret),
offer_id,
payer_note,
payer_id: Some(payer_id),
quantity,
};

let payment = PaymentDetails::new(
Expand Down
12 changes: 12 additions & 0 deletions src/payment/bolt12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ impl Bolt12Payment {
secret: None,
offer_id: offer.id(),
payer_note: payer_note.map(UntrustedString),
payer_id: None,
quantity,
};
let payment = PaymentDetails::new(
payment_id,
Expand All @@ -120,6 +122,8 @@ impl Bolt12Payment {
secret: None,
offer_id: offer.id(),
payer_note: payer_note.map(UntrustedString),
payer_id: None,
quantity,
};
let payment = PaymentDetails::new(
payment_id,
Expand Down Expand Up @@ -200,6 +204,8 @@ impl Bolt12Payment {
secret: None,
offer_id: offer.id(),
payer_note: payer_note.map(UntrustedString),
payer_id: None,
quantity,
};
let payment = PaymentDetails::new(
payment_id,
Expand All @@ -223,6 +229,8 @@ impl Bolt12Payment {
secret: None,
offer_id: offer.id(),
payer_note: payer_note.map(UntrustedString),
payer_id: None,
quantity,
};
let payment = PaymentDetails::new(
payment_id,
Expand Down Expand Up @@ -291,6 +299,8 @@ impl Bolt12Payment {
preimage: None,
secret: None,
payer_note: refund.payer_note().map(|note| UntrustedString(note.to_string())),
payer_id: None,
quantity: None,
};

let payment = PaymentDetails::new(
Expand Down Expand Up @@ -344,6 +354,8 @@ impl Bolt12Payment {
preimage: None,
secret: None,
payer_note: refund.payer_note().map(|note| UntrustedString(note.to_string())),
payer_id: None,
quantity: None,
};
let payment = PaymentDetails::new(
payment_id,
Expand Down
29 changes: 26 additions & 3 deletions src/payment/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::logger::{log_error, Logger};
use crate::types::DynStore;
use crate::Error;

use bitcoin::secp256k1::PublicKey;
use lightning::ln::channelmanager::PaymentId;
use lightning::ln::msgs::DecodeError;
use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret};
Expand Down Expand Up @@ -213,10 +214,20 @@ pub enum PaymentKind {
secret: Option<PaymentSecret>,
/// The ID of the offer this payment is for.
offer_id: OfferId,
/// The payer note for the payment.
/// The payer note for the payment. Truncated to [PAYER_NOTE_LIMIT] characters.
///
/// This will always be `None` for payments serialized with version `v0.3.0`.
///
/// [PAYER_NOTE_LIMIT]: lightning::offers::invoice_request::PAYER_NOTE_LIMIT
payer_note: Option<UntrustedString>,
/// The payers ID for the payment.
///
/// This will always be `None` for payments serialized with version `v0.3.0`.
payer_id: Option<PublicKey>,
/// The quantity of items or units requested in the offer.
///
/// This will always be `None` for payments serialized with version `v0.3.0`.
quantity: Option<u64>,
},
/// A [BOLT 12] 'refund' payment, i.e., a payment for a [`Refund`].
///
Expand All @@ -233,6 +244,14 @@ pub enum PaymentKind {
///
/// This will always be `None` for payments serialized with version `v0.3.0`.
payer_note: Option<UntrustedString>,
/// The payers ID for the refund payment.
///
/// This will always be `None` for payments serialized with version `v0.3.0`.
payer_id: Option<PublicKey>,
/// The quantity of items or units requested in the offer.
///
/// This will always be `None` for payments serialized with version `v0.3.0`.
quantity: Option<u64>,
},
/// A spontaneous ("keysend") payment.
Spontaneous {
Expand All @@ -258,20 +277,24 @@ impl_writeable_tlv_based_enum!(PaymentKind,
},
(6, Bolt12Offer) => {
(0, hash, option),
(1, payer_note, option),
(2, preimage, option),
(3, payer_id, option),
(4, secret, option),
(5, quantity, option),
(6, offer_id, required),
(1, payer_note, option),
},
(8, Spontaneous) => {
(0, hash, required),
(2, preimage, option),
},
(10, Bolt12Refund) => {
(0, hash, option),
(1, payer_note, option),
(2, preimage, option),
(3, payer_id, option),
(4, secret, option),
(1, payer_note, option),
(5, quantity, option),
};
);

Expand Down

0 comments on commit d4a92b0

Please sign in to comment.