polytone_evm/handshake/
note.rs

1use cosmwasm_std::{
2    from_json, Binary, IbcChannelConnectMsg, IbcChannelOpenMsg, IbcChannelOpenResponse,
3};
4
5use super::{error::HandshakeError, note_version, voice_version};
6
7/// Performs the open step of the IBC handshake for a note module.
8///
9/// # Arguments
10///
11/// - `extensions` the Polytone extensions supported by the caller.
12///   Extensions are explained in detail in the polytone spec.
13/// - `msg` the message received to open the channel.
14pub fn open(
15    msg: &IbcChannelOpenMsg,
16    extensions: &[&str],
17) -> Result<IbcChannelOpenResponse, HandshakeError> {
18    super::open(msg, extensions, note_version(), voice_version())
19}
20
21/// Performs the connect step of the IBC handshake for a voice module.
22///
23/// # Arguments
24///
25/// - `extensions` the Polytone extensions supported by the caller.
26///   Extensions are explained in detail in the polytone spec.
27pub fn connect(msg: &IbcChannelConnectMsg, extensions: &[&str]) -> Result<(), HandshakeError> {
28    match msg {
29        IbcChannelConnectMsg::OpenAck {
30            channel: _,
31            counterparty_version,
32        } => {
33            let proposed_version: Vec<String> =
34                from_json(Binary::from_base64(counterparty_version).unwrap()).unwrap();
35            let subseteq_violation = extensions
36                .iter()
37                .find(|e| !proposed_version.contains(&e.to_string()));
38            match subseteq_violation {
39                None => Ok(()),
40                Some(first_voilation) => {
41                    Err(HandshakeError::Unspeakable(first_voilation.to_string()))
42                }
43            }
44        }
45        IbcChannelConnectMsg::OpenConfirm { channel: _ } => Ok(()),
46    }
47}