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

add client block query #659

Merged
merged 2 commits into from
Oct 31, 2022
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/features/658-add-client-block-query.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Client: Add a command to query the last committed block's hash, height and
timestamp. ([#658](https://github.com/anoma/namada/issues/658))
3 changes: 3 additions & 0 deletions apps/src/bin/anoma-client/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ pub async fn main() -> Result<()> {
Sub::QueryEpoch(QueryEpoch(args)) => {
rpc::query_epoch(args).await;
}
Sub::QueryBlock(QueryBlock(args)) => {
rpc::query_block(args).await;
}
Sub::QueryBalance(QueryBalance(args)) => {
rpc::query_balance(ctx, args).await;
}
Expand Down
23 changes: 23 additions & 0 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ pub mod cmds {
.subcommand(Withdraw::def().display_order(2))
// Queries
.subcommand(QueryEpoch::def().display_order(3))
.subcommand(QueryBlock::def().display_order(3))
.subcommand(QueryBalance::def().display_order(3))
.subcommand(QueryBonds::def().display_order(3))
.subcommand(QueryVotingPower::def().display_order(3))
Expand Down Expand Up @@ -198,6 +199,7 @@ pub mod cmds {
let unbond = Self::parse_with_ctx(matches, Unbond);
let withdraw = Self::parse_with_ctx(matches, Withdraw);
let query_epoch = Self::parse_with_ctx(matches, QueryEpoch);
let query_block = Self::parse_with_ctx(matches, QueryBlock);
let query_balance = Self::parse_with_ctx(matches, QueryBalance);
let query_bonds = Self::parse_with_ctx(matches, QueryBonds);
let query_voting_power =
Expand All @@ -224,6 +226,7 @@ pub mod cmds {
.or(unbond)
.or(withdraw)
.or(query_epoch)
.or(query_block)
.or(query_balance)
.or(query_bonds)
.or(query_voting_power)
Expand Down Expand Up @@ -283,6 +286,7 @@ pub mod cmds {
Unbond(Unbond),
Withdraw(Withdraw),
QueryEpoch(QueryEpoch),
QueryBlock(QueryBlock),
QueryBalance(QueryBalance),
QueryBonds(QueryBonds),
QueryVotingPower(QueryVotingPower),
Expand Down Expand Up @@ -936,6 +940,25 @@ pub mod cmds {
}
}

#[derive(Clone, Debug)]
pub struct QueryBlock(pub args::Query);

impl SubCmd for QueryBlock {
const CMD: &'static str = "block";

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

fn def() -> App {
App::new(Self::CMD)
.about("Query the last committed block.")
.add_args::<args::Query>()
}
}

#[derive(Clone, Debug)]
pub struct QueryBalance(pub args::QueryBalance);

Expand Down
15 changes: 15 additions & 0 deletions apps/src/lib/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ pub async fn query_epoch(args: args::Query) -> Epoch {
cli::safe_exit(1)
}

/// Query the last committed block
pub async fn query_block(
args: args::Query,
) -> tendermint_rpc::endpoint::block::Response {
let client = HttpClient::new(args.ledger_address).unwrap();
let response = client.latest_block().await.unwrap();
println!(
"Last committed block ID: {}, height: {}, time: {}",
response.block_id,
response.block.header.height,
response.block.header.time
);
response
}

/// Query the raw bytes of given storage key
pub async fn query_raw_bytes(_ctx: Context, args: args::QueryRawBytes) {
let client = HttpClient::new(args.query.ledger_address).unwrap();
Expand Down