Skip to content

Commit ee7b9bc

Browse files
committed
Add Bolt12 variant to PaymentKind
1 parent 3a0bcb5 commit ee7b9bc

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

bindings/ldk_node.udl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ interface PaymentKind {
225225
Onchain();
226226
Bolt11(PaymentHash hash, PaymentPreimage? preimage, PaymentSecret? secret);
227227
Bolt11Jit(PaymentHash hash, PaymentPreimage? preimage, PaymentSecret? secret, LSPFeeLimits lsp_fee_limits);
228+
Bolt12(PaymentHash? hash, PaymentPreimage? preimage, PaymentSecret? secret);
228229
Spontaneous(PaymentHash hash, PaymentPreimage? preimage);
229230
};
230231

src/payment/store.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,18 @@ pub enum PaymentKind {
176176
/// [`LdkChannelConfig::accept_underpaying_htlcs`]: lightning::util::config::ChannelConfig::accept_underpaying_htlcs
177177
lsp_fee_limits: LSPFeeLimits,
178178
},
179+
/// A [BOLT 12] payment.
180+
///
181+
/// [BOLT 12]: https://github.com/lightning/bolts/blob/master/12-offer-encoding.md
182+
// TODO: Bolt12 { offer: Option<Offer>, refund: Option<Refund> },
183+
Bolt12 {
184+
/// The payment hash, i.e., the hash of the `preimage`.
185+
hash: Option<PaymentHash>,
186+
/// The pre-image used by the payment.
187+
preimage: Option<PaymentPreimage>,
188+
/// The secret used by the payment.
189+
secret: Option<PaymentSecret>,
190+
},
179191
/// A spontaneous ("keysend") payment.
180192
Spontaneous {
181193
/// The payment hash, i.e., the hash of the `preimage`.
@@ -198,6 +210,11 @@ impl_writeable_tlv_based_enum!(PaymentKind,
198210
(4, secret, option),
199211
(6, lsp_fee_limits, required),
200212
},
213+
(6, Bolt12) => {
214+
(0, hash, option),
215+
(2, preimage, option),
216+
(4, secret, option),
217+
},
201218
(8, Spontaneous) => {
202219
(0, hash, required),
203220
(2, preimage, option),
@@ -227,6 +244,7 @@ impl_writeable_tlv_based!(LSPFeeLimits, {
227244
#[derive(Clone, Debug, PartialEq, Eq)]
228245
pub(crate) struct PaymentDetailsUpdate {
229246
pub id: PaymentId,
247+
pub hash: Option<Option<PaymentHash>>,
230248
pub preimage: Option<Option<PaymentPreimage>>,
231249
pub secret: Option<Option<PaymentSecret>>,
232250
pub amount_msat: Option<Option<u64>>,
@@ -236,7 +254,15 @@ pub(crate) struct PaymentDetailsUpdate {
236254

237255
impl PaymentDetailsUpdate {
238256
pub fn new(id: PaymentId) -> Self {
239-
Self { id, preimage: None, secret: None, amount_msat: None, direction: None, status: None }
257+
Self {
258+
id,
259+
hash: None,
260+
preimage: None,
261+
secret: None,
262+
amount_msat: None,
263+
direction: None,
264+
status: None,
265+
}
240266
}
241267
}
242268

@@ -299,10 +325,17 @@ where
299325
let mut locked_payments = self.payments.lock().unwrap();
300326

301327
if let Some(payment) = locked_payments.get_mut(&update.id) {
328+
if let Some(hash_opt) = update.hash {
329+
match payment.kind {
330+
PaymentKind::Bolt12 { ref mut hash, .. } => *hash = hash_opt,
331+
_ => {},
332+
}
333+
}
302334
if let Some(preimage_opt) = update.preimage {
303335
match payment.kind {
304336
PaymentKind::Bolt11 { ref mut preimage, .. } => *preimage = preimage_opt,
305337
PaymentKind::Bolt11Jit { ref mut preimage, .. } => *preimage = preimage_opt,
338+
PaymentKind::Bolt12 { ref mut preimage, .. } => *preimage = preimage_opt,
306339
PaymentKind::Spontaneous { ref mut preimage, .. } => *preimage = preimage_opt,
307340
_ => {},
308341
}
@@ -312,6 +345,7 @@ where
312345
match payment.kind {
313346
PaymentKind::Bolt11 { ref mut secret, .. } => *secret = secret_opt,
314347
PaymentKind::Bolt11Jit { ref mut secret, .. } => *secret = secret_opt,
348+
PaymentKind::Bolt12 { ref mut secret, .. } => *secret = secret_opt,
315349
_ => {},
316350
}
317351
}

0 commit comments

Comments
 (0)