ibc_core_connection/handler/
mod.rs1use ibc_core_client::types::error::ClientError;
2use ibc_core_connection_types::error::ConnectionError;
3#[cfg(feature = "wasm-client")]
4use ibc_core_host::types::error::DecodingError;
5use ibc_core_host::types::identifiers::ClientId;
6use ibc_primitives::proto::Any;
7
8pub mod conn_open_ack;
9pub mod conn_open_confirm;
10pub mod conn_open_init;
11pub mod conn_open_try;
12
13pub(crate) fn unpack_host_client_state<CS>(
19 value: Any,
20 host_client_id_at_counterparty: &ClientId,
21) -> Result<CS, ConnectionError>
22where
23 CS: TryFrom<Any>,
24 <CS as TryFrom<Any>>::Error: Into<ClientError>,
25{
26 #[cfg(feature = "wasm-client")]
27 if host_client_id_at_counterparty.is_wasm_client_id() {
28 use ibc_client_wasm_types::client_state::ClientState as WasmClientState;
29 use prost::Message;
30
31 let wasm_client_state = WasmClientState::try_from(value)?;
32
33 let any_client_state = <Any as Message>::decode(wasm_client_state.data.as_slice())
34 .map_err(|e| ConnectionError::Decoding(DecodingError::Prost(e)))?;
35
36 Ok(CS::try_from(any_client_state).map_err(Into::<ClientError>::into)?)
37 } else {
38 Ok(CS::try_from(value).map_err(Into::<ClientError>::into)?)
39 }
40
41 #[cfg(not(feature = "wasm-client"))]
42 {
43 let _ = host_client_id_at_counterparty;
45 Ok(CS::try_from(value).map_err(Into::<ClientError>::into)?)
46 }
47}
48
49pub(crate) fn pack_host_consensus_state<CS>(
55 value: CS,
56 host_client_id_at_counterparty: &ClientId,
57) -> Any
58where
59 CS: Into<Any>,
60{
61 let any_value = value.into();
62
63 #[cfg(feature = "wasm-client")]
64 if host_client_id_at_counterparty.is_wasm_client_id() {
65 use ibc_client_wasm_types::consensus_state::ConsensusState as WasmConsensusState;
66 use prost::Message;
67
68 let wasm_consensus_state = WasmConsensusState::new(any_value.encode_to_vec());
69
70 wasm_consensus_state.into()
71 } else {
72 any_value
73 }
74
75 #[cfg(not(feature = "wasm-client"))]
76 {
77 let _ = host_client_id_at_counterparty;
79 any_value
80 }
81}