Skip to content

Commit 87bcac6

Browse files
committed
Make open_channel_inner address parameter optional and use get_peer_address_if_connected
1 parent 1017438 commit 87bcac6

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/lib.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ impl Node {
10431043
}
10441044

10451045
fn open_channel_inner(
1046-
&self, node_id: PublicKey, address: SocketAddress, channel_amount_sats: u64,
1046+
&self, node_id: PublicKey, address: Option<SocketAddress>, channel_amount_sats: u64,
10471047
push_to_counterparty_msat: Option<u64>, channel_config: Option<ChannelConfig>,
10481048
announce_for_forwarding: bool,
10491049
) -> Result<UserChannelId, Error> {
@@ -1053,7 +1053,13 @@ impl Node {
10531053
}
10541054
let runtime = rt_lock.as_ref().unwrap();
10551055

1056-
let peer_info = PeerInfo { node_id, address };
1056+
// Get the address from the provided parameter or try to find an existing connection
1057+
let peer_address = match address {
1058+
Some(addr) => addr,
1059+
None => self.get_peer_address_if_connected(&node_id).ok_or(Error::ConnectionFailed)?,
1060+
};
1061+
1062+
let peer_info = PeerInfo { node_id, address: peer_address };
10571063

10581064
let con_node_id = peer_info.node_id;
10591065
let con_addr = peer_info.address.clone();
@@ -1185,7 +1191,7 @@ impl Node {
11851191
) -> Result<UserChannelId, Error> {
11861192
self.open_channel_inner(
11871193
node_id,
1188-
address,
1194+
Some(address),
11891195
channel_amount_sats,
11901196
push_to_counterparty_msat,
11911197
channel_config,
@@ -1221,7 +1227,7 @@ impl Node {
12211227
if may_announce_channel(&self.config) {
12221228
self.open_channel_inner(
12231229
node_id,
1224-
address,
1230+
Some(address),
12251231
channel_amount_sats,
12261232
push_to_counterparty_msat,
12271233
channel_config,

0 commit comments

Comments
 (0)