Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions ipc/cli/src/commands/subnet/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// SPDX-License-Identifier: MIT
//! Get the validator information

use crate::{get_ipc_provider, CommandLineHandler, GlobalArguments};
use async_trait::async_trait;
use clap::Args;
use fvm_shared::address::Address;
use ipc_api::subnet_id::SubnetID;
use ipc_types::EthAddress;
use std::fmt::Debug;
use std::str::FromStr;

use crate::{get_ipc_provider, CommandLineHandler, GlobalArguments};

/// The command to get the validator information
pub(crate) struct ValidatorInfo;

Expand All @@ -23,7 +23,11 @@ impl CommandLineHandler for ValidatorInfo {

let provider = get_ipc_provider(global)?;
let subnet = SubnetID::from_str(&arguments.subnet)?;
let validator = Address::from_str(&arguments.validator)?;
// Attempt to parse the validator address as an EthAddress first; if not, parse as a
// Filecoin address.
let validator: Address = EthAddress::from_str(&arguments.validator)
.map(EthAddress::into)
.or_else(|_| Address::from_str(&arguments.validator))?;

let validator_info = provider.get_validator_info(&subnet, &validator).await?;
println!("{}", validator_info);
Expand All @@ -37,6 +41,9 @@ impl CommandLineHandler for ValidatorInfo {
pub(crate) struct ValidatorInfoArgs {
#[arg(long, help = "The subnet id to query validator info")]
pub subnet: String,
#[arg(long, help = "The validator address")]
#[arg(
long,
help = "The validator address, in 0x Eth format or Filecoin address format"
)]
pub validator: String,
}