Skip to content

Commit 2b8064c

Browse files
committed
Merge branch 'bengt/pos-cli-queries' (#1656)
* origin/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
2 parents 9cc004f + 86638ec commit 2b8064c

File tree

10 files changed

+336
-84
lines changed

10 files changed

+336
-84
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Added a client query for `validator-state` and improved the slashes query to
2+
show more info. ([\#1656](https://github.com/anoma/namada/pull/1656))

apps/src/bin/namada-client/cli.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,22 @@ pub async fn main() -> Result<()> {
325325
let args = args.to_sdk(&mut ctx);
326326
rpc::query_bonded_stake(&client, args).await;
327327
}
328+
Sub::QueryValidatorState(QueryValidatorState(mut args)) => {
329+
let client = HttpClient::new(utils::take_config_address(
330+
&mut args.query.ledger_address,
331+
))
332+
.unwrap();
333+
wait_until_node_is_synched(&client)
334+
.await
335+
.proceed_or_else(error)?;
336+
let args = args.to_sdk(&mut ctx);
337+
rpc::query_and_print_validator_state(
338+
&client,
339+
&mut ctx.wallet,
340+
args,
341+
)
342+
.await;
343+
}
328344
Sub::QueryCommissionRate(QueryCommissionRate(mut args)) => {
329345
let client = HttpClient::new(utils::take_config_address(
330346
&mut args.query.ledger_address,

apps/src/lib/cli.rs

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ pub mod cmds {
238238
.subcommand(QueryProposal::def().display_order(4))
239239
.subcommand(QueryProposalResult::def().display_order(4))
240240
.subcommand(QueryProtocolParameters::def().display_order(4))
241+
.subcommand(QueryValidatorState::def().display_order(4))
241242
// Utils
242243
.subcommand(Utils::def().display_order(5))
243244
}
@@ -282,6 +283,8 @@ pub mod cmds {
282283
Self::parse_with_ctx(matches, QueryProposalResult);
283284
let query_protocol_parameters =
284285
Self::parse_with_ctx(matches, QueryProtocolParameters);
286+
let query_validator_state =
287+
Self::parse_with_ctx(matches, QueryValidatorState);
285288
let add_to_eth_bridge_pool =
286289
Self::parse_with_ctx(matches, AddToEthBridgePool);
287290
let utils = SubCmd::parse(matches).map(Self::WithoutContext);
@@ -314,6 +317,7 @@ pub mod cmds {
314317
.or(query_proposal)
315318
.or(query_proposal_result)
316319
.or(query_protocol_parameters)
320+
.or(query_validator_state)
317321
.or(utils)
318322
}
319323
}
@@ -381,6 +385,7 @@ pub mod cmds {
381385
QueryProposal(QueryProposal),
382386
QueryProposalResult(QueryProposalResult),
383387
QueryProtocolParameters(QueryProtocolParameters),
388+
QueryValidatorState(QueryValidatorState),
384389
}
385390

386391
#[allow(clippy::large_enum_variant)]
@@ -1453,6 +1458,27 @@ pub mod cmds {
14531458
}
14541459
}
14551460

1461+
#[derive(Clone, Debug)]
1462+
pub struct QueryValidatorState(
1463+
pub args::QueryValidatorState<args::CliTypes>,
1464+
);
1465+
1466+
impl SubCmd for QueryValidatorState {
1467+
const CMD: &'static str = "validator-state";
1468+
1469+
fn parse(matches: &ArgMatches) -> Option<Self> {
1470+
matches.subcommand_matches(Self::CMD).map(|matches| {
1471+
QueryValidatorState(args::QueryValidatorState::parse(matches))
1472+
})
1473+
}
1474+
1475+
fn def() -> App {
1476+
App::new(Self::CMD)
1477+
.about("Query the state of a PoS validator.")
1478+
.add_args::<args::QueryValidatorState<args::CliTypes>>()
1479+
}
1480+
}
1481+
14561482
#[derive(Clone, Debug)]
14571483
pub struct QueryTransfers(pub args::QueryTransfers<args::CliTypes>);
14581484

@@ -1488,7 +1514,7 @@ pub mod cmds {
14881514

14891515
fn def() -> App {
14901516
App::new(Self::CMD)
1491-
.about("Query commission rate.")
1517+
.about("Query a validator's commission rate.")
14921518
.add_args::<args::QueryCommissionRate<args::CliTypes>>()
14931519
}
14941520
}
@@ -4042,8 +4068,44 @@ pub mod args {
40424068
"The validator's address whose bonded stake to query.",
40434069
))
40444070
.arg(EPOCH.def().help(
4045-
"The epoch at which to query (last committed, if not \
4046-
specified).",
4071+
"The epoch at which to query (corresponding to the last \
4072+
committed block, if not specified).",
4073+
))
4074+
}
4075+
}
4076+
4077+
impl CliToSdk<QueryValidatorState<SdkTypes>> for QueryValidatorState<CliTypes> {
4078+
fn to_sdk(self, ctx: &mut Context) -> QueryValidatorState<SdkTypes> {
4079+
QueryValidatorState::<SdkTypes> {
4080+
query: self.query.to_sdk(ctx),
4081+
validator: ctx.get(&self.validator),
4082+
epoch: self.epoch,
4083+
}
4084+
}
4085+
}
4086+
4087+
impl Args for QueryValidatorState<CliTypes> {
4088+
fn parse(matches: &ArgMatches) -> Self {
4089+
let query = Query::parse(matches);
4090+
let validator = VALIDATOR.parse(matches);
4091+
let epoch = EPOCH.parse(matches);
4092+
Self {
4093+
query,
4094+
validator,
4095+
epoch,
4096+
}
4097+
}
4098+
4099+
fn def(app: App) -> App {
4100+
app.add_args::<Query<CliTypes>>()
4101+
.arg(
4102+
VALIDATOR.def().help(
4103+
"The validator's address whose state is queried.",
4104+
),
4105+
)
4106+
.arg(EPOCH.def().help(
4107+
"The epoch at which to query (corresponding to the last \
4108+
committed block, if not specified).",
40474109
))
40484110
}
40494111
}
@@ -4153,8 +4215,8 @@ pub mod args {
41534215
"The validator's address whose commission rate to query.",
41544216
))
41554217
.arg(EPOCH.def().help(
4156-
"The epoch at which to query (last committed, if not \
4157-
specified).",
4218+
"The epoch at which to query (corresponding to the last \
4219+
committed block, if not specified).",
41584220
))
41594221
}
41604222
}

0 commit comments

Comments
 (0)