Skip to content

Commit 1994fdd

Browse files
committed
Create HTLCDestination enum
1 parent b558603 commit 1994fdd

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;
@@ -799,6 +800,36 @@ impl fmt::Debug for ChannelError {
799800
}
800801
}
801802

803+
/// Used to return destination of where we are forwarding our HTLC to.
804+
#[derive(Clone, Debug)]
805+
pub enum HTLCDestination {
806+
OpenChannel { node_id: PublicKey, channel_id: [u8; 32] },
807+
Unknown { previous_hop_scid: u64 },
808+
Payment { payment_hash: PaymentHash, payment_preimage: Option<PaymentPreimage> },
809+
}
810+
811+
impl Writeable for HTLCDestination {
812+
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), Error> {
813+
match self {
814+
HTLCDestination::OpenChannel { ref node_id, ref channel_id } => {
815+
0u8.write(writer)?;
816+
node_id.write(writer)?;
817+
channel_id.write(writer)?;
818+
},
819+
HTLCDestination::Unknown { ref previous_hop_scid } => {
820+
1u8.write(writer)?;
821+
previous_hop_scid.write(writer)?;
822+
},
823+
HTLCDestination::Payment { ref payment_hash, ref payment_preimage } => {
824+
2u8.write(writer)?;
825+
payment_hash.write(writer)?;
826+
payment_preimage.write(writer)?;
827+
}
828+
}
829+
Ok(())
830+
}
831+
}
832+
802833
macro_rules! secp_check {
803834
($res: expr, $err: expr) => {
804835
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;
@@ -451,9 +451,9 @@ pub enum Event {
451451
/// Indicates that a payment has failed to be forwarded through us
452452
PaymentForwardedFailed {
453453
/// The channel_id of the sender
454-
source_channel_id: u64,
455-
/// The node_id of the receiver where forwarding has failed
456-
sink_node_id: PublicKey
454+
source_channel_id: [u8; 32],
455+
/// Destination of payment:
456+
destination: HTLCDestination
457457
},
458458
}
459459

@@ -573,11 +573,11 @@ impl Writeable for Event {
573573
// We never write the OpenChannelRequest events as, upon disconnection, peers
574574
// drop any channels which have not yet exchanged funding_signed.
575575
},
576-
&Event::PaymentForwardedFailed { ref source_channel_id, ref sink_node_id } => {
576+
&Event::PaymentForwardedFailed { ref source_channel_id, ref destination } => {
577577
18u8.write(writer)?;
578578
write_tlv_fields!(writer, {
579579
(0, source_channel_id, required),
580-
(2, sink_node_id, required),
580+
(2, destination, required),
581581
})
582582
}
583583
// Note that, going forward, all new events must only write data inside of

0 commit comments

Comments
 (0)