+fn do_disconnect_peer(
+ pubkey: bitcoin::secp256k1::PublicKey, peer_manager: Arc<PeerManager>,
+ channel_manager: Arc<ChannelManager>,
+) -> Result<(), ()> {
+ //check for open channels with peer
+ for channel in channel_manager.list_channels() {
+ if channel.counterparty.node_id == pubkey {
+ println!("Error: Node has an active channel with this peer, close any channels first");
+ return Err(());
+ }
+ }
+
+ //check the pubkey matches a valid connected peer
+ let peers = peer_manager.get_peer_node_ids();
+ if !peers.iter().any(|(pk, _)| &pubkey == pk) {
+ println!("Error: Could not find peer {}", pubkey);
+ return Err(());
+ }
+
+ peer_manager.disconnect_by_node_id(pubkey);
+ Ok(())
+}
+