@@ -76,7 +76,7 @@ build_config! {
7676 // * Open port 12535 for ws rpc if `jsonrpc_ws_port` is not provided.
7777 // * Open port 12536 for tcp rpc if `jsonrpc_tcp_port` is not provided.
7878 // * Open port 12537 for http rpc if `jsonrpc_http_port` is not provided.
79- // * generate blocks automatically without PoW if `start_mining` is false
79+ // * generate blocks automatically without PoW.
8080 // * Skip catch-up mode even there is no peer
8181 //
8282 ( mode, ( Option <String >) , None )
@@ -85,7 +85,7 @@ build_config! {
8585 ( debug_invalid_state_root_epoch, ( Option <String >) , None )
8686 ( debug_dump_dir_invalid_state_root, ( String ) , "./storage_db/debug_dump_invalid_state_root/" . to_string( ) )
8787 // Controls block generation speed.
88- // Only effective in `dev` mode and `start_mining` is false
88+ // Only effective in `dev` mode
8989 ( dev_block_interval_ms, ( u64 ) , 250 )
9090 ( enable_state_expose, ( bool ) , false )
9191 ( generate_tx, ( bool ) , false )
@@ -124,11 +124,10 @@ build_config! {
124124
125125 // Mining section.
126126 ( mining_author, ( Option <String >) , None )
127- ( start_mining , ( bool ) , false )
127+ ( mining_type , ( Option < String > ) , None )
128128 ( stratum_listen_address, ( String ) , "127.0.0.1" . into( ) )
129129 ( stratum_port, ( u16 ) , 32525 )
130130 ( stratum_secret, ( Option <String >) , None )
131- ( use_stratum, ( bool ) , false )
132131 ( use_octopus_in_test_mode, ( bool ) , false )
133132
134133 // Network section.
@@ -313,9 +312,8 @@ impl Configuration {
313312 network_config. config_path = self . raw_conf . netconf_dir . clone ( ) ;
314313 }
315314 network_config. use_secret =
316- self . raw_conf . net_key . clone ( ) . map ( |sec_str| {
317- sec_str
318- . parse ( )
315+ self . raw_conf . net_key . as_ref ( ) . map ( |sec_str| {
316+ parse_hex_string ( sec_str)
319317 . expect ( "net_key is not a valid secret string" )
320318 } ) ;
321319 if let Some ( addr) = self . raw_conf . public_address . clone ( ) {
@@ -450,16 +448,25 @@ impl Configuration {
450448
451449 pub fn pow_config ( & self ) -> ProofOfWorkConfig {
452450 let stratum_secret =
453- self . raw_conf
454- . stratum_secret
455- . clone ( )
456- . map ( |hex_str| H256 :: from_str ( hex_str. as_str ( ) )
457- . expect ( "Stratum secret should be 64-digit hex string without 0x prefix" ) ) ;
451+ self . raw_conf . stratum_secret . as_ref ( ) . map ( |hex_str| {
452+ parse_hex_string ( hex_str)
453+ . expect ( "Stratum secret should be 64-digit hex string" )
454+ } ) ;
458455
459456 ProofOfWorkConfig :: new (
460457 self . is_test_or_dev_mode ( ) ,
461458 self . raw_conf . use_octopus_in_test_mode ,
462- self . raw_conf . use_stratum ,
459+ self . raw_conf . mining_type . as_ref ( ) . map_or_else (
460+ || {
461+ // Enable stratum implicitly if `mining_author` is set.
462+ if self . raw_conf . mining_author . is_some ( ) {
463+ "stratum"
464+ } else {
465+ "disable"
466+ }
467+ } ,
468+ |s| s. as_str ( ) ,
469+ ) ,
463470 self . raw_conf . initial_difficulty ,
464471 self . raw_conf . stratum_listen_address . clone ( ) ,
465472 self . raw_conf . stratum_port ,
@@ -752,6 +759,8 @@ pub fn to_bootnodes(bootnodes: &Option<String>) -> Result<Vec<String>, String> {
752759 match * bootnodes {
753760 Some ( ref x) if !x. is_empty ( ) => x
754761 . split ( ',' )
762+ // ignore empty strings
763+ . filter ( |s| !s. is_empty ( ) )
755764 . map ( |s| match validate_node_url ( s) . map ( Into :: into) {
756765 None => Ok ( s. to_owned ( ) ) ,
757766 Some ( ErrorKind :: AddressResolve ( _) ) => Err ( format ! (
@@ -768,3 +777,7 @@ pub fn to_bootnodes(bootnodes: &Option<String>) -> Result<Vec<String>, String> {
768777 None => Ok ( vec ! [ ] ) ,
769778 }
770779}
780+
781+ pub fn parse_hex_string < F : FromStr > ( hex_str : & str ) -> Result < F , F :: Err > {
782+ hex_str. strip_prefix ( "0x" ) . unwrap_or ( hex_str) . parse ( )
783+ }
0 commit comments