@@ -25,17 +25,17 @@ use std::time::Duration;
25
25
/// The event queue will be persisted under this key.
26
26
pub ( crate ) const EVENTS_PERSISTENCE_KEY : & str = "events" ;
27
27
28
- /// An event emitted by [`LdkLite`] that should be handled by the user.
28
+ /// An event emitted by [`LdkLite`], which should be handled by the user.
29
29
///
30
30
/// [`LdkLite`]: [`crate::LdkLite`]
31
31
#[ derive( Debug , Clone , PartialEq ) ]
32
32
pub enum Event {
33
- /// A payment we sent was successful.
33
+ /// A sent payment was successful.
34
34
PaymentSuccessful {
35
35
/// The hash of the payment.
36
36
payment_hash : PaymentHash ,
37
37
} ,
38
- /// A payment we sent has failed.
38
+ /// A sent payment has failed.
39
39
PaymentFailed {
40
40
/// The hash of the payment.
41
41
payment_hash : PaymentHash ,
@@ -44,28 +44,23 @@ pub enum Event {
44
44
PaymentReceived {
45
45
/// The hash of the payment.
46
46
payment_hash : PaymentHash ,
47
- /// The value, in thousandths of a satoshi that has been received.
47
+ /// The value, in thousandths of a satoshi, that has been received.
48
48
amount_msat : u64 ,
49
49
} ,
50
50
/// A channel is ready to be used.
51
51
ChannelReady {
52
- /// The channel_id of the channel which is ready .
52
+ /// The ` channel_id` of the channel.
53
53
channel_id : [ u8 ; 32 ] ,
54
- /// The user_channel_id of the channel which is ready .
54
+ /// The ` user_channel_id` of the channel.
55
55
user_channel_id : u128 ,
56
56
} ,
57
57
/// A channel has been closed.
58
58
ChannelClosed {
59
- /// The channel_id of the channel which has been closed .
59
+ /// The ` channel_id` of the channel.
60
60
channel_id : [ u8 ; 32 ] ,
61
- /// The user_channel_id of the channel which has been closed .
61
+ /// The ` user_channel_id` of the channel.
62
62
user_channel_id : u128 ,
63
63
} ,
64
- // TODO: Implement on-chain events when better integrating with BDK wallet sync.
65
- //OnChainPaymentSent {
66
- //},
67
- //OnChainPaymentReceived {
68
- //}
69
64
}
70
65
71
66
// TODO: Figure out serialization more concretely - see issue #30
@@ -97,12 +92,6 @@ impl Readable for Event {
97
92
let user_channel_id: u128 = Readable :: read ( reader) ?;
98
93
Ok ( Self :: ChannelClosed { channel_id, user_channel_id } )
99
94
}
100
- //5u8 => {
101
- // TODO OnChainPaymentSent
102
- //}
103
- //6u8 => {
104
- // TODO OnChainPaymentReceived
105
- //}
106
95
_ => Err ( lightning:: ln:: msgs:: DecodeError :: InvalidValue ) ,
107
96
}
108
97
}
@@ -138,12 +127,7 @@ impl Writeable for Event {
138
127
channel_id. write ( writer) ?;
139
128
user_channel_id. write ( writer) ?;
140
129
Ok ( ( ) )
141
- } //Self::OnChainPaymentSent { .. } => {
142
- //TODO
143
- //}
144
- //Self::OnChainPaymentReceived { .. } => {
145
- //TODO
146
- //}
130
+ }
147
131
}
148
132
}
149
133
}
@@ -310,7 +294,7 @@ where
310
294
output_script,
311
295
..
312
296
} => {
313
- // Construct the raw transaction with one output, that is paid the amount of the
297
+ // Construct the raw transaction with the output that is paid the amount of the
314
298
// channel.
315
299
let confirmation_target = ConfirmationTarget :: Normal ;
316
300
@@ -356,7 +340,7 @@ where
356
340
} => {
357
341
log_info ! (
358
342
self . logger,
359
- "Received payment from payment hash {} of {} millisatoshis " ,
343
+ "Received payment from payment hash {} of {} msats " ,
360
344
hex_utils:: to_string( & payment_hash. 0 ) ,
361
345
amount_msat,
362
346
) ;
@@ -391,7 +375,7 @@ where
391
375
} => {
392
376
log_info ! (
393
377
self . logger,
394
- "Claimed payment from payment hash {} of {} millisatoshis ." ,
378
+ "Claimed payment from payment hash {} of {} msats ." ,
395
379
hex_utils:: to_string( & payment_hash. 0 ) ,
396
380
amount_msat,
397
381
) ;
@@ -430,17 +414,18 @@ where
430
414
payment. status = PaymentStatus :: Succeeded ;
431
415
log_info ! (
432
416
self . logger,
433
- "Successfully sent payment of {} millisatoshis {} from \
417
+ "Successfully sent payment of {} msats {} from \
434
418
payment hash {:?} with preimage {:?}",
435
419
payment. amount_msat. unwrap( ) ,
436
420
if let Some ( fee) = fee_paid_msat {
437
- format!( " (fee {} msat )" , fee)
421
+ format!( " (fee {} msats )" , fee)
438
422
} else {
439
423
"" . to_string( )
440
424
} ,
441
425
hex_utils:: to_string( & payment_hash. 0 ) ,
442
426
hex_utils:: to_string( & payment_preimage. 0 )
443
427
) ;
428
+ break ;
444
429
}
445
430
}
446
431
self . event_queue
@@ -450,7 +435,7 @@ where
450
435
LdkEvent :: PaymentFailed { payment_hash, .. } => {
451
436
log_info ! (
452
437
self . logger,
453
- "Failed to send payment to payment hash {:?}: exhausted payment retry attempts " ,
438
+ "Failed to send payment to payment hash {:?}. " ,
454
439
hex_utils:: to_string( & payment_hash. 0 )
455
440
) ;
456
441
@@ -515,23 +500,19 @@ where
515
500
let nodes = read_only_network_graph. nodes ( ) ;
516
501
let channels = self . channel_manager . list_channels ( ) ;
517
502
518
- let node_str = |channel_id : & Option < [ u8 ; 32 ] > | match channel_id {
519
- None => String :: new ( ) ,
520
- Some ( channel_id) => match channels. iter ( ) . find ( |c| c. channel_id == * channel_id)
521
- {
522
- None => String :: new ( ) ,
523
- Some ( channel) => {
524
- match nodes. get ( & NodeId :: from_pubkey ( & channel. counterparty . node_id ) ) {
525
- None => "private node" . to_string ( ) ,
526
- Some ( node) => match & node. announcement_info {
527
- None => "unnamed node" . to_string ( ) ,
528
- Some ( announcement) => {
529
- format ! ( "node {}" , announcement. alias)
530
- }
531
- } ,
532
- }
533
- }
534
- } ,
503
+ let node_str = |channel_id : & Option < [ u8 ; 32 ] > | {
504
+ channel_id
505
+ . and_then ( |channel_id| channels. iter ( ) . find ( |c| c. channel_id == channel_id) )
506
+ . and_then ( |channel| {
507
+ nodes. get ( & NodeId :: from_pubkey ( & channel. counterparty . node_id ) )
508
+ } )
509
+ . map_or ( "private_node" . to_string ( ) , |node| {
510
+ node. announcement_info
511
+ . as_ref ( )
512
+ . map_or ( "unnamed node" . to_string ( ) , |ann| {
513
+ format ! ( "node {}" , ann. alias)
514
+ } )
515
+ } )
535
516
} ;
536
517
let channel_str = |channel_id : & Option < [ u8 ; 32 ] > | {
537
518
channel_id
@@ -548,27 +529,22 @@ where
548
529
let to_next_str =
549
530
format ! ( " to {}{}" , node_str( & next_channel_id) , channel_str( & next_channel_id) ) ;
550
531
551
- let from_onchain_str = if claim_from_onchain_tx {
552
- "from onchain downstream claim"
553
- } else {
554
- "from HTLC fulfill message"
555
- } ;
556
- if let Some ( fee_earned) = fee_earned_msat {
532
+ let fee_earned = fee_earned_msat. unwrap_or ( 0 ) ;
533
+ if claim_from_onchain_tx {
557
534
log_info ! (
558
535
self . logger,
559
- "Forwarded payment{}{}, earning {} msat {} " ,
536
+ "Forwarded payment{}{}, earning {} msats in fees from claiming onchain. " ,
560
537
from_prev_str,
561
538
to_next_str,
562
539
fee_earned,
563
- from_onchain_str
564
540
) ;
565
541
} else {
566
542
log_info ! (
567
543
self . logger,
568
- "Forwarded payment{}{}, claiming onchain {} " ,
544
+ "Forwarded payment{}{}, earning {} msats in fees. " ,
569
545
from_prev_str,
570
546
to_next_str,
571
- from_onchain_str
547
+ fee_earned ,
572
548
) ;
573
549
}
574
550
}
0 commit comments