Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving the CLI for PoS queries #1656

Merged
merged 5 commits into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions .changelog/unreleased/improvements/1656-pos-cli-queries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Added a client query for `validator-state` and improved the slashes query to
show more info. ([\#1656](https://github.com/anoma/namada/pull/1656))
16 changes: 16 additions & 0 deletions apps/src/bin/namada-client/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,22 @@ pub async fn main() -> Result<()> {
let args = args.to_sdk(&mut ctx);
rpc::query_bonded_stake(&client, args).await;
}
Sub::QueryValidatorState(QueryValidatorState(mut args)) => {
let client = HttpClient::new(utils::take_config_address(
&mut args.query.ledger_address,
))
.unwrap();
wait_until_node_is_synched(&client)
.await
.proceed_or_else(error)?;
let args = args.to_sdk(&mut ctx);
rpc::query_and_print_validator_state(
&client,
&mut ctx.wallet,
args,
)
.await;
}
Sub::QueryCommissionRate(QueryCommissionRate(mut args)) => {
let client = HttpClient::new(utils::take_config_address(
&mut args.query.ledger_address,
Expand Down
72 changes: 67 additions & 5 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ pub mod cmds {
.subcommand(QueryProposal::def().display_order(4))
.subcommand(QueryProposalResult::def().display_order(4))
.subcommand(QueryProtocolParameters::def().display_order(4))
.subcommand(QueryValidatorState::def().display_order(4))
// Utils
.subcommand(Utils::def().display_order(5))
}
Expand Down Expand Up @@ -282,6 +283,8 @@ pub mod cmds {
Self::parse_with_ctx(matches, QueryProposalResult);
let query_protocol_parameters =
Self::parse_with_ctx(matches, QueryProtocolParameters);
let query_validator_state =
Self::parse_with_ctx(matches, QueryValidatorState);
let add_to_eth_bridge_pool =
Self::parse_with_ctx(matches, AddToEthBridgePool);
let utils = SubCmd::parse(matches).map(Self::WithoutContext);
Expand Down Expand Up @@ -314,6 +317,7 @@ pub mod cmds {
.or(query_proposal)
.or(query_proposal_result)
.or(query_protocol_parameters)
.or(query_validator_state)
.or(utils)
}
}
Expand Down Expand Up @@ -381,6 +385,7 @@ pub mod cmds {
QueryProposal(QueryProposal),
QueryProposalResult(QueryProposalResult),
QueryProtocolParameters(QueryProtocolParameters),
QueryValidatorState(QueryValidatorState),
}

#[allow(clippy::large_enum_variant)]
Expand Down Expand Up @@ -1453,6 +1458,27 @@ pub mod cmds {
}
}

#[derive(Clone, Debug)]
pub struct QueryValidatorState(
pub args::QueryValidatorState<args::CliTypes>,
);

impl SubCmd for QueryValidatorState {
const CMD: &'static str = "validator-state";

fn parse(matches: &ArgMatches) -> Option<Self> {
matches.subcommand_matches(Self::CMD).map(|matches| {
QueryValidatorState(args::QueryValidatorState::parse(matches))
})
}

fn def() -> App {
App::new(Self::CMD)
.about("Query the state of a PoS validator.")
.add_args::<args::QueryValidatorState<args::CliTypes>>()
}
}

#[derive(Clone, Debug)]
pub struct QueryTransfers(pub args::QueryTransfers<args::CliTypes>);

Expand Down Expand Up @@ -1488,7 +1514,7 @@ pub mod cmds {

fn def() -> App {
App::new(Self::CMD)
.about("Query commission rate.")
.about("Query a validator's commission rate.")
.add_args::<args::QueryCommissionRate<args::CliTypes>>()
}
}
Expand Down Expand Up @@ -4016,8 +4042,44 @@ pub mod args {
"The validator's address whose bonded stake to query.",
))
.arg(EPOCH.def().help(
"The epoch at which to query (last committed, if not \
specified).",
"The epoch at which to query (corresponding to the last \
committed block, if not specified).",
))
}
}

impl CliToSdk<QueryValidatorState<SdkTypes>> for QueryValidatorState<CliTypes> {
fn to_sdk(self, ctx: &mut Context) -> QueryValidatorState<SdkTypes> {
QueryValidatorState::<SdkTypes> {
query: self.query.to_sdk(ctx),
validator: ctx.get(&self.validator),
epoch: self.epoch,
}
}
}

impl Args for QueryValidatorState<CliTypes> {
fn parse(matches: &ArgMatches) -> Self {
let query = Query::parse(matches);
let validator = VALIDATOR.parse(matches);
let epoch = EPOCH.parse(matches);
Self {
query,
validator,
epoch,
}
}

fn def(app: App) -> App {
app.add_args::<Query<CliTypes>>()
.arg(
VALIDATOR.def().help(
"The validator's address whose state is queried.",
),
)
.arg(EPOCH.def().help(
"The epoch at which to query (corresponding to the last \
committed block, if not specified).",
))
}
}
Expand Down Expand Up @@ -4127,8 +4189,8 @@ pub mod args {
"The validator's address whose commission rate to query.",
))
.arg(EPOCH.def().help(
"The epoch at which to query (last committed, if not \
specified).",
"The epoch at which to query (corresponding to the last \
committed block, if not specified).",
))
}
}
Expand Down
Loading
Loading