@@ -25,17 +25,17 @@ use std::time::Duration;
2525/// The event queue will be persisted under this key.
2626pub ( crate ) const EVENTS_PERSISTENCE_KEY : & str = "events" ;
2727
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.
2929///
3030/// [`LdkLite`]: [`crate::LdkLite`]
3131#[ derive( Debug , Clone , PartialEq ) ]
3232pub enum Event {
33- /// A payment we sent was successful.
33+ /// A sent payment was successful.
3434 PaymentSuccessful {
3535 /// The hash of the payment.
3636 payment_hash : PaymentHash ,
3737 } ,
38- /// A payment we sent has failed.
38+ /// A sent payment has failed.
3939 PaymentFailed {
4040 /// The hash of the payment.
4141 payment_hash : PaymentHash ,
@@ -44,28 +44,23 @@ pub enum Event {
4444 PaymentReceived {
4545 /// The hash of the payment.
4646 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.
4848 amount_msat : u64 ,
4949 } ,
5050 /// A channel is ready to be used.
5151 ChannelReady {
52- /// The channel_id of the channel which is ready .
52+ /// The ` channel_id` of the channel.
5353 channel_id : [ u8 ; 32 ] ,
54- /// The user_channel_id of the channel which is ready .
54+ /// The ` user_channel_id` of the channel.
5555 user_channel_id : u128 ,
5656 } ,
5757 /// A channel has been closed.
5858 ChannelClosed {
59- /// The channel_id of the channel which has been closed .
59+ /// The ` channel_id` of the channel.
6060 channel_id : [ u8 ; 32 ] ,
61- /// The user_channel_id of the channel which has been closed .
61+ /// The ` user_channel_id` of the channel.
6262 user_channel_id : u128 ,
6363 } ,
64- // TODO: Implement on-chain events when better integrating with BDK wallet sync.
65- //OnChainPaymentSent {
66- //},
67- //OnChainPaymentReceived {
68- //}
6964}
7065
7166// TODO: Figure out serialization more concretely - see issue #30
@@ -97,12 +92,6 @@ impl Readable for Event {
9792 let user_channel_id: u128 = Readable :: read ( reader) ?;
9893 Ok ( Self :: ChannelClosed { channel_id, user_channel_id } )
9994 }
100- //5u8 => {
101- // TODO OnChainPaymentSent
102- //}
103- //6u8 => {
104- // TODO OnChainPaymentReceived
105- //}
10695 _ => Err ( lightning:: ln:: msgs:: DecodeError :: InvalidValue ) ,
10796 }
10897 }
@@ -138,12 +127,7 @@ impl Writeable for Event {
138127 channel_id. write ( writer) ?;
139128 user_channel_id. write ( writer) ?;
140129 Ok ( ( ) )
141- } //Self::OnChainPaymentSent { .. } => {
142- //TODO
143- //}
144- //Self::OnChainPaymentReceived { .. } => {
145- //TODO
146- //}
130+ }
147131 }
148132 }
149133}
@@ -310,7 +294,7 @@ where
310294 output_script,
311295 ..
312296 } => {
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
314298 // channel.
315299 let confirmation_target = ConfirmationTarget :: Normal ;
316300
@@ -356,7 +340,7 @@ where
356340 } => {
357341 log_info ! (
358342 self . logger,
359- "Received payment from payment hash {} of {} millisatoshis " ,
343+ "Received payment from payment hash {} of {} msats " ,
360344 hex_utils:: to_string( & payment_hash. 0 ) ,
361345 amount_msat,
362346 ) ;
@@ -391,7 +375,7 @@ where
391375 } => {
392376 log_info ! (
393377 self . logger,
394- "Claimed payment from payment hash {} of {} millisatoshis ." ,
378+ "Claimed payment from payment hash {} of {} msats ." ,
395379 hex_utils:: to_string( & payment_hash. 0 ) ,
396380 amount_msat,
397381 ) ;
@@ -430,17 +414,18 @@ where
430414 payment. status = PaymentStatus :: Succeeded ;
431415 log_info ! (
432416 self . logger,
433- "Successfully sent payment of {} millisatoshis {} from \
417+ "Successfully sent payment of {} msats {} from \
434418 payment hash {:?} with preimage {:?}",
435419 payment. amount_msat. unwrap( ) ,
436420 if let Some ( fee) = fee_paid_msat {
437- format!( " (fee {} msat )" , fee)
421+ format!( " (fee {} msats )" , fee)
438422 } else {
439423 "" . to_string( )
440424 } ,
441425 hex_utils:: to_string( & payment_hash. 0 ) ,
442426 hex_utils:: to_string( & payment_preimage. 0 )
443427 ) ;
428+ break ;
444429 }
445430 }
446431 self . event_queue
@@ -450,7 +435,7 @@ where
450435 LdkEvent :: PaymentFailed { payment_hash, .. } => {
451436 log_info ! (
452437 self . logger,
453- "Failed to send payment to payment hash {:?}: exhausted payment retry attempts " ,
438+ "Failed to send payment to payment hash {:?}. " ,
454439 hex_utils:: to_string( & payment_hash. 0 )
455440 ) ;
456441
@@ -515,23 +500,19 @@ where
515500 let nodes = read_only_network_graph. nodes ( ) ;
516501 let channels = self . channel_manager . list_channels ( ) ;
517502
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+ } )
535516 } ;
536517 let channel_str = |channel_id : & Option < [ u8 ; 32 ] > | {
537518 channel_id
@@ -548,27 +529,22 @@ where
548529 let to_next_str =
549530 format ! ( " to {}{}" , node_str( & next_channel_id) , channel_str( & next_channel_id) ) ;
550531
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 {
557534 log_info ! (
558535 self . logger,
559- "Forwarded payment{}{}, earning {} msat {} " ,
536+ "Forwarded payment{}{}, earning {} msats in fees from claiming onchain. " ,
560537 from_prev_str,
561538 to_next_str,
562539 fee_earned,
563- from_onchain_str
564540 ) ;
565541 } else {
566542 log_info ! (
567543 self . logger,
568- "Forwarded payment{}{}, claiming onchain {} " ,
544+ "Forwarded payment{}{}, earning {} msats in fees. " ,
569545 from_prev_str,
570546 to_next_str,
571- from_onchain_str
547+ fee_earned ,
572548 ) ;
573549 }
574550 }
0 commit comments