polytone_evm/handshake/
mod.rs1use cosmwasm_std::{
2 to_json_binary, Ibc3ChannelOpenResponse, IbcChannelOpenMsg, IbcChannelOpenResponse, IbcOrder,
3};
4
5use error::HandshakeError;
6
7pub const POLYTONE_VERSION: &str = "polytone-1";
8
9pub fn note_version() -> String {
12 format!("{POLYTONE_VERSION}-note")
13}
14
15pub fn voice_version() -> String {
18 format!("{POLYTONE_VERSION}-voice")
19}
20
21fn open(
34 msg: &IbcChannelOpenMsg,
35 extensions: &[&str],
36 version: String,
37 counterparty_version: String,
38) -> Result<IbcChannelOpenResponse, HandshakeError> {
39 match msg {
40 IbcChannelOpenMsg::OpenInit { channel } => {
41 if channel.version != POLYTONE_VERSION {
42 Err(HandshakeError::ProtocolMismatch {
43 actual: channel.version.clone(),
44 expected: POLYTONE_VERSION.to_string(),
45 })
46 } else if channel.order != IbcOrder::Unordered {
47 Err(HandshakeError::ExpectUnordered)
48 } else {
49 Ok(Some(Ibc3ChannelOpenResponse { version }))
50 }
51 }
52 IbcChannelOpenMsg::OpenTry {
53 channel,
54 counterparty_version: cv,
55 } => {
56 if *cv != counterparty_version {
57 Err(HandshakeError::WrongCounterparty)
58 } else if channel.order != IbcOrder::Unordered {
59 Err(HandshakeError::ExpectUnordered)
60 } else {
61 Ok(Some(Ibc3ChannelOpenResponse {
62 version: to_json_binary(extensions).unwrap().to_base64(),
63 }))
64 }
65 }
66 }
67}
68
69pub mod error;
70pub mod note;
71pub mod voice;
72
73#[cfg(test)]
74mod tests;