@@ -21,29 +21,31 @@ use crate::ibc::connection_03::client_connections_path;
2121use crate :: ibc:: connection_03:: types:: { ConnectionEnd , ConnectionIdentifiersInClient , ConnectionState } ;
2222use rlp:: { Encodable , Rlp } ;
2323
24- #[ derive( Default ) ]
25- pub struct Manager { }
24+ pub struct Manager < ' a > {
25+ ctx : & ' a mut dyn ibc:: Context ,
26+ }
2627
2728// FIXME: this will be changed after implementing Vector commitment
2829fn get_commiment_prefix ( ) -> String {
2930 "" . to_owned ( )
3031}
3132
32- impl Manager {
33- pub fn new ( ) -> Self {
34- Manager { }
33+ impl < ' a > Manager < ' a > {
34+ pub fn new ( ctx : & ' a mut dyn ibc:: Context ) -> Self {
35+ Manager {
36+ ctx,
37+ }
3538 }
3639
3740 pub fn handle_open_init (
38- & self ,
39- ctx : & mut dyn ibc:: Context ,
41+ & mut self ,
4042 identifier : Identifier ,
4143 desired_counterparty_connection_identifier : Identifier ,
4244 counterparty_prefix : CommitmentPrefix ,
4345 client_identifier : Identifier ,
4446 counterparty_client_identifier : Identifier ,
4547 ) -> Result < ( ) , String > {
46- let kv_store = ctx. get_kv_store ( ) ;
48+ let kv_store = self . ctx . get_kv_store ( ) ;
4749 if kv_store. has ( & connection_path ( & identifier) ) {
4850 return Err ( "Connection exist" . to_owned ( ) )
4951 }
@@ -56,15 +58,14 @@ impl Manager {
5658 counterparty_client_identifier,
5759 } ;
5860 kv_store. set ( & connection_path ( & identifier) , & connection. rlp_bytes ( ) ) ;
59- self . add_connection_to_client ( ctx , client_identifier, identifier) ?;
61+ self . add_connection_to_client ( client_identifier, identifier) ?;
6062 Ok ( ( ) )
6163 }
6264
6365 // We all following ICS spec.
6466 #[ allow( clippy:: too_many_arguments) ]
6567 pub fn handle_open_try (
66- & self ,
67- ctx : & mut dyn ibc:: Context ,
68+ & mut self ,
6869 desired_identifier : Identifier ,
6970 counterparty_connection_identifier : Identifier ,
7071 counterparty_prefix : CommitmentPrefix ,
@@ -75,7 +76,7 @@ impl Manager {
7576 proof_height : u64 ,
7677 consensus_height : u64 ,
7778 ) -> Result < ( ) , String > {
78- let current_height = ctx. get_current_height ( ) ;
79+ let current_height = self . ctx . get_current_height ( ) ;
7980 if consensus_height > current_height {
8081 return Err ( format ! (
8182 "Consensus height {} is greater than current height {}" ,
@@ -98,9 +99,9 @@ impl Manager {
9899 counterparty_client_identifier : counterparty_client_identifier. clone ( ) ,
99100 } ;
100101
101- self . verify_connection_state ( ctx , & connection, proof_height, proof_init, desired_identifier. clone ( ) , & expected) ;
102+ self . verify_connection_state ( & connection, proof_height, proof_init, desired_identifier. clone ( ) , & expected) ;
102103
103- if let Some ( previous_connection_end) = self . query ( ctx , & desired_identifier) {
104+ if let Some ( previous_connection_end) = self . query ( & desired_identifier) {
104105 let expected_init = ConnectionEnd {
105106 state : ConnectionState :: INIT ,
106107 counterparty_connection_identifier,
@@ -116,13 +117,13 @@ impl Manager {
116117 }
117118 }
118119
119- let kv_store = ctx. get_kv_store ( ) ;
120+ let kv_store = self . ctx . get_kv_store ( ) ;
120121 kv_store. set ( & connection_path ( & desired_identifier) , & connection. rlp_bytes ( ) ) ;
121122 Ok ( ( ) )
122123 }
123124
124- fn query ( & self , ctx : & mut dyn ibc :: Context , identifier : & str ) -> Option < ConnectionEnd > {
125- let kv_store = ctx. get_kv_store ( ) ;
125+ fn query ( & mut self , identifier : & str ) -> Option < ConnectionEnd > {
126+ let kv_store = self . ctx . get_kv_store ( ) ;
126127
127128 let path = connection_path ( & identifier) ;
128129 if kv_store. has ( & path) {
@@ -135,8 +136,7 @@ impl Manager {
135136 }
136137
137138 fn verify_connection_state (
138- & self ,
139- ctx : & mut dyn ibc:: Context ,
139+ & mut self ,
140140 connection : & ConnectionEnd ,
141141 proof_height : u64 ,
142142 proof : CommitmentProof ,
@@ -160,12 +160,11 @@ impl Manager {
160160 }
161161
162162 fn add_connection_to_client (
163- & self ,
164- ctx : & mut dyn ibc:: Context ,
163+ & mut self ,
165164 client_identifier : Identifier ,
166165 connection_identifier : Identifier ,
167166 ) -> Result < ( ) , String > {
168- let kv_store = ctx. get_kv_store ( ) ;
167+ let kv_store = self . ctx . get_kv_store ( ) ;
169168 if kv_store. has ( & connection_path ( & connection_identifier) ) {
170169 return Err ( "Connection exist" . to_owned ( ) )
171170 }
0 commit comments