@@ -9,6 +9,7 @@ use crate::Error;
99use lightning:: ln:: channelmanager:: PaymentId ;
1010use lightning:: ln:: msgs:: DecodeError ;
1111use lightning:: ln:: { PaymentHash , PaymentPreimage , PaymentSecret } ;
12+ use lightning:: offers:: offer:: OfferId ;
1213use lightning:: util:: ser:: { Readable , Writeable } ;
1314use lightning:: {
1415 _init_and_read_len_prefixed_tlv_fields, impl_writeable_tlv_based,
@@ -145,7 +146,6 @@ pub enum PaymentKind {
145146 /// A [BOLT 11] payment.
146147 ///
147148 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
148- // TODO: Bolt11 { invoice: Option<Bolt11Invoice> },
149149 Bolt11 {
150150 /// The payment hash, i.e., the hash of the `preimage`.
151151 hash : PaymentHash ,
@@ -158,7 +158,6 @@ pub enum PaymentKind {
158158 ///
159159 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
160160 /// [LSPS 2]: https://github.com/BitcoinAndLightningLayerSpecs/lsp/blob/main/LSPS2/README.md
161- // TODO: Bolt11Jit { invoice: Option<Bolt11Invoice> },
162161 Bolt11Jit {
163162 /// The payment hash, i.e., the hash of the `preimage`.
164163 hash : PaymentHash ,
@@ -176,6 +175,32 @@ pub enum PaymentKind {
176175 /// [`LdkChannelConfig::accept_underpaying_htlcs`]: lightning::util::config::ChannelConfig::accept_underpaying_htlcs
177176 lsp_fee_limits : LSPFeeLimits ,
178177 } ,
178+ /// A [BOLT 12] 'offer' payment, i.e., a payment for an [`Offer`].
179+ ///
180+ /// [BOLT 12]: https://github.com/lightning/bolts/blob/master/12-offer-encoding.md
181+ /// [`Offer`]: crate::lightning::offers::offer::Offer
182+ Bolt12Offer {
183+ /// The payment hash, i.e., the hash of the `preimage`.
184+ hash : Option < PaymentHash > ,
185+ /// The pre-image used by the payment.
186+ preimage : Option < PaymentPreimage > ,
187+ /// The secret used by the payment.
188+ secret : Option < PaymentSecret > ,
189+ /// The ID of the offer this payment is for.
190+ offer_id : OfferId ,
191+ } ,
192+ /// A [BOLT 12] 'refund' payment, i.e., a payment for a [`Refund`].
193+ ///
194+ /// [BOLT 12]: https://github.com/lightning/bolts/blob/master/12-offer-encoding.md
195+ /// [`Refund`]: lightning::offers::refund::Refund
196+ Bolt12Refund {
197+ /// The payment hash, i.e., the hash of the `preimage`.
198+ hash : Option < PaymentHash > ,
199+ /// The pre-image used by the payment.
200+ preimage : Option < PaymentPreimage > ,
201+ /// The secret used by the payment.
202+ secret : Option < PaymentSecret > ,
203+ } ,
179204 /// A spontaneous ("keysend") payment.
180205 Spontaneous {
181206 /// The payment hash, i.e., the hash of the `preimage`.
@@ -198,9 +223,20 @@ impl_writeable_tlv_based_enum!(PaymentKind,
198223 ( 4 , secret, option) ,
199224 ( 6 , lsp_fee_limits, required) ,
200225 } ,
226+ ( 6 , Bolt12Offer ) => {
227+ ( 0 , hash, option) ,
228+ ( 2 , preimage, option) ,
229+ ( 4 , secret, option) ,
230+ ( 6 , offer_id, required) ,
231+ } ,
201232 ( 8 , Spontaneous ) => {
202233 ( 0 , hash, required) ,
203234 ( 2 , preimage, option) ,
235+ } ,
236+ ( 10 , Bolt12Refund ) => {
237+ ( 0 , hash, option) ,
238+ ( 2 , preimage, option) ,
239+ ( 4 , secret, option) ,
204240 } ;
205241) ;
206242
@@ -227,6 +263,7 @@ impl_writeable_tlv_based!(LSPFeeLimits, {
227263#[ derive( Clone , Debug , PartialEq , Eq ) ]
228264pub ( crate ) struct PaymentDetailsUpdate {
229265 pub id : PaymentId ,
266+ pub hash : Option < Option < PaymentHash > > ,
230267 pub preimage : Option < Option < PaymentPreimage > > ,
231268 pub secret : Option < Option < PaymentSecret > > ,
232269 pub amount_msat : Option < Option < u64 > > ,
@@ -236,7 +273,15 @@ pub(crate) struct PaymentDetailsUpdate {
236273
237274impl PaymentDetailsUpdate {
238275 pub fn new ( id : PaymentId ) -> Self {
239- Self { id, preimage : None , secret : None , amount_msat : None , direction : None , status : None }
276+ Self {
277+ id,
278+ hash : None ,
279+ preimage : None ,
280+ secret : None ,
281+ amount_msat : None ,
282+ direction : None ,
283+ status : None ,
284+ }
240285 }
241286}
242287
@@ -299,10 +344,29 @@ where
299344 let mut locked_payments = self . payments . lock ( ) . unwrap ( ) ;
300345
301346 if let Some ( payment) = locked_payments. get_mut ( & update. id ) {
347+ if let Some ( hash_opt) = update. hash {
348+ match payment. kind {
349+ PaymentKind :: Bolt12Offer { ref mut hash, .. } => {
350+ debug_assert_eq ! ( payment. direction, PaymentDirection :: Outbound ,
351+ "We should only ever override payment hash for outbound BOLT 12 payments" ) ;
352+ * hash = hash_opt
353+ } ,
354+ PaymentKind :: Bolt12Refund { ref mut hash, .. } => {
355+ debug_assert_eq ! ( payment. direction, PaymentDirection :: Outbound ,
356+ "We should only ever override payment hash for outbound BOLT 12 payments" ) ;
357+ * hash = hash_opt
358+ } ,
359+ _ => {
360+ // We can omit updating the hash for BOLT11 payments as the payment has will always be known from the beginning.
361+ } ,
362+ }
363+ }
302364 if let Some ( preimage_opt) = update. preimage {
303365 match payment. kind {
304366 PaymentKind :: Bolt11 { ref mut preimage, .. } => * preimage = preimage_opt,
305367 PaymentKind :: Bolt11Jit { ref mut preimage, .. } => * preimage = preimage_opt,
368+ PaymentKind :: Bolt12Offer { ref mut preimage, .. } => * preimage = preimage_opt,
369+ PaymentKind :: Bolt12Refund { ref mut preimage, .. } => * preimage = preimage_opt,
306370 PaymentKind :: Spontaneous { ref mut preimage, .. } => * preimage = preimage_opt,
307371 _ => { } ,
308372 }
@@ -312,6 +376,8 @@ where
312376 match payment. kind {
313377 PaymentKind :: Bolt11 { ref mut secret, .. } => * secret = secret_opt,
314378 PaymentKind :: Bolt11Jit { ref mut secret, .. } => * secret = secret_opt,
379+ PaymentKind :: Bolt12Offer { ref mut secret, .. } => * secret = secret_opt,
380+ PaymentKind :: Bolt12Refund { ref mut secret, .. } => * secret = secret_opt,
315381 _ => { } ,
316382 }
317383 }
@@ -327,7 +393,6 @@ where
327393 self . persist_info ( & update. id , payment) ?;
328394 updated = true ;
329395 }
330-
331396 Ok ( updated)
332397 }
333398
0 commit comments