@@ -17,7 +17,10 @@ use pluto_eth2util::{
1717 deposit:: { eths_to_gweis, verify_deposit_amounts} ,
1818 enr:: Record ,
1919 helpers:: { checksum_address, public_key_to_address} ,
20- network:: { GOERLI , PRATER , network_to_fork_version, valid_network} ,
20+ network:: {
21+ GNOSIS , GOERLI , HOLESKY , HOODI , MAINNET , PRATER , SEPOLIA , network_to_fork_version,
22+ valid_network,
23+ } ,
2124} ;
2225use tracing:: { info, warn} ;
2326
@@ -198,9 +201,9 @@ async fn run_create_dkg(mut args: CreateDkgArgs) -> Result<()> {
198201
199202 let mut operators: Vec < Operator > = Vec :: new ( ) ;
200203
201- for enr_str in & args. operator_enrs {
204+ for ( i , enr_str) in args. operator_enrs . iter ( ) . enumerate ( ) {
202205 Record :: try_from ( enr_str. as_str ( ) )
203- . map_err ( |e| CliError :: Other ( format ! ( "invalid ENR: {e}" ) ) ) ?;
206+ . map_err ( |e| CliError :: Other ( format ! ( "invalid ENR (operator {i}) : {e}" ) ) ) ?;
204207
205208 operators. push ( Operator {
206209 enr : enr_str. clone ( ) ,
@@ -335,8 +338,8 @@ fn validate_dkg_config(
335338
336339fn validate_addresses (
337340 num_validators : u64 ,
338- mut fee_recipient_addrs : Vec < String > ,
339- mut withdrawal_addrs : Vec < String > ,
341+ fee_recipient_addrs : Vec < String > ,
342+ withdrawal_addrs : Vec < String > ,
340343) -> Result < ( Vec < String > , Vec < String > ) > {
341344 let num_vals = num_validators;
342345 let num_fee = u64:: try_from ( fee_recipient_addrs. len ( ) )
@@ -356,21 +359,17 @@ fn validate_addresses(
356359 ) ) ;
357360 }
358361
359- if fee_recipient_addrs. len ( ) == 1 {
360- let addr = fee_recipient_addrs[ 0 ] . clone ( ) ;
361- for _ in 1 ..num_validators {
362- fee_recipient_addrs. push ( addr. clone ( ) ) ;
362+ let num_validators = usize:: try_from ( num_validators)
363+ . map_err ( |_| CliError :: Other ( "num_validators is greater than usize::MAX" . to_string ( ) ) ) ?;
364+ let expand = |addrs : Vec < String > | -> Vec < String > {
365+ if addrs. len ( ) == 1 {
366+ vec ! [ addrs[ 0 ] . clone( ) ; num_validators]
367+ } else {
368+ addrs
363369 }
364- }
365-
366- if withdrawal_addrs. len ( ) == 1 {
367- let addr = withdrawal_addrs[ 0 ] . clone ( ) ;
368- for _ in 1 ..num_validators {
369- withdrawal_addrs. push ( addr. clone ( ) ) ;
370- }
371- }
370+ } ;
372371
373- Ok ( ( fee_recipient_addrs, withdrawal_addrs) )
372+ Ok ( ( expand ( fee_recipient_addrs) , expand ( withdrawal_addrs) ) )
374373}
375374
376375fn validate_withdrawal_addrs ( addrs : & [ String ] , network : & str ) -> Result < ( ) > {
@@ -395,7 +394,7 @@ fn validate_withdrawal_addrs(addrs: &[String], network: &str) -> Result<()> {
395394}
396395
397396fn is_main_or_gnosis ( network : & str ) -> bool {
398- network == "mainnet" || network == "gnosis"
397+ network == MAINNET . name || network == GNOSIS . name
399398}
400399
401400fn safe_threshold ( num_operators : u64 ) -> Result < u64 > {
@@ -409,12 +408,12 @@ fn safe_threshold(num_operators: u64) -> Result<u64> {
409408}
410409
411410fn generate_launchpad_link ( config_hash : & [ u8 ] , network : & str ) -> String {
412- let network_prefix = match network {
413- "holesky" => "holesky." ,
414- "hoodi" => "hoodi." ,
415- "sepolia" => "sepolia." ,
416- _ => "" ,
417- } ;
411+ let network_prefix =
412+ if network == HOLESKY . name || network == HOODI . name || network == SEPOLIA . name {
413+ format ! ( "{network}." )
414+ } else {
415+ String :: new ( )
416+ } ;
418417 format ! (
419418 "https://{}launchpad.obol.org/dv#0x{}" ,
420419 network_prefix,
@@ -529,7 +528,7 @@ mod tests {
529528 threshold: 3 , network: DEFAULT_NETWORK . to_string( ) ,
530529 ..default_args( )
531530 } ,
532- "invalid ENR: The format of the record is invalid: Record does not start with 'enr:'" ;
531+ "invalid ENR (operator 0) : The format of the record is invalid: Record does not start with 'enr:'" ;
533532 "missing_enr_prefix_dash"
534533 ) ]
535534 #[ test_case(
@@ -542,7 +541,7 @@ mod tests {
542541 threshold: 3 , network: DEFAULT_NETWORK . to_string( ) ,
543542 ..default_args( )
544543 } ,
545- "invalid ENR: Failed to decode the base64 encoded data: Invalid last symbol 117, offset 194." ;
544+ "invalid ENR (operator 0) : Failed to decode the base64 encoded data: Invalid last symbol 117, offset 194." ;
546545 "enr_colon_no_dash"
547546 ) ]
548547 #[ test_case(
@@ -555,7 +554,7 @@ mod tests {
555554 threshold: 3 , network: DEFAULT_NETWORK . to_string( ) ,
556555 ..default_args( )
557556 } ,
558- "invalid ENR: The format of the record is invalid: Record does not start with 'enr:'" ;
557+ "invalid ENR (operator 0) : The format of the record is invalid: Record does not start with 'enr:'" ;
559558 "enr_no_colon"
560559 ) ]
561560 #[ test_case(
@@ -568,7 +567,7 @@ mod tests {
568567 threshold: 3 , network: DEFAULT_NETWORK . to_string( ) ,
569568 ..default_args( )
570569 } ,
571- "invalid ENR: The format of the record is invalid: Record does not start with 'enr:'" ;
570+ "invalid ENR (operator 0) : The format of the record is invalid: Record does not start with 'enr:'" ;
572571 "no_enr_prefix"
573572 ) ]
574573 #[ test_case(
0 commit comments