Skip to content

Commit 0675964

Browse files
committed
Create HTLCDestination enum
1 parent 357913d commit 0675964

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

lightning/src/ln/channel.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ use io;
4646
use prelude::*;
4747
use core::{cmp,mem,fmt};
4848
use core::ops::Deref;
49+
use io::Error;
4950
#[cfg(any(test, fuzzing, debug_assertions))]
5051
use sync::Mutex;
5152
use bitcoin::hashes::hex::ToHex;
@@ -804,6 +805,36 @@ impl fmt::Debug for ChannelError {
804805
}
805806
}
806807

808+
/// Used to return destination of where we are forwarding our HTLC to.
809+
#[derive(Clone, Debug)]
810+
pub enum HTLCDestination {
811+
OpenChannel { node_id: PublicKey, channel_id: [u8; 32] },
812+
Unknown { previous_hop_scid: u64 },
813+
Payment { payment_hash: PaymentHash, payment_preimage: Option<PaymentPreimage> },
814+
}
815+
816+
impl Writeable for HTLCDestination {
817+
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), Error> {
818+
match self {
819+
HTLCDestination::OpenChannel { ref node_id, ref channel_id } => {
820+
0u8.write(writer)?;
821+
node_id.write(writer)?;
822+
channel_id.write(writer)?;
823+
},
824+
HTLCDestination::Unknown { ref previous_hop_scid } => {
825+
1u8.write(writer)?;
826+
previous_hop_scid.write(writer)?;
827+
},
828+
HTLCDestination::Payment { ref payment_hash, ref payment_preimage } => {
829+
2u8.write(writer)?;
830+
payment_hash.write(writer)?;
831+
payment_preimage.write(writer)?;
832+
}
833+
}
834+
Ok(())
835+
}
836+
}
837+
807838
macro_rules! secp_check {
808839
($res: expr, $err: expr) => {
809840
match $res {

lightning/src/util/events.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
1717
use chain::keysinterface::SpendableOutputDescriptor;
1818
use ln::channelmanager::PaymentId;
19-
use ln::channel::FUNDING_CONF_DEADLINE_BLOCKS;
19+
use ln::channel::{FUNDING_CONF_DEADLINE_BLOCKS, HTLCDestination};
2020
use ln::features::ChannelTypeFeatures;
2121
use ln::msgs;
2222
use ln::msgs::DecodeError;
@@ -505,9 +505,9 @@ pub enum Event {
505505
/// Indicates that a payment has failed to be forwarded through us
506506
PaymentForwardedFailed {
507507
/// The channel_id of the sender
508-
source_channel_id: u64,
509-
/// The node_id of the receiver where forwarding has failed
510-
sink_node_id: PublicKey
508+
source_channel_id: [u8; 32],
509+
/// Destination of payment:
510+
destination: HTLCDestination
511511
},
512512
}
513513

@@ -636,11 +636,11 @@ impl Writeable for Event {
636636
(4, amount_msat, required),
637637
});
638638
},
639-
&Event::PaymentForwardedFailed { ref source_channel_id, ref sink_node_id } => {
639+
&Event::PaymentForwardedFailed { ref source_channel_id, ref destination } => {
640640
21u8.write(writer)?;
641641
write_tlv_fields!(writer, {
642642
(0, source_channel_id, required),
643-
(2, sink_node_id, required),
643+
(2, destination, required),
644644
})
645645
}
646646
// Note that, going forward, all new events must only write data inside of

0 commit comments

Comments
 (0)