Skip to content

Commit

Permalink
Add delete all validators
Browse files Browse the repository at this point in the history
  • Loading branch information
chong-he committed Dec 17, 2024
1 parent 8556f85 commit ba45cc5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
24 changes: 18 additions & 6 deletions validator_manager/src/delete_validators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ pub fn cli_app() -> Command {
Arg::new(VALIDATOR_FLAG)
.long(VALIDATOR_FLAG)
.value_name("STRING")
.help("Comma-separated list of validators (pubkey) that will be deleted.")
.help(
"Comma-separated list of validators (pubkey) that will be deleted. \
To delete all validators, use the keyword \"all\".",
)
.action(ArgAction::Set)
.required(true)
.display_order(0),
Expand All @@ -64,10 +67,14 @@ impl DeleteConfig {
let validators_to_delete_str =
clap_utils::parse_required::<String>(matches, VALIDATOR_FLAG)?;

let validators_to_delete = validators_to_delete_str
.split(',')
.map(|s| s.trim().parse())
.collect::<Result<Vec<PublicKeyBytes>, _>>()?;
let validators_to_delete = if validators_to_delete_str.trim() == "all" {
Vec::new()
} else {
validators_to_delete_str
.split(',')
.map(|s| s.trim().parse())
.collect::<Result<Vec<PublicKeyBytes>, _>>()?
};

Ok(Self {
vc_token_path: clap_utils::parse_required(matches, VC_TOKEN_FLAG)?,
Expand All @@ -90,11 +97,16 @@ async fn run<'a>(config: DeleteConfig) -> Result<(), String> {
let DeleteConfig {
vc_url,
vc_token_path,
validators_to_delete,
mut validators_to_delete,
} = config;

let (http_client, validators) = vc_http_client(vc_url.clone(), &vc_token_path).await?;

// Delete all validators on the VC
if validators_to_delete.is_empty() {
validators_to_delete = validators.iter().map(|v| v.validating_pubkey).collect();
}

for validator_to_delete in &validators_to_delete {
if !validators
.iter()
Expand Down
5 changes: 4 additions & 1 deletion validator_manager/src/exit_validators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ pub fn cli_app() -> Command {
Arg::new(VALIDATOR_FLAG)
.long(VALIDATOR_FLAG)
.value_name("STRING")
.help("List of validators (pubkey) to exit.")
.help(
"Comma-separated list of validators (pubkey) to exit. \
To exit all validators, use the keyword \"all\".",
)
.action(ArgAction::Set)
.required(true)
.display_order(0),
Expand Down

0 comments on commit ba45cc5

Please sign in to comment.