penumbra_ibc/
version.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use ibc_types::core::connection::Version;

/// Selects a version from the intersection of locally supported and counterparty versions.
pub fn pick_connection_version(
    supported_versions: &[Version],
    counterparty_versions: &[Version],
) -> anyhow::Result<Version> {
    let mut intersection: Vec<Version> = Vec::new();
    for s in supported_versions.iter() {
        for c in counterparty_versions.iter() {
            if c.identifier != s.identifier {
                continue;
            }
            for feature in c.features.iter() {
                if feature.trim().is_empty() {
                    anyhow::bail!("freatures cannot be empty");
                }
            }
            intersection.append(&mut vec![s.clone()]);
        }
    }
    intersection.sort_by(|a, b| a.identifier.cmp(&b.identifier));
    if intersection.is_empty() {
        anyhow::bail!("no common version");
    }
    Ok(intersection[0].clone())
}