Ok(())
}
- /// Gets the list of open channels, in random order. See ChannelDetail field documentation for
- /// more information.
- pub fn list_channels(&self) -> Vec<ChannelDetails> {
+ fn list_channels_with_filter<F: FnMut(&(&[u8; 32], &Channel<ChanSigner>)) -> bool>(&self, f: F) -> Vec<ChannelDetails> {
let mut res = Vec::new();
{
let channel_state = self.channel_state.lock().unwrap();
res.reserve(channel_state.by_id.len());
- for (channel_id, channel) in channel_state.by_id.iter() {
+ for (channel_id, channel) in channel_state.by_id.iter().filter(f) {
let (inbound_capacity_msat, outbound_capacity_msat) = channel.get_inbound_outbound_available_balance_msat();
res.push(ChannelDetails {
channel_id: (*channel_id).clone(),
res
}
+ /// Gets the list of open channels, in random order. See ChannelDetail field documentation for
+ /// more information.
+ pub fn list_channels(&self) -> Vec<ChannelDetails> {
+ self.list_channels_with_filter(|_| true)
+ }
+
/// Gets the list of usable channels, in random order. Useful as an argument to
/// Router::get_route to ensure non-announced channels are used.
///
/// These are guaranteed to have their is_live value set to true, see the documentation for
/// ChannelDetails::is_live for more info on exactly what the criteria are.
pub fn list_usable_channels(&self) -> Vec<ChannelDetails> {
- let mut res = Vec::new();
- {
- let channel_state = self.channel_state.lock().unwrap();
- res.reserve(channel_state.by_id.len());
- for (channel_id, channel) in channel_state.by_id.iter() {
- // Note we use is_live here instead of usable which leads to somewhat confused
- // internal/external nomenclature, but that's ok cause that's probably what the user
- // really wanted anyway.
- if channel.is_live() {
- let (inbound_capacity_msat, outbound_capacity_msat) = channel.get_inbound_outbound_available_balance_msat();
- res.push(ChannelDetails {
- channel_id: (*channel_id).clone(),
- short_channel_id: channel.get_short_channel_id(),
- remote_network_id: channel.get_their_node_id(),
- counterparty_features: InitFeatures::empty(),
- channel_value_satoshis: channel.get_value_satoshis(),
- inbound_capacity_msat,
- outbound_capacity_msat,
- user_id: channel.get_user_id(),
- is_live: true,
- });
- }
- }
- }
- let per_peer_state = self.per_peer_state.read().unwrap();
- for chan in res.iter_mut() {
- if let Some(peer_state) = per_peer_state.get(&chan.remote_network_id) {
- chan.counterparty_features = peer_state.lock().unwrap().latest_features.clone();
- }
- }
- res
+ // Note we use is_live here instead of usable which leads to somewhat confused
+ // internal/external nomenclature, but that's ok cause that's probably what the user
+ // really wanted anyway.
+ self.list_channels_with_filter(|&(_, ref channel)| channel.is_live())
}
/// Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs