11//! BitCell node binary
22
33use bitcell_node:: { NodeConfig , ValidatorNode , MinerNode } ;
4- use bitcell_crypto:: SecretKey ;
54use clap:: { Parser , Subcommand } ;
65use std:: path:: PathBuf ;
76
@@ -81,18 +80,18 @@ async fn main() {
8180 let cli = Cli :: parse ( ) ;
8281
8382 match cli. command {
84- Commands :: Validator { port, rpc_port, data_dir : _ , enable_dht, bootstrap, key_seed, key_file, private_key } => {
83+ Commands :: Validator { port, rpc_port, data_dir, enable_dht, bootstrap, key_seed, key_file, private_key } => {
8584 println ! ( "🌌 BitCell Validator Node" ) ;
8685 println ! ( "=========================" ) ;
8786
8887 let mut config = NodeConfig :: default ( ) ;
8988 config. network_port = port;
9089 config. enable_dht = enable_dht;
9190 config. key_seed = key_seed. clone ( ) ;
91+ config. data_dir = data_dir;
9292 if let Some ( bootstrap_node) = bootstrap {
9393 config. bootstrap_nodes . push ( bootstrap_node) ;
9494 }
95- // TODO: Use data_dir
9695
9796 // Resolve secret key
9897 let secret_key = match bitcell_node:: keys:: resolve_secret_key (
@@ -122,7 +121,13 @@ async fn main() {
122121 // Or we can modify NodeConfig to hold the secret key? No, NodeConfig is serializable.
123122
124123 // Let's update ValidatorNode::new to take the secret key as an argument.
125- let mut node = ValidatorNode :: with_key ( config, secret_key. clone ( ) ) ;
124+ let mut node = match ValidatorNode :: with_key ( config, secret_key. clone ( ) ) {
125+ Ok ( node) => node,
126+ Err ( e) => {
127+ eprintln ! ( "Error initializing validator node: {}" , e) ;
128+ std:: process:: exit ( 1 ) ;
129+ }
130+ } ;
126131
127132 // Start metrics server on port + 2 to avoid conflict with P2P port (30333) and RPC port (30334)
128133 let metrics_port = port + 2 ;
@@ -162,14 +167,15 @@ async fn main() {
162167 tokio:: signal:: ctrl_c ( ) . await . expect ( "Failed to listen for Ctrl+C" ) ;
163168 println ! ( "\n Shutting down..." ) ;
164169 }
165- Commands :: Miner { port, rpc_port, data_dir : _ , enable_dht, bootstrap, key_seed, key_file, private_key } => {
170+ Commands :: Miner { port, rpc_port, data_dir, enable_dht, bootstrap, key_seed, key_file, private_key } => {
166171 println ! ( "⛏️ BitCell Miner Node" ) ;
167172 println ! ( "======================" ) ;
168173
169174 let mut config = NodeConfig :: default ( ) ;
170175 config. network_port = port;
171176 config. enable_dht = enable_dht;
172177 config. key_seed = key_seed. clone ( ) ;
178+ config. data_dir = data_dir;
173179 if let Some ( bootstrap_node) = bootstrap {
174180 config. bootstrap_nodes . push ( bootstrap_node) ;
175181 }
@@ -190,7 +196,13 @@ async fn main() {
190196
191197 println ! ( "Miner Public Key: {:?}" , secret_key. public_key( ) ) ;
192198
193- let mut node = MinerNode :: with_key ( config, secret_key. clone ( ) ) ;
199+ let mut node = match MinerNode :: with_key ( config, secret_key. clone ( ) ) {
200+ Ok ( node) => node,
201+ Err ( e) => {
202+ eprintln ! ( "Error initializing miner node: {}" , e) ;
203+ std:: process:: exit ( 1 ) ;
204+ }
205+ } ;
194206
195207 let metrics_port = port + 2 ;
196208
@@ -228,14 +240,15 @@ async fn main() {
228240 tokio:: signal:: ctrl_c ( ) . await . expect ( "Failed to listen for Ctrl+C" ) ;
229241 println ! ( "\n Shutting down..." ) ;
230242 }
231- Commands :: FullNode { port, rpc_port, data_dir : _ , enable_dht, bootstrap, key_seed, key_file, private_key } => {
243+ Commands :: FullNode { port, rpc_port, data_dir, enable_dht, bootstrap, key_seed, key_file, private_key } => {
232244 println ! ( "🌍 BitCell Full Node" ) ;
233245 println ! ( "====================" ) ;
234246
235247 let mut config = NodeConfig :: default ( ) ;
236248 config. network_port = port;
237249 config. enable_dht = enable_dht;
238250 config. key_seed = key_seed. clone ( ) ;
251+ config. data_dir = data_dir;
239252 if let Some ( bootstrap_node) = bootstrap {
240253 config. bootstrap_nodes . push ( bootstrap_node) ;
241254 }
@@ -257,7 +270,13 @@ async fn main() {
257270 println ! ( "Full Node Public Key: {:?}" , secret_key. public_key( ) ) ;
258271
259272 // Reuse ValidatorNode for now as FullNode logic is similar (just no voting)
260- let mut node = ValidatorNode :: with_key ( config, secret_key. clone ( ) ) ;
273+ let mut node = match ValidatorNode :: with_key ( config, secret_key. clone ( ) ) {
274+ Ok ( node) => node,
275+ Err ( e) => {
276+ eprintln ! ( "Error initializing full node: {}" , e) ;
277+ std:: process:: exit ( 1 ) ;
278+ }
279+ } ;
261280
262281 let metrics_port = port + 2 ;
263282
0 commit comments