55// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
66// accordance with one or both of these licenses.
77
8- use crate :: types:: { DynStore , Sweeper , Wallet } ;
8+ use crate :: types:: { CustomTlvRecord , DynStore , Sweeper , Wallet } ;
99
1010use crate :: {
1111 hex_utils, BumpTransactionEventHandler , ChannelManager , Config , Error , Graph , PeerInfo ,
@@ -102,6 +102,8 @@ pub enum Event {
102102 payment_hash : PaymentHash ,
103103 /// The value, in thousandths of a satoshi, that has been received.
104104 amount_msat : u64 ,
105+ /// Custom TLV records received on the payment
106+ custom_records : Vec < CustomTlvRecord > ,
105107 } ,
106108 /// A payment has been forwarded.
107109 PaymentForwarded {
@@ -168,6 +170,8 @@ pub enum Event {
168170 /// The block height at which this payment will be failed back and will no longer be
169171 /// eligible for claiming.
170172 claim_deadline : Option < u32 > ,
173+ /// Custom TLV records attached to the payment
174+ custom_records : Vec < CustomTlvRecord > ,
171175 } ,
172176 /// A channel has been created and is pending confirmation on-chain.
173177 ChannelPending {
@@ -224,6 +228,7 @@ impl_writeable_tlv_based_enum!(Event,
224228 ( 0 , payment_hash, required) ,
225229 ( 1 , payment_id, option) ,
226230 ( 2 , amount_msat, required) ,
231+ ( 3 , custom_records, optional_vec) ,
227232 } ,
228233 ( 3 , ChannelReady ) => {
229234 ( 0 , channel_id, required) ,
@@ -248,6 +253,7 @@ impl_writeable_tlv_based_enum!(Event,
248253 ( 2 , payment_id, required) ,
249254 ( 4 , claimable_amount_msat, required) ,
250255 ( 6 , claim_deadline, option) ,
256+ ( 7 , custom_records, optional_vec) ,
251257 } ,
252258 ( 7 , PaymentForwarded ) => {
253259 ( 0 , prev_channel_id, required) ,
@@ -542,7 +548,7 @@ where
542548 via_channel_id : _,
543549 via_user_channel_id : _,
544550 claim_deadline,
545- onion_fields : _ ,
551+ onion_fields,
546552 counterparty_skimmed_fee_msat,
547553 } => {
548554 let payment_id = PaymentId ( payment_hash. 0 ) ;
@@ -644,11 +650,17 @@ where
644650 "We would have registered the preimage if we knew"
645651 ) ;
646652
653+ let custom_records = onion_fields
654+ . map ( |cf| {
655+ cf. custom_tlvs ( ) . into_iter ( ) . map ( |tlv| tlv. into ( ) ) . collect ( )
656+ } )
657+ . unwrap_or_default ( ) ;
647658 let event = Event :: PaymentClaimable {
648659 payment_id,
649660 payment_hash,
650661 claimable_amount_msat : amount_msat,
651662 claim_deadline,
663+ custom_records,
652664 } ;
653665 match self . event_queue . add_event ( event) {
654666 Ok ( _) => return Ok ( ( ) ) ,
@@ -799,7 +811,7 @@ where
799811 receiver_node_id : _,
800812 htlcs : _,
801813 sender_intended_total_msat : _,
802- onion_fields : _ ,
814+ onion_fields,
803815 } => {
804816 let payment_id = PaymentId ( payment_hash. 0 ) ;
805817 log_info ! (
@@ -875,6 +887,9 @@ where
875887 payment_id : Some ( payment_id) ,
876888 payment_hash,
877889 amount_msat,
890+ custom_records : onion_fields
891+ . map ( |cf| cf. custom_tlvs ( ) . into_iter ( ) . map ( |tlv| tlv. into ( ) ) . collect ( ) )
892+ . unwrap_or_default ( ) ,
878893 } ;
879894 match self . event_queue . add_event ( event) {
880895 Ok ( _) => return Ok ( ( ) ) ,
0 commit comments