Skip to content

Commit

Permalink
f Preliminary handling of ChannelReady
Browse files Browse the repository at this point in the history
  • Loading branch information
tnull committed Nov 4, 2022
1 parent a834254 commit cc83be6
Showing 1 changed file with 54 additions and 23 deletions.
77 changes: 54 additions & 23 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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!(
Expand All @@ -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 { .. } => {}
Expand Down Expand Up @@ -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: {:?}",
Expand All @@ -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 { .. } => {}
}
Expand Down

0 comments on commit cc83be6

Please sign in to comment.