11use crate :: types:: { Any , ClientId , Height , Time } ;
22use crate :: {
33 errors:: Error ,
4- path:: { ClientConsensusStatePath , ClientStatePath , ClientTypePath , NEXT_CLIENT_SEQUENCE } ,
4+ path:: { ClientConsensusStatePath , ClientStatePath , ClientTypePath } ,
55 prelude:: * ,
66} ;
77use store:: KVStore ;
@@ -12,6 +12,12 @@ pub trait HostContext {
1212}
1313
1414pub trait ClientReader : KVStore {
15+ /// Returns `true` if the client exists in the store.
16+ fn client_exists ( & self , client_id : & ClientId ) -> bool {
17+ self . get ( format ! ( "{}" , ClientTypePath :: new( client_id) ) . as_bytes ( ) )
18+ . is_some ( )
19+ }
20+
1521 /// Returns the ClientType for the given identifier `client_id`.
1622 fn client_type ( & self , client_id : & ClientId ) -> Result < String , Error > {
1723 let value = self . get ( format ! ( "{}" , ClientTypePath :: new( client_id) ) . as_bytes ( ) ) ;
@@ -54,19 +60,6 @@ pub trait ClientReader: KVStore {
5460 . 0 ,
5561 )
5662 }
57-
58- /// Returns a natural number, counting how many clients have been created thus far.
59- /// The value of this counter should increase only via method `ClientKeeper::increase_client_counter`.
60- fn client_counter ( & self ) -> Result < u64 , Error > {
61- match self . get ( NEXT_CLIENT_SEQUENCE . as_bytes ( ) ) {
62- Some ( bz) => {
63- let mut b: [ u8 ; 8 ] = Default :: default ( ) ;
64- b. copy_from_slice ( & bz) ;
65- Ok ( u64:: from_be_bytes ( b) )
66- }
67- None => Ok ( 0 ) ,
68- }
69- }
7063}
7164
7265pub trait ClientKeeper : ClientReader {
@@ -106,17 +99,6 @@ pub trait ClientKeeper: ClientReader {
10699 self . set ( format ! ( "{}" , path) . into_bytes ( ) , bz) ;
107100 Ok ( ( ) )
108101 }
109-
110- /// Called upon client creation.
111- /// Increases the counter which keeps track of how many clients have been created.
112- /// Should never fail.
113- fn increase_client_counter ( & mut self ) {
114- let next_counter = <Self as ClientReader >:: client_counter ( self ) . unwrap ( ) + 1 ;
115- self . set (
116- NEXT_CLIENT_SEQUENCE . as_bytes ( ) . to_vec ( ) ,
117- next_counter. to_be_bytes ( ) . to_vec ( ) ,
118- ) ;
119- }
120102}
121103
122104pub trait HostClientReader : HostContext + ClientReader { }
0 commit comments