@@ -42,6 +42,13 @@ pub struct PaymentDetails {
42
42
pub kind : PaymentKind ,
43
43
/// The amount transferred.
44
44
pub amount_msat : Option < u64 > ,
45
+ /// The fees that were paid for this payment.
46
+ ///
47
+ /// For Lightning payments, this will only be updated for outbound payments once they
48
+ /// succeeded.
49
+ ///
50
+ /// Will be `None` for Lightning payments made with LDK Node v0.4.x and earlier.
51
+ pub fee_paid_msat : Option < u64 > ,
45
52
/// The direction of the payment.
46
53
pub direction : PaymentDirection ,
47
54
/// The status of the payment.
@@ -52,14 +59,14 @@ pub struct PaymentDetails {
52
59
53
60
impl PaymentDetails {
54
61
pub ( crate ) fn new (
55
- id : PaymentId , kind : PaymentKind , amount_msat : Option < u64 > , direction : PaymentDirection ,
56
- status : PaymentStatus ,
62
+ id : PaymentId , kind : PaymentKind , amount_msat : Option < u64 > , fee_paid_msat : Option < u64 > ,
63
+ direction : PaymentDirection , status : PaymentStatus ,
57
64
) -> Self {
58
65
let latest_update_timestamp = SystemTime :: now ( )
59
66
. duration_since ( UNIX_EPOCH )
60
67
. unwrap_or ( Duration :: from_secs ( 0 ) )
61
68
. as_secs ( ) ;
62
- Self { id, kind, amount_msat, direction, status, latest_update_timestamp }
69
+ Self { id, kind, amount_msat, fee_paid_msat , direction, status, latest_update_timestamp }
63
70
}
64
71
65
72
pub ( crate ) fn update ( & mut self , update : & PaymentDetailsUpdate ) -> bool {
@@ -154,6 +161,10 @@ impl PaymentDetails {
154
161
update_if_necessary ! ( self . amount_msat, amount_opt) ;
155
162
}
156
163
164
+ if let Some ( fee_paid_msat_opt) = update. fee_paid_msat {
165
+ update_if_necessary ! ( self . fee_paid_msat, fee_paid_msat_opt) ;
166
+ }
167
+
157
168
if let Some ( status) = update. status {
158
169
update_if_necessary ! ( self . status, status) ;
159
170
}
@@ -192,6 +203,7 @@ impl Writeable for PaymentDetails {
192
203
( 4 , None :: <Option <PaymentSecret >>, required) ,
193
204
( 5 , self . latest_update_timestamp, required) ,
194
205
( 6 , self . amount_msat, required) ,
206
+ ( 7 , self . fee_paid_msat, option) ,
195
207
( 8 , self . direction, required) ,
196
208
( 10 , self . status, required)
197
209
} ) ;
@@ -213,6 +225,7 @@ impl Readable for PaymentDetails {
213
225
( 4 , secret, required) ,
214
226
( 5 , latest_update_timestamp, ( default_value, unix_time_secs) ) ,
215
227
( 6 , amount_msat, required) ,
228
+ ( 7 , fee_paid_msat, option) ,
216
229
( 8 , direction, required) ,
217
230
( 10 , status, required)
218
231
} ) ;
@@ -253,7 +266,15 @@ impl Readable for PaymentDetails {
253
266
}
254
267
} ;
255
268
256
- Ok ( PaymentDetails { id, kind, amount_msat, direction, status, latest_update_timestamp } )
269
+ Ok ( PaymentDetails {
270
+ id,
271
+ kind,
272
+ amount_msat,
273
+ fee_paid_msat,
274
+ direction,
275
+ status,
276
+ latest_update_timestamp,
277
+ } )
257
278
}
258
279
}
259
280
@@ -479,6 +500,7 @@ pub(crate) struct PaymentDetailsUpdate {
479
500
pub preimage : Option < Option < PaymentPreimage > > ,
480
501
pub secret : Option < Option < PaymentSecret > > ,
481
502
pub amount_msat : Option < Option < u64 > > ,
503
+ pub fee_paid_msat : Option < Option < u64 > > ,
482
504
pub direction : Option < PaymentDirection > ,
483
505
pub status : Option < PaymentStatus > ,
484
506
pub confirmation_status : Option < ConfirmationStatus > ,
@@ -492,6 +514,7 @@ impl PaymentDetailsUpdate {
492
514
preimage : None ,
493
515
secret : None ,
494
516
amount_msat : None ,
517
+ fee_paid_msat : None ,
495
518
direction : None ,
496
519
status : None ,
497
520
confirmation_status : None ,
@@ -521,6 +544,7 @@ impl From<&PaymentDetails> for PaymentDetailsUpdate {
521
544
preimage : Some ( preimage) ,
522
545
secret : Some ( secret) ,
523
546
amount_msat : Some ( value. amount_msat ) ,
547
+ fee_paid_msat : Some ( value. fee_paid_msat ) ,
524
548
direction : Some ( value. direction ) ,
525
549
status : Some ( value. status ) ,
526
550
confirmation_status,
@@ -708,8 +732,14 @@ mod tests {
708
732
. is_err( ) ) ;
709
733
710
734
let kind = PaymentKind :: Bolt11 { hash, preimage : None , secret : None } ;
711
- let payment =
712
- PaymentDetails :: new ( id, kind, None , PaymentDirection :: Inbound , PaymentStatus :: Pending ) ;
735
+ let payment = PaymentDetails :: new (
736
+ id,
737
+ kind,
738
+ None ,
739
+ None ,
740
+ PaymentDirection :: Inbound ,
741
+ PaymentStatus :: Pending ,
742
+ ) ;
713
743
714
744
assert_eq ! ( Ok ( false ) , payment_store. insert( payment. clone( ) ) ) ;
715
745
assert ! ( payment_store. get( & id) . is_some( ) ) ;
0 commit comments