diff --git a/src/event.rs b/src/event.rs index 2e4008b9f..c8b807b4d 100644 --- a/src/event.rs +++ b/src/event.rs @@ -51,13 +51,19 @@ pub enum LdkLiteEvent { /// The value, in thousandths of a satoshi that has been received. amount_msat: u64, }, - // TODO: Implement after a corresponding LDK event is added. - //ChannelOpened { - //}, + /// A channel is ready to be used. + ChannelReady { + /// The channel_id of the channel which is ready. + channel_id: [u8; 32], + /// The user_channel_id of the channel which is ready. + user_channel_id: u64, + }, /// A channel has been closed. ChannelClosed { /// The channel_id of the channel which has been closed. channel_id: [u8; 32], + /// The user_channel_id of the channel which has been closed. + user_channel_id: u64, }, // TODO: Implement on-chain events when better integrating with BDK wallet sync. //OnChainPaymentSent { @@ -84,12 +90,15 @@ impl Readable for LdkLiteEvent { let amount_msat: u64 = Readable::read(reader)?; Ok(Self::PaymentReceived { payment_hash, amount_msat }) } - //3u8 => { - // TODO ChannelOpened - //} + 3u8 => { + let channel_id: [u8; 32] = Readable::read(reader)?; + let user_channel_id: u64 = Readable::read(reader)?; + Ok(Self::ChannelReady { channel_id, user_channel_id }) + } 4u8 => { let channel_id: [u8; 32] = Readable::read(reader)?; - Ok(Self::ChannelClosed { channel_id }) + let user_channel_id: u64 = Readable::read(reader)?; + Ok(Self::ChannelClosed { channel_id, user_channel_id }) } //5u8 => { // TODO OnChainPaymentSent @@ -121,12 +130,16 @@ impl Writeable for LdkLiteEvent { amount_msat.write(writer)?; Ok(()) } - //Self::ChannelOpened { .. } => { - //TODO - //} - Self::ChannelClosed { channel_id } => { + Self::ChannelReady { channel_id, user_channel_id } => { + 3u8.write(writer)?; + channel_id.write(writer)?; + user_channel_id.write(writer)?; + Ok(()) + } + Self::ChannelClosed { channel_id, user_channel_id } => { 4u8.write(writer)?; channel_id.write(writer)?; + user_channel_id.write(writer)?; Ok(()) } //Self::OnChainPaymentSent { .. } => { //TODO @@ -318,7 +331,7 @@ impl LdkEventHandler for LdkLiteEventHandler { payment_hash: *payment_hash, amount_msat: *amount_msat, }) - .unwrap(); + .expect("Failed to push to event queue"); } else { log_error!( self.logger, @@ -361,6 +374,12 @@ impl LdkEventHandler for LdkLiteEventHandler { }); } } + self.event_queue + .add_event(Event::PaymentReceived { + payment_hash: *payment_hash, + amount_msat: *amount_msat, + }) + .expect("Failed to push to event queue"); } LdkEvent::PaymentSent { payment_preimage, @@ -389,10 +408,8 @@ impl LdkEventHandler for LdkLiteEventHandler { } } self.event_queue - .add_event(LdkLiteEvent::PaymentSuccessful { - payment_hash: *payment_hash, - }) - .unwrap(); + .add_event(Event::PaymentSuccessful { payment_hash: *payment_hash }) + .expect("Failed to push to event queue"); } LdkEvent::PaymentFailed { payment_hash, .. } => { log_info!( @@ -408,10 +425,8 @@ impl LdkEventHandler for LdkLiteEventHandler { payment.status = PaymentStatus::Failed; } self.event_queue - .add_event(LdkLiteEvent::PaymentFailed { - payment_hash: *payment_hash, - }) - .unwrap(); + .add_event(Event::PaymentFailed { payment_hash: *payment_hash }) + .expect("Failed to push to event queue"); } LdkEvent::PaymentPathSuccessful { .. } => {} @@ -514,8 +529,23 @@ impl LdkEventHandler for LdkLiteEventHandler { ); } } - - LdkEvent::ChannelClosed { channel_id, reason, user_channel_id: _ } => { + LdkEvent::ChannelReady { + channel_id, user_channel_id, counterparty_node_id, .. + } => { + log_info!( + self.logger, + "Channel {} with {} ready to be used.", + hex_utils::to_string(channel_id), + counterparty_node_id, + ); + self.event_queue + .add_event(LdkLiteEvent::ChannelReady { + channel_id: *channel_id, + user_channel_id: *user_channel_id, + }) + .expect("Failed to push to event queue"); + } + LdkEvent::ChannelClosed { channel_id, reason, user_channel_id } => { log_info!( self.logger, "Channel {} closed due to: {:?}", @@ -525,8 +555,9 @@ impl LdkEventHandler for LdkLiteEventHandler { self.event_queue .add_event(LdkLiteEvent::ChannelClosed { channel_id: *channel_id, + user_channel_id: *user_channel_id, }) - .unwrap(); + .expect("Failed to push to event queue"); } LdkEvent::DiscardFunding { .. } => {} }