@@ -18,6 +18,7 @@ pub mod bump_transaction;
18
18
19
19
pub use bump_transaction:: BumpTransactionEvent ;
20
20
21
+ use crate :: blinded_path:: payment:: { Bolt12OfferContext , Bolt12RefundContext , PaymentContext , PaymentContextRef } ;
21
22
use crate :: sign:: SpendableOutputDescriptor ;
22
23
use crate :: ln:: channelmanager:: { InterceptId , PaymentId , RecipientOnionFields } ;
23
24
use crate :: ln:: channel:: FUNDING_CONF_DEADLINE_BLOCKS ;
@@ -70,6 +71,46 @@ pub enum PaymentPurpose {
70
71
/// [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
71
72
payment_secret : PaymentSecret ,
72
73
} ,
74
+ /// A payment for a BOLT 12 [`Offer`].
75
+ ///
76
+ /// [`Offer`]: crate::offers::offer::Offer
77
+ Bolt12OfferPayment {
78
+ /// The preimage to the payment hash. If provided, this can be handed directly to
79
+ /// [`ChannelManager::claim_funds`].
80
+ ///
81
+ /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
82
+ payment_preimage : Option < PaymentPreimage > ,
83
+ /// The secret used to authenticate the sender to the recipient, preventing a number of
84
+ /// de-anonymization attacks while routing a payment.
85
+ ///
86
+ /// See [`PaymentPurpose::Bolt11InvoicePayment::payment_secret`] for further details.
87
+ payment_secret : PaymentSecret ,
88
+ /// The context of the payment such as information about the corresponding [`Offer`] and
89
+ /// [`InvoiceRequest`].
90
+ ///
91
+ /// [`Offer`]: crate::offers::offer::Offer
92
+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
93
+ payment_context : Bolt12OfferContext ,
94
+ } ,
95
+ /// A payment for a BOLT 12 [`Refund`].
96
+ ///
97
+ /// [`Refund`]: crate::offers::refund::Refund
98
+ Bolt12RefundPayment {
99
+ /// The preimage to the payment hash. If provided, this can be handed directly to
100
+ /// [`ChannelManager::claim_funds`].
101
+ ///
102
+ /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
103
+ payment_preimage : Option < PaymentPreimage > ,
104
+ /// The secret used to authenticate the sender to the recipient, preventing a number of
105
+ /// de-anonymization attacks while routing a payment.
106
+ ///
107
+ /// See [`PaymentPurpose::Bolt11InvoicePayment::payment_secret`] for further details.
108
+ payment_secret : PaymentSecret ,
109
+ /// The context of the payment such as information about the corresponding [`Refund`].
110
+ ///
111
+ /// [`Refund`]: crate::offers::refund::Refund
112
+ payment_context : Bolt12RefundContext ,
113
+ } ,
73
114
/// Because this is a spontaneous payment, the payer generated their own preimage rather than us
74
115
/// (the payee) providing a preimage.
75
116
SpontaneousPayment ( PaymentPreimage ) ,
@@ -80,13 +121,17 @@ impl PaymentPurpose {
80
121
pub fn preimage ( & self ) -> Option < PaymentPreimage > {
81
122
match self {
82
123
PaymentPurpose :: Bolt11InvoicePayment { payment_preimage, .. } => * payment_preimage,
124
+ PaymentPurpose :: Bolt12OfferPayment { payment_preimage, .. } => * payment_preimage,
125
+ PaymentPurpose :: Bolt12RefundPayment { payment_preimage, .. } => * payment_preimage,
83
126
PaymentPurpose :: SpontaneousPayment ( preimage) => Some ( * preimage) ,
84
127
}
85
128
}
86
129
87
130
pub ( crate ) fn is_keysend ( & self ) -> bool {
88
131
match self {
89
132
PaymentPurpose :: Bolt11InvoicePayment { .. } => false ,
133
+ PaymentPurpose :: Bolt12OfferPayment { .. } => false ,
134
+ PaymentPurpose :: Bolt12RefundPayment { .. } => false ,
90
135
PaymentPurpose :: SpontaneousPayment ( ..) => true ,
91
136
}
92
137
}
@@ -96,7 +141,18 @@ impl_writeable_tlv_based_enum!(PaymentPurpose,
96
141
( 0 , Bolt11InvoicePayment ) => {
97
142
( 0 , payment_preimage, option) ,
98
143
( 2 , payment_secret, required) ,
99
- } ;
144
+ } ,
145
+ ( 4 , Bolt12OfferPayment ) => {
146
+ ( 0 , payment_preimage, option) ,
147
+ ( 2 , payment_secret, required) ,
148
+ ( 4 , payment_context, required) ,
149
+ } ,
150
+ ( 6 , Bolt12RefundPayment ) => {
151
+ ( 0 , payment_preimage, option) ,
152
+ ( 2 , payment_secret, required) ,
153
+ ( 4 , payment_context, required) ,
154
+ } ,
155
+ ;
100
156
( 2 , SpontaneousPayment )
101
157
) ;
102
158
@@ -1065,13 +1121,28 @@ impl Writeable for Event {
1065
1121
1u8 . write ( writer) ?;
1066
1122
let mut payment_secret = None ;
1067
1123
let payment_preimage;
1124
+ let mut payment_context = None ;
1068
1125
match & purpose {
1069
1126
PaymentPurpose :: Bolt11InvoicePayment {
1070
1127
payment_preimage : preimage, payment_secret : secret
1071
1128
} => {
1072
1129
payment_secret = Some ( secret) ;
1073
1130
payment_preimage = * preimage;
1074
1131
} ,
1132
+ PaymentPurpose :: Bolt12OfferPayment {
1133
+ payment_preimage : preimage, payment_secret : secret, payment_context : context
1134
+ } => {
1135
+ payment_secret = Some ( secret) ;
1136
+ payment_preimage = * preimage;
1137
+ payment_context = Some ( PaymentContextRef :: Bolt12Offer ( context) ) ;
1138
+ } ,
1139
+ PaymentPurpose :: Bolt12RefundPayment {
1140
+ payment_preimage : preimage, payment_secret : secret, payment_context : context
1141
+ } => {
1142
+ payment_secret = Some ( secret) ;
1143
+ payment_preimage = * preimage;
1144
+ payment_context = Some ( PaymentContextRef :: Bolt12Refund ( context) ) ;
1145
+ } ,
1075
1146
PaymentPurpose :: SpontaneousPayment ( preimage) => {
1076
1147
payment_preimage = Some ( * preimage) ;
1077
1148
}
@@ -1090,6 +1161,7 @@ impl Writeable for Event {
1090
1161
( 8 , payment_preimage, option) ,
1091
1162
( 9 , onion_fields, option) ,
1092
1163
( 10 , skimmed_fee_opt, option) ,
1164
+ ( 11 , payment_context, option) ,
1093
1165
} ) ;
1094
1166
} ,
1095
1167
& Event :: PaymentSent { ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat } => {
@@ -1320,6 +1392,7 @@ impl MaybeReadable for Event {
1320
1392
let mut claim_deadline = None ;
1321
1393
let mut via_user_channel_id = None ;
1322
1394
let mut onion_fields = None ;
1395
+ let mut payment_context = None ;
1323
1396
read_tlv_fields ! ( reader, {
1324
1397
( 0 , payment_hash, required) ,
1325
1398
( 1 , receiver_node_id, option) ,
@@ -1332,11 +1405,30 @@ impl MaybeReadable for Event {
1332
1405
( 8 , payment_preimage, option) ,
1333
1406
( 9 , onion_fields, option) ,
1334
1407
( 10 , counterparty_skimmed_fee_msat_opt, option) ,
1408
+ ( 11 , payment_context, option) ,
1335
1409
} ) ;
1336
1410
let purpose = match payment_secret {
1337
- Some ( secret) => PaymentPurpose :: Bolt11InvoicePayment {
1338
- payment_preimage,
1339
- payment_secret : secret
1411
+ Some ( secret) => match payment_context {
1412
+ Some ( PaymentContext :: Unknown ( _) ) | None => {
1413
+ PaymentPurpose :: Bolt11InvoicePayment {
1414
+ payment_preimage,
1415
+ payment_secret : secret,
1416
+ }
1417
+ } ,
1418
+ Some ( PaymentContext :: Bolt12Offer ( context) ) => {
1419
+ PaymentPurpose :: Bolt12OfferPayment {
1420
+ payment_preimage,
1421
+ payment_secret : secret,
1422
+ payment_context : context,
1423
+ }
1424
+ } ,
1425
+ Some ( PaymentContext :: Bolt12Refund ( context) ) => {
1426
+ PaymentPurpose :: Bolt12RefundPayment {
1427
+ payment_preimage,
1428
+ payment_secret : secret,
1429
+ payment_context : context,
1430
+ }
1431
+ } ,
1340
1432
} ,
1341
1433
None if payment_preimage. is_some ( ) => PaymentPurpose :: SpontaneousPayment ( payment_preimage. unwrap ( ) ) ,
1342
1434
None => return Err ( msgs:: DecodeError :: InvalidValue ) ,
0 commit comments