Skip to content

Commit

Permalink
Merge branch 'bengt/pos-cli-queries' (#1656)
Browse files Browse the repository at this point in the history
* bengt/pos-cli-queries:
  changelog: add #1656
  pos: return sorted validator sets and code re-use for queries
  Expanding and fixing slashes query
  CLI query a validator's state
  query bonded-stake and order
  • Loading branch information
brentstone committed Jul 12, 2023
2 parents 7f45cb2 + 86638ec commit c0b1e20
Show file tree
Hide file tree
Showing 10 changed files with 336 additions and 84 deletions.
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 @@ -4042,8 +4068,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 @@ -4153,8 +4215,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

0 comments on commit c0b1e20

Please sign in to comment.