@@ -68,13 +68,13 @@ pub struct NodeConfig {
6868 pub dkg_keys : Option < DkgKeys > ,
6969 pub log_file_path : Option < PathBuf > ,
7070 #[ serde( skip) ]
71- key_file_path : PathBuf ,
71+ pub key_file_path : PathBuf ,
7272 #[ serde( skip) ]
73- config_file_path : PathBuf ,
74- database_directory : Option < PathBuf > ,
75- grpc_port : Option < u16 > ,
76- libp2p_udp_port : Option < u16 > ,
77- libp2p_tcp_port : Option < u16 > ,
73+ pub config_file_path : PathBuf ,
74+ pub database_directory : PathBuf ,
75+ pub grpc_port : u16 ,
76+ pub libp2p_udp_port : u16 ,
77+ pub libp2p_tcp_port : u16 ,
7878}
7979
8080#[ derive( Serialize , Deserialize ) ]
@@ -88,10 +88,10 @@ pub struct ConfigStore {
8888 allowed_peers : Vec < PeerData > ,
8989 log_file_path : Option < PathBuf > ,
9090 key_file_path : PathBuf ,
91- database_directory : Option < PathBuf > ,
92- grpc_port : Option < u16 > ,
93- libp2p_udp_port : Option < u16 > ,
94- libp2p_tcp_port : Option < u16 > ,
91+ database_directory : PathBuf ,
92+ grpc_port : u16 ,
93+ libp2p_udp_port : u16 ,
94+ libp2p_tcp_port : u16 ,
9595}
9696
9797impl NodeConfig {
@@ -156,11 +156,26 @@ impl NodeConfig {
156156 log_file_path,
157157 key_file_path,
158158 config_file_path,
159- database_directory : None ,
160- grpc_port : None ,
161- libp2p_udp_port : None ,
162- libp2p_tcp_port : None ,
163- } )
159+ database_directory : PathBuf :: from ( "nodedb.db" ) ,
160+ grpc_port : 50051 ,
161+ libp2p_udp_port : 0 ,
162+ libp2p_tcp_port : 0 ,
163+ } )
164+ }
165+
166+ pub fn save_to_keys_file ( & self ) -> Result < ( ) , NodeError > {
167+ let key_store = KeyStore {
168+ key_data : self . key_data . clone ( ) ,
169+ dkg_keys : self . dkg_keys . clone ( ) ,
170+ } ;
171+
172+ let key_info_str = serde_json:: to_string_pretty ( & key_store)
173+ . map_err ( |e| NodeError :: Error ( format ! ( "Failed to serialize key data: {}" , e) ) ) ?;
174+
175+ fs:: write ( & self . key_file_path , key_info_str)
176+ . map_err ( |e| NodeError :: Error ( format ! ( "Failed to write key data: {}" , e) ) ) ?;
177+
178+ Ok ( ( ) )
164179 }
165180
166181 pub fn save_to_file ( & self ) -> Result < ( ) , NodeError > {
@@ -180,9 +195,9 @@ impl NodeConfig {
180195 log_file_path : self . log_file_path . clone ( ) ,
181196 key_file_path : self . key_file_path . clone ( ) ,
182197 database_directory : self . database_directory . clone ( ) ,
183- grpc_port : self . grpc_port . clone ( ) ,
184- libp2p_udp_port : self . libp2p_udp_port . clone ( ) ,
185- libp2p_tcp_port : self . libp2p_tcp_port . clone ( ) ,
198+ grpc_port : self . grpc_port ,
199+ libp2p_udp_port : self . libp2p_udp_port ,
200+ libp2p_tcp_port : self . libp2p_tcp_port ,
186201 } ;
187202
188203 let config_str: String = serde_yaml:: to_string ( & config_store) . unwrap ( ) ;
@@ -200,6 +215,22 @@ impl NodeConfig {
200215 pub fn set_key_data ( & mut self , key_data : KeyData ) {
201216 self . key_data = key_data;
202217 }
218+
219+ pub fn set_grpc_port ( & mut self , port : u16 ) {
220+ self . grpc_port = port;
221+ }
222+
223+ pub fn set_libp2p_udp_port ( & mut self , port : u16 ) {
224+ self . libp2p_udp_port = port;
225+ }
226+
227+ pub fn set_libp2p_tcp_port ( & mut self , port : u16 ) {
228+ self . libp2p_tcp_port = port;
229+ }
230+
231+ pub fn set_database_directory ( & mut self , dir : PathBuf ) {
232+ self . database_directory = dir;
233+ }
203234}
204235
205236pub struct NodeState < N : Network , D : Db , O : Oracle > {
0 commit comments