1+ #[ cfg( not( target_arch = "wasm32" ) ) ]
12use std:: path:: { Path , PathBuf } ;
23
34use super :: graph:: UdtCfgInfos ;
@@ -8,8 +9,10 @@ use crate::fiber::{
89 types:: { Hash256 , Pubkey } ,
910 FiberConfig , NetworkActorCommand , NetworkActorMessage ,
1011} ;
12+ #[ cfg( not( target_arch = "wasm32" ) ) ]
1113use crate :: now_timestamp_as_millis_u64;
12- use crate :: rpc:: server:: RpcServerStore ;
14+ #[ cfg( not( target_arch = "wasm32" ) ) ]
15+ use crate :: rpc:: server:: { KVStore , RpcServerStore } ;
1316use crate :: { handle_actor_call, log_and_error} ;
1417use ckb_jsonrpc_types:: Script ;
1518#[ cfg( not( target_arch = "wasm32" ) ) ]
@@ -18,6 +21,7 @@ use jsonrpsee::types::error::CALL_EXECUTION_FAILED_CODE;
1821use jsonrpsee:: types:: ErrorObjectOwned ;
1922
2023use ractor:: { call, ActorRef } ;
24+ #[ cfg( not( target_arch = "wasm32" ) ) ]
2125use rocksdb:: checkpoint:: Checkpoint ;
2226use serde:: { Deserialize , Serialize } ;
2327use serde_with:: serde_as;
@@ -96,19 +100,36 @@ pub struct BackupResult {
96100
97101pub struct InfoRpcServerImpl < S > {
98102 actor : ActorRef < NetworkActorMessage > ,
103+
104+ default_funding_lock_script : Script ,
105+
106+ #[ cfg( not( target_arch = "wasm32" ) ) ]
99107 store : S ,
100- ckb_key_path : PathBuf ,
108+ # [ cfg ( not ( target_arch = "wasm32" ) ) ]
101109 fiber_key_path : PathBuf ,
102- default_funding_lock_script : Script ,
110+ #[ cfg( not( target_arch = "wasm32" ) ) ]
111+ ckb_key_path : PathBuf ,
112+
113+ #[ cfg( target_arch = "wasm32" ) ]
114+ _marker : std:: marker:: PhantomData < S > ,
103115}
104116
105- impl < S : RpcServerStore + Clone + Send + Sync + ' static > InfoRpcServerImpl < S > {
117+ #[ cfg( not( target_arch = "wasm32" ) ) ]
118+ pub trait StoreInfo : RpcServerStore + KVStore + Clone + Send + Sync + ' static { }
119+ #[ cfg( not( target_arch = "wasm32" ) ) ]
120+ impl < T > StoreInfo for T where T : RpcServerStore + KVStore + Clone + Send + Sync + ' static { }
121+ #[ cfg( target_arch = "wasm32" ) ]
122+ pub trait StoreInfo : Clone + Send + Sync + ' static { }
123+ #[ cfg( target_arch = "wasm32" ) ]
124+ impl < T > StoreInfo for T where T : Clone + Send + Sync + ' static { }
125+
126+ impl < S : StoreInfo > InfoRpcServerImpl < S > {
106127 #[ allow( unused_variables) ]
107128 pub fn new (
108129 actor : ActorRef < NetworkActorMessage > ,
109130 store : S ,
110131 ckb_config : CkbConfig ,
111- fiber_config : FiberConfig ,
132+ fiber_config : Option < FiberConfig > ,
112133 ) -> Self {
113134 #[ cfg( not( test) ) ]
114135 let default_funding_lock_script = ckb_config
@@ -121,15 +142,21 @@ impl<S: RpcServerStore + Clone + Send + Sync + 'static> InfoRpcServerImpl<S> {
121142 #[ cfg( test) ]
122143 let default_funding_lock_script = Default :: default ( ) ;
123144
124- let ckb_key_path = ckb_config . base_dir ( ) . join ( "key" ) ;
125- let fiber_key_path = fiber_config. base_dir ( ) . join ( "sk ") ;
145+ # [ cfg ( not ( target_arch = "wasm32" ) ) ]
146+ let fiber_config = fiber_config. expect ( "fiber config should be set ") ;
126147
127148 InfoRpcServerImpl {
128149 actor,
129- store,
130- ckb_key_path,
131- fiber_key_path,
132150 default_funding_lock_script,
151+
152+ #[ cfg( not( target_arch = "wasm32" ) ) ]
153+ store,
154+ #[ cfg( not( target_arch = "wasm32" ) ) ]
155+ ckb_key_path : ckb_config. base_dir ( ) . join ( "key" ) ,
156+ #[ cfg( not( target_arch = "wasm32" ) ) ]
157+ fiber_key_path : fiber_config. base_dir ( ) . join ( "sk" ) ,
158+ #[ cfg( target_arch = "wasm32" ) ]
159+ _marker : std:: marker:: PhantomData ,
133160 }
134161 }
135162}
@@ -142,14 +169,14 @@ trait InfoRpc {
142169 #[ method( name = "node_info" ) ]
143170 async fn node_info ( & self ) -> Result < NodeInfoResult , ErrorObjectOwned > ;
144171
145- //Back the node information .
172+ /// Backup the node database and key files to a specified path .
146173 #[ method( name = "backup_now" ) ]
147174 async fn backup_now ( & self , path : String ) -> Result < BackupResult , ErrorObjectOwned > ;
148175}
149176
150177#[ async_trait:: async_trait]
151178#[ cfg( not( target_arch = "wasm32" ) ) ]
152- impl < S : RpcServerStore + Clone + Send + Sync + ' static > InfoRpcServer for InfoRpcServerImpl < S > {
179+ impl < S : StoreInfo > InfoRpcServer for InfoRpcServerImpl < S > {
153180 async fn node_info ( & self ) -> Result < NodeInfoResult , ErrorObjectOwned > {
154181 self . node_info ( ) . await
155182 }
@@ -158,7 +185,8 @@ impl<S: RpcServerStore + Clone + Send + Sync + 'static> InfoRpcServer for InfoRp
158185 self . backup_now ( path) . await
159186 }
160187}
161- impl < S : RpcServerStore + Clone + Send + Sync + ' static > InfoRpcServerImpl < S > {
188+
189+ impl < S : StoreInfo > InfoRpcServerImpl < S > {
162190 pub async fn node_info ( & self ) -> Result < NodeInfoResult , ErrorObjectOwned > {
163191 let version = env ! ( "CARGO_PKG_VERSION" ) . to_string ( ) ;
164192 let commit_hash = crate :: get_git_commit_info ( ) ;
@@ -188,6 +216,7 @@ impl<S: RpcServerStore + Clone + Send + Sync + 'static> InfoRpcServerImpl<S> {
188216 } )
189217 }
190218
219+ #[ cfg( not( target_arch = "wasm32" ) ) ]
191220 async fn backup_now ( & self , path : String ) -> Result < BackupResult , ErrorObjectOwned > {
192221 let target_dir = PathBuf :: from ( & path) ;
193222
@@ -222,9 +251,8 @@ impl<S: RpcServerStore + Clone + Send + Sync + 'static> InfoRpcServerImpl<S> {
222251 timestamp : now,
223252 } )
224253 }
225- }
226254
227- impl < S : RpcServerStore > InfoRpcServerImpl < S > {
255+ # [ cfg ( not ( target_arch = "wasm32" ) ) ]
228256 fn perform_key_backup ( & self , target_dir : & Path ) -> Result < ( ) , ErrorObjectOwned > {
229257 let keys_to_copy = [ ( & self . ckb_key_path , "key" ) , ( & self . fiber_key_path , "sk" ) ] ;
230258
@@ -246,7 +274,7 @@ impl<S: RpcServerStore> InfoRpcServerImpl<S> {
246274 }
247275}
248276
249- #[ cfg( test) ]
277+ #[ cfg( all ( test, not ( target_arch = "wasm32" ) ) ) ]
250278mod tests {
251279 use super :: * ;
252280 use crate :: test_utils:: { generate_store, get_fiber_config, NetworkNode , TempDir } ;
@@ -268,15 +296,15 @@ mod tests {
268296 let ckb_key_dir = ckb_config. base_dir . as_ref ( ) . unwrap ( ) ;
269297 let fiber_key_dir = fiber_config. base_dir ( ) . to_path_buf ( ) ;
270298
271- fs:: create_dir_all ( & ckb_key_dir) . unwrap ( ) ;
299+ fs:: create_dir_all ( ckb_key_dir) . unwrap ( ) ;
272300 fs:: create_dir_all ( & fiber_key_dir) . unwrap ( ) ;
273301 fs:: write ( ckb_key_dir. join ( "key" ) , "mock_ckb_key" ) . unwrap ( ) ;
274302 fs:: write ( fiber_key_dir. join ( "sk" ) , "mock_fiber_key" ) . unwrap ( ) ;
275303
276304 let node = NetworkNode :: new_with_node_name_opt ( Some ( "backup_test" . to_string ( ) ) ) ;
277305 let actor = node. await . get_actor ( ) ;
278306
279- let server = InfoRpcServerImpl :: new ( actor, store, ckb_config, fiber_config) ;
307+ let server = InfoRpcServerImpl :: new ( actor, store, ckb_config, Some ( fiber_config) ) ;
280308
281309 ( server, tempdir)
282310 }
0 commit comments