@@ -46,19 +46,17 @@ use rand::rngs::OsRng;
4646use tracing:: { debug, info, warn} ;
4747
4848use crate :: {
49- commands:: create_dkg,
49+ commands:: {
50+ address_validation:: validate_addresses,
51+ constants:: { MIN_NODES , MIN_THRESHOLD } ,
52+ create_dkg,
53+ } ,
5054 error:: {
5155 CliError , CreateClusterError , InvalidNetworkConfigError , Result as CliResult ,
5256 ThresholdError ,
5357 } ,
5458} ;
5559
56- /// Minimum number of nodes required in a cluster.
57- pub const MIN_NODES : u64 = 3 ;
58- /// Minimum threshold value.
59- pub const MIN_THRESHOLD : u64 = 2 ;
60- /// Zero ethereum address (not allowed on mainnet/gnosis).
61- pub const ZERO_ADDRESS : & str = "0x0000000000000000000000000000000000000000" ;
6260/// HTTP scheme.
6361const HTTP_SCHEME : & str = "http" ;
6462/// HTTPS scheme.
@@ -1210,52 +1208,6 @@ async fn load_definition(
12101208 Ok ( def)
12111209}
12121210
1213- /// Validates that addresses match the number of validators.
1214- /// If only one address is provided, it fills the slice to match num_validators.
1215- ///
1216- /// Returns an error if the number of addresses doesn't match and isn't exactly
1217- /// 1.
1218- fn validate_addresses (
1219- num_validators : u64 ,
1220- fee_recipient_addrs : & [ String ] ,
1221- withdrawal_addrs : & [ String ] ,
1222- ) -> Result < ( Vec < String > , Vec < String > ) > {
1223- let num_validators_usize =
1224- usize:: try_from ( num_validators) . map_err ( |_| CreateClusterError :: ValueExceedsUsize {
1225- value : num_validators,
1226- } ) ?;
1227-
1228- if fee_recipient_addrs. len ( ) != num_validators_usize && fee_recipient_addrs. len ( ) != 1 {
1229- return Err ( CreateClusterError :: MismatchingFeeRecipientAddresses {
1230- num_validators,
1231- addresses : fee_recipient_addrs. len ( ) ,
1232- } ) ;
1233- }
1234-
1235- if withdrawal_addrs. len ( ) != num_validators_usize && withdrawal_addrs. len ( ) != 1 {
1236- return Err ( CreateClusterError :: MismatchingWithdrawalAddresses {
1237- num_validators,
1238- addresses : withdrawal_addrs. len ( ) ,
1239- } ) ;
1240- }
1241-
1242- let mut fee_addrs = fee_recipient_addrs. to_vec ( ) ;
1243- let mut withdraw_addrs = withdrawal_addrs. to_vec ( ) ;
1244-
1245- // Expand single address to match num_validators
1246- if fee_addrs. len ( ) == 1 {
1247- let addr = fee_addrs[ 0 ] . clone ( ) ;
1248- fee_addrs = vec ! [ addr; num_validators_usize] ;
1249- }
1250-
1251- if withdraw_addrs. len ( ) == 1 {
1252- let addr = withdraw_addrs[ 0 ] . clone ( ) ;
1253- withdraw_addrs = vec ! [ addr; num_validators_usize] ;
1254- }
1255-
1256- Ok ( ( fee_addrs, withdraw_addrs) )
1257- }
1258-
12591211/// Returns the safe threshold, logging a warning if a non-standard threshold is
12601212/// provided.
12611213fn safe_threshold ( num_nodes : u64 , threshold : Option < u64 > ) -> u64 {
0 commit comments