Skip to content

Commit 88bed87

Browse files
committed
Add internal_connect_open_channel
Split the current `connect_open_channel` into two separate functions to utilise the code in future channel opening functions. More precisly, this is to use `internal_connect_open_channel` in a future commit by new `payjoin_connect_open_channel` function.
1 parent faa065f commit 88bed87

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

src/lib.rs

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -942,20 +942,6 @@ impl Node {
942942
return Err(Error::InsufficientFunds);
943943
}
944944

945-
let peer_info = PeerInfo { node_id, address };
946-
947-
let con_node_id = peer_info.node_id;
948-
let con_addr = peer_info.address.clone();
949-
let con_cm = Arc::clone(&self.connection_manager);
950-
951-
// We need to use our main runtime here as a local runtime might not be around to poll
952-
// connection futures going forward.
953-
tokio::task::block_in_place(move || {
954-
runtime.block_on(async move {
955-
con_cm.connect_peer_if_necessary(con_node_id, con_addr).await
956-
})
957-
})?;
958-
959945
let channel_config = (*(channel_config.unwrap_or_default())).clone().into();
960946
let user_config = UserConfig {
961947
channel_handshake_limits: Default::default(),
@@ -969,14 +955,41 @@ impl Node {
969955

970956
let push_msat = push_to_counterparty_msat.unwrap_or(0);
971957
let user_channel_id: u128 = rand::thread_rng().gen::<u128>();
958+
self.internal_connect_open_channel(
959+
node_id,
960+
channel_amount_sats,
961+
push_msat,
962+
user_channel_id,
963+
address,
964+
Some(user_config),
965+
runtime,
966+
)
967+
}
968+
969+
fn internal_connect_open_channel(
970+
&self, node_id: PublicKey, channel_amount_sats: u64, push_msat: u64, user_channel_id: u128,
971+
address: SocketAddress, user_config: Option<UserConfig>, runtime: &tokio::runtime::Runtime,
972+
) -> Result<UserChannelId, Error> {
973+
let peer_info = PeerInfo { node_id, address };
974+
let con_node_id = peer_info.node_id;
975+
let con_addr = peer_info.address.clone();
976+
let con_cm = Arc::clone(&self.connection_manager);
977+
978+
// We need to use our main runtime here as a local runtime might not be around to poll
979+
// connection futures going forward.
980+
tokio::task::block_in_place(move || {
981+
runtime.block_on(async move {
982+
con_cm.connect_peer_if_necessary(con_node_id, con_addr).await
983+
})
984+
})?;
972985

973986
match self.channel_manager.create_channel(
974987
peer_info.node_id,
975988
channel_amount_sats,
976989
push_msat,
977990
user_channel_id,
978991
None,
979-
Some(user_config),
992+
user_config,
980993
) {
981994
Ok(_) => {
982995
log_info!(

0 commit comments

Comments
 (0)