penumbra_sdk_ibc/
version.rs

1use ibc_types::core::connection::Version;
2
3/// Selects a version from the intersection of locally supported and counterparty versions.
4pub fn pick_connection_version(
5    supported_versions: &[Version],
6    counterparty_versions: &[Version],
7) -> anyhow::Result<Version> {
8    let mut intersection: Vec<Version> = Vec::new();
9    for s in supported_versions.iter() {
10        for c in counterparty_versions.iter() {
11            if c.identifier != s.identifier {
12                continue;
13            }
14            for feature in c.features.iter() {
15                if feature.trim().is_empty() {
16                    anyhow::bail!("freatures cannot be empty");
17                }
18            }
19            intersection.append(&mut vec![s.clone()]);
20        }
21    }
22    intersection.sort_by(|a, b| a.identifier.cmp(&b.identifier));
23    if intersection.is_empty() {
24        anyhow::bail!("no common version");
25    }
26    Ok(intersection[0].clone())
27}