Skip to content

Commit

Permalink
pcli: 🛻 query validator status fetches validator status
Browse files Browse the repository at this point in the history
see #3846.

this builds upon the previous commit, and adds a `status` subcommand
that will print the status of a validator to stdout.
  • Loading branch information
cratelyn committed Apr 29, 2024
1 parent fd690d3 commit f7539e8
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions crates/bin/pcli/src/command/query/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ pub enum ValidatorCmd {
/// The identity key of the validator to fetch.
identity_key: String,
},
/// Fetch the current status for a particular validator.
Status {
/// The identity key of the validator to fetch.
identity_key: String,
},
}

impl ValidatorCmd {
Expand Down Expand Up @@ -338,6 +343,35 @@ impl ValidatorCmd {
}
}
}
ValidatorCmd::Status { identity_key } => {
// Parse the identity key and construct the RPC request.
let request = tonic::Request::new(GetValidatorInfoRequest {
identity_key: identity_key
.parse::<IdentityKey>()
.map(|ik| ik.to_proto())
.map(Some)?,
});

// Instantiate an RPC client and send the request.
let GetValidatorInfoResponse { validator_info } = app
.pd_channel()
.await
.map(StakeQueryServiceClient::new)?
.get_validator_info(request)
.await?
.into_inner();

// Parse the validator status, or return an error if it was not found within the
// client's response.
let Info { status, .. } = validator_info
.ok_or_else(|| anyhow!("response did not include validator info"))?
.try_into()
.context("parsing validator info")?;

// Serialize the status to TOML, and print it to stdout.
let toml = toml::to_string_pretty(&status)?;
println!("{}", toml);
}
}

Ok(())
Expand Down

0 comments on commit f7539e8

Please sign in to comment.