Skip to content

Commit f287cf6

Browse files
committed
f - Direction::select_node_id
1 parent 15964d3 commit f287cf6

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

lightning/src/blinded_path/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,17 @@ impl_writeable!(BlindedHop, {
229229
encrypted_payload
230230
});
231231

232+
impl Direction {
233+
/// Returns the [`NodeId`] from the inputs corresponding to the direction.
234+
pub fn select_node_id<'a>(&self, node_a: &'a NodeId, node_b: &'a NodeId) -> &'a NodeId {
235+
let (node_one, node_two) = if node_a < node_b {
236+
(node_a, node_b)
237+
} else {
238+
(node_b, node_a)
239+
};
240+
match self {
241+
Direction::NodeOne => node_one,
242+
Direction::NodeTwo => node_two,
243+
}
244+
}
245+
}

lightning/src/routing/router.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2558,15 +2558,7 @@ where L::Target: Logger {
25582558
);
25592559
match first_hop {
25602560
Some((counterparty_node_id, _)) => {
2561-
let (node_one, node_two) = if our_node_id < *counterparty_node_id {
2562-
(&our_node_id, counterparty_node_id)
2563-
} else {
2564-
(counterparty_node_id, &our_node_id)
2565-
};
2566-
match direction {
2567-
Direction::NodeOne => node_one,
2568-
Direction::NodeTwo => node_two,
2569-
}
2561+
direction.select_node_id(&our_node_id, counterparty_node_id)
25702562
},
25712563
None => continue,
25722564
}

0 commit comments

Comments
 (0)