@@ -8,11 +8,11 @@ pub mod conn_open_confirm;
8
8
pub mod conn_open_init;
9
9
pub mod conn_open_try;
10
10
11
- /// Unpacks the client state from the provided [`Any`] type .
11
+ /// Unpacks the client state from the format that is stored at the counterparty chain .
12
12
///
13
- /// Currently, the IBC-go enabled chains stores Wasm LightClient states in a
14
- /// WasmClientState wrapper. This function unpacks the client state from
15
- /// the WasmClientState wrapper if the client identifier is of Wasm client type.
13
+ /// Currently, the IBC-go enabled chains stores Wasm LightClient states in a WasmClientState
14
+ /// wrapper. This function unpacks the client state from the WasmClientState wrapper
15
+ /// if the client identifier at counterparty is of Wasm client type.
16
16
pub ( crate ) fn unpack_host_client_state < CS > (
17
17
value : Any ,
18
18
host_client_id_at_counterparty : & ClientId ,
21
21
CS : TryFrom < Any > ,
22
22
<CS as TryFrom < Any > >:: Error : Into < ClientError > ,
23
23
{
24
- #[ cfg( feature = "wasm-wrapped- client-state " ) ]
24
+ #[ cfg( feature = "wasm-client" ) ]
25
25
if host_client_id_at_counterparty. is_wasm_client_id ( ) {
26
26
use ibc_client_wasm_types:: client_state:: ClientState as WasmClientState ;
27
27
use ibc_core_connection_types:: error:: ConnectionError ;
@@ -46,10 +46,44 @@ where
46
46
Ok ( CS :: try_from ( value) . map_err ( Into :: < ClientError > :: into) ?)
47
47
}
48
48
49
- #[ cfg( not( feature = "wasm-wrapped- client-state " ) ) ]
49
+ #[ cfg( not( feature = "wasm-client" ) ) ]
50
50
{
51
51
// this avoids lint warning for unused variable.
52
52
let _ = host_client_id_at_counterparty;
53
53
Ok ( CS :: try_from ( value) . map_err ( Into :: < ClientError > :: into) ?)
54
54
}
55
55
}
56
+
57
+ /// Pack the host consensus state in the expected format stored at the counterparty chain.
58
+ ///
59
+ /// Currently, the IBC-go enabled chains stores Wasm LightClient states in a WasmConsensusState
60
+ /// wrapper. This function packs the consensus state in the WasmConsensusState wrapper
61
+ /// if the client identifier at counterparty is of Wasm client type.
62
+ pub ( crate ) fn pack_host_consensus_state < CS > (
63
+ value : CS ,
64
+ host_client_id_at_counterparty : & ClientId ,
65
+ ) -> Any
66
+ where
67
+ CS : Into < Any > ,
68
+ {
69
+ let any_value = value. into ( ) ;
70
+
71
+ #[ cfg( feature = "wasm-client" ) ]
72
+ if host_client_id_at_counterparty. is_wasm_client_id ( ) {
73
+ use ibc_client_wasm_types:: consensus_state:: ConsensusState as WasmConsensusState ;
74
+ use prost:: Message ;
75
+
76
+ let wasm_consensus_state = WasmConsensusState :: new ( any_value. encode_to_vec ( ) ) ;
77
+
78
+ wasm_consensus_state. into ( )
79
+ } else {
80
+ any_value
81
+ }
82
+
83
+ #[ cfg( not( feature = "wasm-client" ) ) ]
84
+ {
85
+ // this avoids lint warning for unused variable.
86
+ let _ = host_client_id_at_counterparty;
87
+ any_value
88
+ }
89
+ }
0 commit comments